Guides

How to Integrate SnagRelay Widget into a Svelte Application

Integrate visual bug reporting into Svelte and SvelteKit. Capture the element, console errors, requests and session replay with onMount—SSR compatible.

How to Integrate SnagRelay Widget into a Svelte Application

Overview

Integrate SnagRelay into your Svelte or SvelteKit application for seamless bug reporting. The widget configuration is managed in your dashboard, making the code integration minimal.

Prerequisites

  • A SnagRelay account (sign up free)
  • Your SnagRelay API key
  • A Svelte or SvelteKit application

SvelteKit Integration

Add SnagRelay to your root layout for app-wide coverage:

<!-- src/routes/+layout.svelte -->
<script>
  import { onMount } from 'svelte';
  import { browser } from '$app/environment';
  
  onMount(() => {
    if (browser) {
      window.onSnagRelayLoad = function (api) {
        api.init();
      };
      
      const script = document.createElement('script');
      script.defer = true;
      script.src = 'https://app.snagrelay.com/widget/load/YOUR_API_KEY?onload=onSnagRelayLoad';
      document.head.appendChild(script);
    }
  });
</script>

<slot />

Replace YOUR_API_KEY with your actual API key.

Vanilla Svelte Integration

For non-SvelteKit Svelte apps:

<!-- App.svelte -->
<script>
  import { onMount } from 'svelte';
  
  onMount(() => {
    window.onSnagRelayLoad = function (api) {
      api.init();
    };
    
    const script = document.createElement('script');
    script.defer = true;
    script.src = 'https://app.snagrelay.com/widget/load/YOUR_API_KEY?onload=onSnagRelayLoad';
    document.head.appendChild(script);
  });
</script>

<main>
  <!-- Your app content -->
</main>

That's It!

The widget configuration (position, colors, button text, session replay settings, etc.) is managed in your SnagRelay dashboard. Any changes you make there will automatically apply to your widget.

Best Practices

  • Use browser check — Always check for browser environment in SvelteKit to avoid SSR issues
  • Environment variables — Use PUBLIC_ prefix for client-side env vars in SvelteKit

Next Steps

  • Connect a tracker (Jira, Linear, GitHub, GitLab, Trello or Azure DevOps), or keep reports in the inbox
  • Configure session replay settings in your dashboard
  • Connect your coding agent over MCP: Cursor, Claude Code or Codex

Further Reading

After install

What you get after install

Every report arrives in your inbox or tracker with the evidence already attached:

  • The element

    What the reporter pointed at: label, component and selector. Errors tied to it are outlined in red.

  • Console and JS errors

    With file and line, captured up to the moment of the report.

  • Network requests

    Status, URL and request and response bodies, failed and successful.

  • Session replay

    The moments leading up to the bug, with repro steps.

  • Environment

    URL, browser, OS and viewport, plus the screenshot. On paid plans, also video.

Optional

Connect your agent

Add the SnagRelay MCP server once, then paste a prompt that tells your agent to call get_issue_context. After you review the fix, mark_issue_resolved emails the reporter. MCP is on every plan.

https://mcp.snagrelay.com/v1

Add this URL as a remote MCP server, then click Allow. Paste a prompt that tells the agent to call get_issue_context, then mark_issue_resolved only after you have reviewed the fix.

More articles

Fix bugs with Cursor, Claude Code or Codex

Send your agent the whole bug, not a screenshot.

Add one script tag. Every report reaches your agent over MCP with the element, the console error and the failing request.

Start free, connect my agent

Free plan. No card. Set up in minutes.

See the agent flow