guide ยท astro
How to add an 18 KB bug report widget to Astro
Add BugSnap's single deferred <script> tag to src/layouts/Layout.astro before </body>. It is 18 KB (about 8 KB gzipped), has zero dependencies, needs no Astro integration or session-replay middleware, and is $0 forever.
1. add it to src/layouts/Layout.astro
Open your base layout and paste the snippet right before </body>. is:inline tells Astro to leave the tag as written instead of bundling it:
---
const bugsnapKey = import.meta.env.PUBLIC_BUGSNAP_KEY;
---
<html lang="en">
<body>
<slot />
<script
is:inline
src="https://getbugsnap.pages.dev/widget.js"
data-project-key={bugsnapKey}
data-trigger="on-error"
defer
></script>
</body>
</html>
Put PUBLIC_BUGSNAP_KEY in .env. The PUBLIC_ prefix makes it available when the page renders.
2. why it fits Astro's zero-bloat approach
- No hydration cost: a small deferred script. No React or Vue island just to show a bug form.
- Invisible by default: with
on-error, your docs, marketing site or app stays clean until a visitor hits a broken image, failed API call, JavaScript crash or dead click. - Masked before capture: passwords, emails, card inputs and payment iframes are masked before the screenshot is drawn, and there is no always-on session replay.
- Markdown for AI fixes: copy any report as Markdown for Claude Code, Cursor or Codex, or send it to GitHub Issues. Try the format with the free bug report to AI prompt generator.
Want the details? Read how BugSnap masks cards, passwords and tokens before a screenshot exists, and how to turn live bug reports into prompts for AI coding agents.