Skip to content

fix(chrome-extension): keep recorder screenshots on their source tab - #3194

Open
dakjdakd wants to merge 1 commit into
web-infra-dev:mainfrom
dakjdakd:fix/chrome-recorder-source-screenshots
Open

dakjdakd wants to merge 1 commit into
web-infra-dev:mainfrom
dakjdakd:fix/chrome-recorder-source-screenshots

Conversation

@dakjdakd

@dakjdakd dakjdakd commented Sep 24, 2026 •

Copy link
Copy Markdown

Fixes #3193

The recorder's content script sends its screenshot request from the tab that produced an event, but chrome.tabs.captureVisibleTab(windowId) captures whichever tab is active in that window. Because the recorder takes an after-action screenshot after a short event delay, switching tabs at that point could attach a different page's image to the event. A check immediately before capture alone would not cover a switch away and back while the capture is pending.

I moved the capture decision into captureTabScreenshot. It uses the tab ID supplied by the message sender to check the active tab in that window before calling captureVisibleTab. It then checks again before returning the image. An onActivated listener spans that entire interval and marks the capture invalid if another tab becomes active in the same window, including the A→B→A case where both active-tab queries would otherwise see A. The listener is removed in finally, so it does not remain registered after a completed or rejected capture.

The worker now sends null when the source tab is inactive or changes during capture. The recorder's existing empty-screenshot handling can then proceed without attaching another tab's image. Capture errors still return null through the worker's error path.

The regression tests exercise four cases: a source tab that stays active, one that is already inactive, a switch to another tab during capture, and a switch away and back before capture completes. The latter specifically guards the gap left by checking only before and after the API call.

Validation completed:

  • pnpm run lint
  • pnpm exec nx build chrome-extension
  • pnpm exec nx test chrome-extension — 58 tests passed
  • pnpm exec tsc -p apps/chrome-extension/tsconfig.json --noEmit --pretty false

Recorded events now retain screenshots only when the image can be attributed to the tab that produced the event.

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.

[Bug]: Recorder can attach another tab's screenshot after a tab switch

1 participant