guide ยท sveltekit
Add an 18 KB Bug Report Widget to SvelteKit
How do you add a bug report widget to SvelteKit? Paste BugSnap's 18 KB defer script before </body> in src/app.html. It persists across client-side navigations with zero runtime dependencies, masks sensitive inputs before capture, and attaches up to 20 recent errors at $0 forever.
1. add it to src/app.html
Open src/app.html and paste the tag right before </body>:
<script
src="https://getbugsnap.pages.dev/widget.js"
data-project-key="YOUR_PROJECT_KEY"
data-trigger="on-error"
defer
></script>
2. ssr and client navigation
Placing the script in src/app.html avoids Svelte component hydration overhead and keeps the on-error listener active across all SvelteKit routes. The page shell loads once, so the widget is not re-mounted on each client-side navigation.
No TypeScript setup is needed: you never import the widget, so src/app.d.ts stays unchanged.
3. why it fits sveltekit
- Zero runtime dependencies: 18 KB minified (about 8 KB gzipped), loaded with
deferso it never blocks Svelte hydration. - Invisible by default: with
data-trigger="on-error"it stays hidden until a JavaScript crash, failed API call, broken image or dead click. - Masked before capture: passwords, emails, phones, card and checkout inputs, payment iframes and
data-bugsnap-maskelements never reach the screenshot. - Markdown for AI fixes: each report includes up to 20 recent errors and copies as Markdown for Claude Code, Cursor or Codex.
Using another stack? See the Next.js, React & Vite and Astro guides. Testing a bug yourself? Scrub your console output with the free log privacy redactor, then turn it into an agent prompt with the bug report to AI prompt generator. Or go back to the BugSnap homepage.