Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add: window.__abs_dumpTrace bridge for CDP debug-trace retrieval#223

Merged
twschiller merged 3 commits into
mainfrom
worktree-soft-tinkering-dahl
Jun 9, 2026
Merged

Add: window.__abs_dumpTrace bridge for CDP debug-trace retrieval#223
twschiller merged 3 commits into
mainfrom
worktree-soft-tinkering-dahl

Conversation

@twschiller

Copy link
Copy Markdown
Contributor

Summary

  • Exposes window.__abs_dumpTrace() in the top frame's MAIN world whenever the debug-trace recorder is on — either the debugTrace: true build flag (CDP-driven harnesses like Browserbase/Hermes/browser-use/OpenClaw) or the popup toggle (Chrome Web Store installs). CDP clients call it via Runtime.evaluate("(async () => await window.__abs_dumpTrace())()", { awaitPromise: true }) to scrape the per-tab mutation record mid-run without needing the popup's Export button.
  • New page-world bridge (dump-trace-bridge-source.ts) ↔ isolated content-script bridge (dump-trace-content-bridge.ts) ↔ background (get-tab-debug-trace message) ↔ IDB (getEventsForTab). Registered/unregistered by dump-trace-bridge-registration.ts on every debugTraceStorage change so flipping the popup toggle reaches the next navigation.
  • Consolidates the recipe into a new /debug-trace/ docs page (single source of truth). install.md plus the four CDP integration docs (browserbase-python.md, hermes-agent.md, browser-use.md, openclaw.md) get short "Investigating a false positive" pointers instead of duplicating the recipe.

Test plan

  • bun run check (biome + eslint) — clean
  • bun run test — 1905/1905 pass; 20 new tests across dump-trace-bridge-registration.test.ts, dump-trace-content-bridge.test.ts, dump-trace-bridge-source.test.ts
  • bun run build — extension bundles cleanly with the new dump-trace-bridge.js entry
  • pre-commit run on the touched docs — mdformat + markdownlint pass
  • astro build — 9 pages built, new /debug-trace/ route resolves
  • Load unpacked with debugTrace: true defaults; confirm typeof window.__abs_dumpTrace === "function" and that await window.__abs_dumpTrace() returns entries matching the popup Export
  • Build without debugTrace; confirm window.__abs_dumpTrace is undefined; flip popup toggle, reload, confirm it appears; flip off, reload, confirm it's gone
  • Drive a real CDP session (Playwright over CDP) and confirm the Runtime.evaluate recipe from the docs returns entries

🤖 Generated with Claude Code

Exposes window.__abs_dumpTrace() in the top frame's MAIN world whenever
the debug-trace recorder is on (build-flag default or popup toggle) so
CDP-driven harnesses can scrape the per-tab mutation record via
Runtime.evaluate to investigate false positives without a human flipping
the popup toggle. Centralizes the recipe in a new debug-trace docs page;
install.md and the four CDP integration docs link out instead of
duplicating.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@vercel

vercel Bot commented Jun 9, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agent-browser-shield-demo-site Ready Ready Preview, Comment Jun 9, 2026 2:45am

Request Review

@unblocked unblocked Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found.

About Unblocked

Unblocked has been set up to automatically review your team's pull requests to identify genuine bugs and issues.

📖 Documentation — Learn more in our docs.

💬 Ask questions — Mention @unblocked to request a review or summary, or ask follow-up questions.

👍 Give feedback — React to comments with 👍 or 👎 to help us improve.

⚙️ Customize — Adjust settings in your preferences.

postResponse(id, { error: String(error) });
return;
}
postResponse(id, { entries: response.entries });

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chrome.runtime.sendMessage resolves with undefined when the background listener returns undefined without calling sendResponse — which happens here when the get-tab-debug-trace handler has no valid tabId (line 442-444 of background.ts). In that case response is undefined and response.entries throws TypeError: Cannot read properties of undefined (reading 'entries').

The popup's own sendMessage call in use-tab-detections.ts correctly types the response as … | undefined and uses response?.entries ?? []. This code should do the same:

Suggested change
postResponse(id, { entries: response.entries });
postResponse(id, { entries: response?.entries ?? [] });

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 7ec3e85 — widened the variable to GetTabDebugTraceResponse | undefined and switched to response?.entries ?? [], mirroring the popup's use-tab-detections.ts pattern. Added a regression test in dump-trace-content-bridge.test.ts that mocks sendMessage to resolve with undefined (the missing-tabId case) and asserts an empty-entries response goes back to the page instead of a TypeError. Good catch — this would have hit any off-tab caller in production. — Claude Code, on behalf of @twschiller

The biome auto-fix rewrote `window` → `globalThis` for the same-window
comparison, but TypeScript's `typeof globalThis` doesn't structurally
satisfy `MessageEventSource`. Hold a `Window`-typed alias once and use
it for the comparison and postMessage origin so both biome and tsc are
happy. Add the dump-trace bundle entrypoint to knip's allow-list
alongside the other probe entrypoints.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
When sender.tab?.id is missing the background's get-tab-debug-trace
handler returns undefined without calling sendResponse, so
chrome.runtime.sendMessage resolves with undefined and the previous
response.entries dereference crashed with TypeError. Widen the type to
GetTabDebugTraceResponse | undefined and fall back to an empty entries
array. Add a regression test covering the undefined-reply path.

Caught by Unblocked review on PR #223.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@twschiller twschiller merged commit 4733d1b into main Jun 9, 2026
7 checks passed
@twschiller twschiller deleted the worktree-soft-tinkering-dahl branch June 9, 2026 02:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant