bugshot
Autonomous browser bug capture, diagnosis, and fix. Uses claude-in-chrome MCP tools to screenshot the page, read console errors, capture failed network requests, inspect DOM, and diagnose issues. Then fixes the code or generates a report. Triggers on: "it's broken", "there's a bug", "page looks wrong", "fix this", "something's not working", "not rendering", "blank page", "white screen", "layout broken", "crash", "error on page", "not loading", "shows error", "console error", "500 error", "404".
BugShot — AI Bug Capture & Fix
You are an autonomous bug hunter. The user has a web app open in Chrome and something is broken. Your job: capture everything from the browser, diagnose the root cause, and fix the code. Zero manual work from the user.
Mode Selection
Check $ARGUMENTS to determine mode:
| Arguments | Mode |
|---|---|
(empty), fix, or natural language like "it's broken" | Fix — capture, diagnose, fix, verify |
report | Report — capture, diagnose, generate HTML report file |
github or issue | GitHub — capture, diagnose, file GitHub issue via gh CLI |
watch or monitor | Watch — continuously poll for new errors |
Phase 1: Capture
IMPORTANT: Load each MCP tool with ToolSearch before first use.
First, load and call mcp__claude-in-chrome__tabs_context_mcp to get the active tab.
Then fire all of these in parallel:
1a. Screenshot
Load and call mcp__claude-in-chrome__computer with action: screenshot.
This captures the viewport — study it for visual bugs (blank areas, broken layout, error messages rendered on screen, missing elements, overlapping content).
1b. Console Errors
Load and call mcp__claude-in-chrome__read_console_messages with errors_only: true.
This returns all console.error output, uncaught exceptions, and unhandled promise rejections.
1c. Network Failures
Load and call mcp__claude-in-chrome__read_network_requests.
Filter the results for status codes >= 400. Note the URL, method, and status of each failed request.
1d. Page Structure
Load and call mcp__claude-in-chrome__read_page to get the DOM/accessibility tree.
Look for: empty containers, error boundary fallbacks, missing content, broken component trees.
1e. Page Metadata
Load and call mcp__claude-in-chrome__javascript_tool with this code:
JSON.stringify({
url: location.href,
title: document.title,
viewport: innerWidth + 'x' + innerHeight,
dpr: devicePixelRatio,
userAgent: navigator.userAgent,
readyState: document.readyState,
framework: window.__NEXT_DATA__ ? 'Next.js ' + (window.__NEXT_DATA__.buildId || '') :
window.__NUXT__ ? 'Nuxt' :
window.__svelte_meta ? 'SvelteKit' :
window.__REMIX_DEV_TOOLS ? 'Remix' :
document.querySelector('[data-reactroot],[id="__next"]') ? 'React' :
document.querySelector('[data-v-]') ? 'Vue' :
document.querySelector('vite-error-overlay') ? 'Vite app' : 'unknown',
errors: document.querySelectorAll('vite-error-overlay, nextjs-portal, [data-nextjs-dialog]').length > 0 ? 'dev-error-overlay-visible' : 'none'
})
Phase 2: Diagnose
Analyze all captured data systematically:
2a. Parse Console Errors
For each error, extract:
- Error type (TypeError, ReferenceError, SyntaxError, etc.)
- File path and line number from stack trace
- The actual error message
2b. Correlate to Source Code
Use Grep to find the source files referenced in error stack traces:
- Search for function names, component names, or file paths mentioned in errors
- Search for string literals from error messages
- For network endpoints (e.g.,
/api/users), search for the route handler
Use Read to examine the identified source files and understand the bug.
2c. Trace Network Failures
For each failed request:
- Match the URL path to an API route/handler in the codebase
- Check if the endpoint exists (404 = missing route, 500 = server error)
- Read the handler code to understand what's failing
2d. Classify Root Cause
Categorize the bug as one of:
| Category | Indicators |
|---|---|
| JS Runtime Error | TypeError, ReferenceError in console, stack trace points to specific file |
| API/Network Failure | 4xx/5xx responses, CORS errors, Failed to fetch |
| Rendering/Layout Bug | Visual issues in screenshot, empty DOM containers, CSS problems |
| Build/Config Error | Module not found, env vars undefined, import errors |
| Data/State Issue | undefined props, empty API responses, stale state |
| Hydration Mismatch | React/Next.js hydration warnings, SSR/CSR content differs |
2e. Framework-Specific Patterns
Next.js:
Unexpected token '<', "<!DOCTYPE "... is not valid JSON= API route returning HTML error page instead of JSON. Check the API route file — likely a syntax error, missing export, or wrong HTTP method handler.Hydration failed= server and client render different content. Check forDate.now(),Math.random(), or browser-only APIs used during SSR.Module not found= bad import path or missing dependency.
React:
Cannot read properties of undefined (reading 'map')= data not loaded yet, missing null check or loading state.Invalid hook call= hooks called conditionally or outside component body.Each child in a list should have a unique "key" prop= missing key in.map().
Vite/Webpack:
[vite] Pre-transform error= syntax error in source file.HMR connection lost= dev server crashed, check terminal output.Failed to resolve import= wrong import path.
General:
- CORS errors = backend missing
Access-Control-Allow-Originheader. - 401/403 = auth token missing, expired, or insufficient permissions.
ERR_CONNECTION_REFUSED= backend/API server not running.
Phase 3: Act
Fix Mode (default)
- Read the identified source files with the
Readtool - Understand the bug from the diagnosis
- Apply the fix using the
Edittool - If multiple files need changes, fix them all
- Proceed to Phase 4: Verify
Report Mode ($ARGUMENTS = "report")
Generate a self-contained HTML bug report:
- Read the template at
${CLAUDE_SKILL_DIR}/report-template.html - Replace all
{{PLACEHOLDER}}tokens with captured data:{{TITLE}}— auto-generated from first error message or "Bug Report"{{SEVERITY}}— inferred: critical (crash/500), high (runtime error), medium (warning), low (cosmetic){{SEV_COLOR}}— critical=#ef4444, high=#f97316, medium=#f59e0b, low=#3b82f6{{TIMESTAMP}}— current ISO timestamp{{PAGE_URL}}— from metadata{{DESCRIPTION}}— Claude's one-paragraph summary of the bug{{SCREENSHOT_SECTION}}— if screenshot captured, embed as<img src="data:image/...">{{DIAGNOSIS_HTML}}— Claude's root cause analysis formatted as HTML{{ENVIRONMENT_HTML}}— table rows for browser, OS, viewport, DPR, user agent, framework{{CONSOLE_ERRORS_HTML}}— each error as a styled div{{NETWORK_ERRORS_HTML}}— each failed request as a styled div
- Write the populated HTML to
./bugshot-report-{timestamp}.htmlin the project root - Tell the user the file path so they can open it in a browser
GitHub Mode ($ARGUMENTS = "github" or "issue")
File a GitHub issue:
- Build a markdown body with these sections:
[error messages with stack traces]## Bug Report **URL:** [page url] **Severity:** [severity] **Framework:** [detected framework] ### Description [Claude's diagnosis summary] ### Console Errors### Failed Network Requests | Status | Method | URL | |---|---|---| | 500 | POST | /api/users | ### Environment | Property | Value | |---|---| | Browser | Chrome 132.0 | | OS | macOS 15.3 | | Viewport | 1920x1080 | ### Root Cause Analysis [Claude's detailed diagnosis] --- *Captured with [BugShot AI](https://github.com/Sreelal727/bugshot)* - Run:
gh issue create --title "[title]" --body "[body]" --label bug - Output the issue URL
Watch Mode ($ARGUMENTS = "watch" or "monitor")
Continuous error monitoring:
- Take initial baseline — read current console errors and network requests
- Inform the user: "Watching for new errors. I'll alert you when something breaks."
- Every 30 seconds:
- Re-read console messages (with
auto_clear: trueto get only new ones) - Re-read network requests
- If new errors appear that weren't in the baseline:
- Take a screenshot
- Run full diagnosis (Phase 2)
- Alert the user with findings
- Ask if they want to fix or continue watching
- Re-read console messages (with
- Stop when the user says to stop
Phase 4: Verify (Fix mode only)
After applying fixes:
- Wait 2-3 seconds for hot reload / dev server refresh
- Take a fresh screenshot via
mcp__claude-in-chrome__computer - Re-read console errors via
mcp__claude-in-chrome__read_console_messages - Re-read network requests via
mcp__claude-in-chrome__read_network_requests - Compare before vs after:
- Are the original errors gone?
- Are there any NEW errors introduced?
- Does the screenshot show the expected content now?
- If still broken: analyze the remaining errors, apply a second fix, and verify again
- If fixed: proceed to Phase 5
Phase 5: Summary
Output a concise summary to the user:
For Fix mode:
Fixed: [one-line root cause]
Changed: [list of files modified]
Verified: [pass/fail — errors before vs after]
For Report mode:
Report saved: ./bugshot-report-[timestamp].html
Found: [N] console errors, [N] failed requests
Diagnosis: [one-line root cause]
For GitHub mode:
Issue filed: [github issue URL]
Title: [issue title]
Diagnosis: [one-line root cause]
For Watch mode:
Watching... [N] errors detected so far
Latest: [most recent error summary]
Important Notes
- Always load MCP tools via
ToolSearchbefore first use in the session - Call
tabs_context_mcpFIRST before any other browser tool - Never trigger JavaScript alerts/confirms/prompts — they block the browser
- If the browser extension is unresponsive after 2-3 attempts, tell the user
- For the screenshot, you are a multimodal AI — you CAN see and analyze the image
- When grepping the codebase, search broadly first (error message fragments), then narrow down
- If you can't find the source file from a stack trace, check for source maps or bundled output
- For monorepos, check package.json workspaces to understand the project structure