Skip to content

fix(screenshot): hide overlays during capture so shots only contain page content - #64

Open
BB-fat wants to merge 1 commit into
mainfrom
fix/screenshot-exclude-overlay
Open

fix(screenshot): hide overlays during capture so shots only contain page content#64
BB-fat wants to merge 1 commit into
mainfrom
fix/screenshot-exclude-overlay

Conversation

@BB-fat

@BB-fat BB-fat commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

Problem

bsk screenshot (and element screenshots via Page.captureScreenshot) capture the extension's in-page overlays — the Agent-control mask, help/record/borrow panels — because they are DOM injected by the content script (shadow host with data-bsk-overlay). Agents end up with screenshots polluted by BSK's own chrome instead of pure page content.

Fix

Suppress overlays around every capture, with a painted-frame guarantee:

  1. overlay.css: new :host([data-bsk-capture-hidden]) { display: none !important; } rule — hiding the host removes the whole shadow tree from compositing.
  2. Content side (content/capture-suppress.ts): on begin it sets the attribute (refcounted for concurrent captures), then waits two requestAnimationFrames before ack'ing, so the compositor has produced a frame without the overlay before any capture runs. end decrements and restores at zero. Host remounts mid-suppression keep the hidden attribute. A 500ms rAF fallback prevents deadlock on hidden tabs (rAF never fires there; the attribute is applied synchronously, so any composited frame is still overlay-free).
  3. Background side (lib/capture-suppress-bridge.ts): withOverlaysHiddenForCapture(tabId, fn) — begin (await ack) → capture → finally end. If the tab has no content script (chrome:// etc.), begin fails and the capture proceeds directly (no overlay can exist there anyway).
  4. tools/observation.ts: both capture paths wrapped — element clip via CDP and full-page captureVisibleTab.

No protocol/CLI changes; behaviour fix only.

Tests

  • 13 new vitest cases: content-side controller (attribute set/remove, two-frame ack, refcount, stray end, host remount), bridge (begin→capture→end ordering, capture error still restores, no-content-script passthrough, end-failure swallowed), and handleScreenshot integration asserting capture happens while hidden.
  • pnpm lint, tsc --noEmit, wxt build: clean.
  • Full vitest: 507 passed; the 41 React.act tsx failures are identical to the base commit (pre-existing env issue).

@BB-fat
BB-fat requested review from Ljy-0827, iuyo5678 and shnpd August 7, 2026 07:00
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