Stage 1: messaging, state, permissions, offscreen scaffold#27
Open
juvirez wants to merge 1 commit into
Open
Conversation
Lay down the cross-context plumbing for the rewrite: typed messages between popup/service worker/offscreen, session storage for recording state, helpers for the per-origin permission request, badge timer via chrome.alarms, and an offscreen document scaffold that the service worker creates on start and closes on stop. The popup now has the real two-state UI (idle / recording) plus an "unsupported page" state for chrome:// and similar URLs. On the first Start click it requests debugger + tabCapture for the current tab's origin only (e.g. *://example.com/*) via chrome.permissions.request, so the user sees a single dialog scoped to the site rather than "all websites" at install time. No actual recording yet — that's Stages 2-5. End to end the START / STOP flow now works: badge ticks, offscreen document spawns and closes, state survives popup close, and tab closure mid-record is detected via chrome.tabs.onRemoved and triggers cleanup.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cross-context plumbing for the rewrite. No actual recording yet — Stages 2–5 will add tabCapture+MediaRecorder in the offscreen document, CDP-based HAR/console, and the zip assembly. This PR makes the START/STOP flow round-trip cleanly between popup, service worker, and offscreen.
What's in this PR
New shared code
src/types/messages.ts—Requestdiscriminated union (START,STOP,GET_STATUS) +Statusresponse typesrc/lib/messaging.ts— typedsendMessage<R>()andonMessage(handler)wrappers (async response viareturn true)src/lib/state.ts—getState/setState/clearStateoverchrome.storage.session, so recording state survives service-worker suspensionsrc/lib/permissions.ts—originPattern(url)to derive*://example.com/*, plusrequestRecorderPermissions(origin)/hasRecorderPermissions(origin)Service worker (
src/background/index.ts)START: writes session state, ensures offscreen document exists, startschrome.alarmsbadge tick, sets badge textSTOP: clears state and alarm, clears badge, closes offscreen documentGET_STATUS: returns recording state for the popupchrome.tabs.onRemoved: if the recording tab is closed, cancels the sessionOffscreen scaffold
src/offscreen/index.html+src/offscreen/index.ts— empty document that just logs on load. Wired throughvite.config.tsrollup input so CRXJS bundles it. Stage 2 will add the MediaRecorder here.Popup (
src/popup/App.tsx)idle(with optional "permissions denied, try again" caption),recording,unsupported(forchrome://etc.)Startclick: derives origin pattern from active tab URL and callschrome.permissions.request({ permissions: ['debugger', 'tabCapture'], origins: [pattern] }). The user sees one dialog scoped to the current site rather than "all websites". If denied, the popup stays open with a retry caption.window.close()after dispatching START/STOP so the action badge takes over as the live status indicator.Test plan
pnpm install && pnpm buildsucceed; offscreen ends up atdist/src/offscreen/index.htmland the service worker loader atdist/service-worker-loader.jstsc -bpasses with no errorschrome://extensions(Load unpacked →dist/):chrome://extensions0:01,0:02, … ticking every secondWhat's not in this PR
chrome.debugger.attach+ Network domain → HAR viachrome-harnpm (fixes the cached-resource timing bug)Runtime.consoleAPICalled/Runtime.exceptionThrown<a download>(so nodownloadspermission needed)onDetachcancellation, SW restart recoveryhttps://claude.ai/code/session_017HbCsooFaMcc15JCHrbbj3
Generated by Claude Code