Repository navigation
feat(extension): Wave 5A zero-tax MV3 runtime injection, orphan window reaping, and shared dom-primitives - #754
Merged
NianJiuZst merged 1 commit intoNov 16, 2026
Conversation
…w reaping, and shared dom-primitives Why: 1. Static <all_urls> content_scripts in manifest.json forced every ordinary user tab and subframe to load React 19 UI bundles, broadcast WXT content-script-started window.postMessage events, or fire startup wakeup IPC, while bh.sessions_live had decayed into write-only dead code. 2. When an MV3 Service Worker died after daemon sessions ended, dedicated Agent Windows created before the crash could remain orphaned on the user's desktop. 3. Duplicated DOM helpers across cooperation-capture and record-capture left cross-module bugs: dead Isolated World history.pushState patching, data-bsk-* / overlay host mutations advancing FrameState.structure, interactions or hover surfaces inside extension ShadowRoot overlays being mis-recorded as webpage steps, and unsequenced/un-pierced runtime subframe injections risking undefined message replies. What: - Migrate all 4 content script entrypoints (content, cooperation.content, record-frame.content, long-screenshot-page.content) to WXT registration: "runtime" with noScriptStartedPostMessage: true and claimIdempotentContentScript mount guards, and strip static content_scripts (and duplicate host_permissions) from dist/chrome-mv3/manifest.json. - Inject Tier A (content.js and long-screenshot-page.js) per tabId/documentId on demand via idempotent ensureOverlayInjected across controlled task tabs, webNavigation.onCommitted (including Speculation Rules prerender outermost frames, sequenced strictly after Tier B cooperation.js arming/repair), pre-confirmation borrow candidate tabs, request_help, record, and active video overlays; skip uninjected tabs on hidden / CAPTURE_SUPPRESS / INPUT_PASSTHROUGH and re-verify ownership after async injection. - Coordinate Tier B (cooperation.js and record-frame.js) via RuntimeContentScriptCoordinator with persistAcrossSessions: false when liveSessions or activeRecordings > 0 and unregisterContentScripts() at 0; load silently at document_start with 0 DOM listeners, 0 startup IPC, and 0 window.postMessage noise until armed by Background with 50ms per-tab subframe coalescing; co-inject cooperation.js alongside record-frame.js in injectRecordFrameAllFrames, sequence injectCooperationAllFrames ahead of pushOverlayStateForTab on tab claim, and probe per-frame COOPERATION_ARM_FRAME across tab_borrow, record_start, COOPERATION_SUBFRAME_READY (preserving subframeNeedsInject across debounce resets), ack === undefined frames, and dynamic light-DOM or open/closed ShadowRoot about:blank / srcdoc / object / embed / fencedframe subframes; delete dead sessions-live-flag.ts. - Track dedicated Agent Window ownedTabIds in chrome.storage.session (bsk.orphan_agent_windows) via OrphanAgentWindowLedger and reap pure orphan Agent Windows on SW startup without closing windows containing user, borrowed, or human-preserved tabs. - Extract shared apps/extension/src/content/dom-primitives.ts, delete Isolated World history.pushState/replaceState patching in record-capture.ts, filter data-bsk-* and <browser-skill-overlay> mutations from cooperation-capture.ts, exclude extension ShadowRoot UI events and hover surfaces across record-capture.ts, record-hover-surface.ts, and cooperation-capture.ts, and wire runtime-injection.browser.test.ts into CI.
NianJiuZst
force-pushed
the
feat/wave5a-mv3-runtime-injection
branch
from
November 15, 2026 20:56
e2daf41 to
9892196
Compare
NianJiuZst
added a commit
to shunxinyi-ljs/BrowserSkill
that referenced
this pull request
Nov 16, 2026
…ncent#724) Why: 1. Main advanced past 0.5.0 through Wave 2-5A (Tencent#731-Tencent#754) and Tencent#749, creating adjacent [Unreleased] merge conflicts in CHANGELOG.md and CHANGELOG.zh-CN.md. 2. Tencent#731/Tencent#732 unified real-browser suites on BSK_TEST_CHROME and enforced via scripts/run-browser-tests.test.mjs that every *.browser.test.ts suite is registered in .github/workflows/ci.yml with zero skipped assertions. What: - Merge origin/main and place the bilingual Tencent#594/Tencent#724 changelog entries under [Unreleased] -> Fixed / 修复. - Migrate apps/extension/src/content/__tests__/record-editor-value.browser.test.ts from legacy BSK_CLICK_CHROME to BSK_TEST_CHROME. - Register src/content/__tests__/record-editor-value.browser.test.ts in .github/workflows/ci.yml alongside record-input-buttons.browser.test.ts.
NianJiuZst
added a commit
to NianJiuZst/BrowserSkill
that referenced
this pull request
Nov 17, 2026
… cold 2x full-page captures Why: - After Wave 5A (Tencent#754) moved `content.js` to lazy runtime injection, cold 2x DPR SwiftShader full-page captures (`agent.browser.test.ts` `scale = 2` on 2-vCPU Linux CI runners) can overlap initial Tier-A ShadowRoot CSS/React mount and `CAPTURE_SUPPRESS` two-frame compositing with `runBrowserMutation` frame collection, intermittently exceeding the 1200ms per-frame IPC deadline with `FrameUnresponsiveError` (`effect_state: "none"`). - `guardedRunner.runBrowserMutation` also invoked `beginDomMutation()` followed immediately by `prepare()`, issuing two redundant back-to-back full-tab `collectCooperationFrames` sweeps per call, while `handleFullPageScreenshot` wrapped passive read-only `inspect` probes in `runBrowserMutation`. What: - Call `prepare(undefined, "Browser.mutate")` directly in `runBrowserMutation` (`action-guard.ts`), preserving full decision/expectation and pending-gesture verification in a single frame sweep before `dispatch(true, "Browser.mutate")`. - Skip `runBrowserMutation` on passive `inspect` probes in `handleFullPageScreenshot` (`screenshot-full-page.ts`). - Raise `FRAME_REPLY_TIMEOUT_MS` (`browser-bridge.ts`) and `OWNER_REPLY_MS` (`hidden-frames.ts`) from `1200ms` to `3000ms`.
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.
Why (根因与动机)
<all_urls>content_scriptsinmanifest.jsonpreviously forced every ordinary user tab and subframe to load React 19 UI bundles, dispatch WXTwxt:content-script-startedwindow.postMessagebroadcasts, or emit startup wakeup IPC, whilebh.sessions_live(sessions-live-flag.ts) had decayed into write-only dead code.cooperation-capture.tsandrecord-capture.tsleft dead Isolated Worldhistory.pushState/replaceStatemonkey-patching, allowed internaldata-bsk-*/<browser-skill-overlay>mutations to advanceFrameState.structure, risked recording interactions or hover surfaces inside extension ShadowRoot overlays as webpage trace steps, and needed deterministiccooperation.js-before-content.js/record-frame.jsordering plus open/closedShadowRootsubframe traversal sochrome.tabs.sendMessagenever encounters anundefinedreply on a live document withoutcooperation.js.What (核心改动与解法边界)
manifest.jsoncontent_scripts& idempotent runtime entrypoints:content.ts,cooperation.content.ts,record-frame.content.ts, andlong-screenshot-page.content.ts) to WXTregistration: "runtime"withnoScriptStartedPostMessage: trueandclaimIdempotentContentScriptmount guards (bsk.overlay.mounted,bsk.cooperation.mounted,bsk.record_frame.mounted,bsk.long_screenshot_page.mounted), stripping staticcontent_scripts(and duplicatehost_permissions) fromdist/chrome-mv3/manifest.json.content.js,long-screenshot-page.js) & strict ordering after Tier B:tabId/documentIdidempotentensureOverlayInjectedacross controlled task tabs,webNavigation.onCommitted(including Speculation Rules prerenderoutermost_frames), pre-confirmationtab_borrowcandidate user tabs,request_help,record, and activevideooverlays.pushOverlayStateForTabstrictly afterinjectCooperationAllFramesononAgentTabClaimed, and invokedensureOverlayInjectedfromattachCooperation'sonOutermostFrameArmedcallback afterarmCommittedFramesettles, ensuring Tier A'sonMessagelistener is never mounted on a controlled document ahead ofcooperation.js.hidden/CAPTURE_SUPPRESS/INPUT_PASSTHROUGHand re-verified ownership after async injection so mid-injection detach/return never flashes stale control UI.cooperation.js,record-frame.js):RuntimeContentScriptCoordinatorregistering Tier B scripts withpersistAcrossSessions: falsewhenliveSessions + activeRecordings > 0and callingunregisterContentScripts()when counts return to0.document_startwith 0 DOM listeners, 0 startup IPC, and 0window.postMessagenoise until armed by Background (COOPERATION_ARM_FRAME/RECORD_FRAME_START) with 50ms per-tab subframe coalescing (COOPERATION_SUBFRAME_READY/subframe_added).[cooperation.js, record-frame.js]ininjectRecordFrameAllFrames, preservedsubframeNeedsInjectacrossscheduleObserveTabdebounce resets, pierced open and closedShadowRoots (openOrClosedShadowRoot) acrosshasAddedSubframeElement,cooperation-capture.ts, andframe-agent.ts, and probed per-frameCOOPERATION_ARM_FRAMEviainjectCooperationAllFramesacrosstab_borrow,record_start,COOPERATION_SUBFRAME_READY,ack === undefinedframes, and dynamically inserted light-DOM, nested grandchild, or closed-ShadowRootabout:blank/srcdoc/object/embed/fencedframesubframes.apps/extension/src/lib/sessions-live-flag.ts.OrphanAgentWindowLedger(chrome.storage.sessionkeybsk.orphan_agent_windows) trackingownedTabIdsper dedicated Agent Window and reaping pure orphan Agent Windows on Service Worker restart while strictly preserving any window containing user, borrowed, or human-preserved tabs.apps/extension/src/content/dom-primitives.ts& CI integration:dom-primitives.ts, removed dead Isolated Worldhistory.pushState/replaceStatepatching fromrecord-capture.ts, filtereddata-bsk-*and<browser-skill-overlay>mutations incooperation-capture.ts, excluded extension ShadowRoot UI events and hover surfaces acrossrecord-capture.ts,record-hover-surface.ts, andcooperation-capture.ts, updated bilingualCHANGELOG.md/CHANGELOG.zh-CN.md, and wiredsrc/entrypoints/__tests__/runtime-injection.browser.test.tsinto.github/workflows/ci.yml.Adversarial Verification (对抗反例验证)
getRegisteredContentScripts() === [], 0<browser-skill-overlay>hosts, 0window.postMessagenoise, and 0 cooperation receivers on ordinary/bystander user tabs before and during active sessions, while on-demand Tier A injection renders thetab borrowAllow modal on the candidate user tab prior to ownership transfer.about:blank/srcdoc+ Speculation Rules prerender): Verified repeatedexecuteScriptofcontent.jsandcooperation.jspreserves singleton<browser-skill-overlay>state and every frame'sFrameState.documentUUID/lease, 50ms debouncedCOOPERATION_SUBFRAME_READYarms dynamicabout:blankandsrcdociframes, and prerenderedoutermost_frameretains its overlay across activation.about:blanksubframes & overlay isolation): Verifieddata-bsk-*and overlay mutations do not advanceFrameState.structure, dynamic child, nested grandchild, and closed-ShadowRootabout:blanksubframes inserted during activebsk record startreceive bothrecord-frame.jsandcooperation.jswithout failingcooperation.readonundefinedreplies, clicks across all 3 dynamicabout:blanksubframes + main page are recorded intotrace.jsonwhile ShadowRootFinishclicks are excluded, and Tier B registrations return to[]after stop.Tiered Testing Verification (分层验证记录)
pnpm --filter @browser-skill/extension exec tsc --noEmitpnpm ext:build+ verifiedapps/extension/dist/chrome-mv3/manifest.jsonhascontent_scripts === undefinednpx biome checkacross all 34 modified TS/JSON files,npx stylelint "apps/extension/src/**/*.css",python3 scripts/check-changelog-sync.py feb17309cargo fmt --all -- --check,cargo clippy --workspace --all-targets --locked -- -D warnings,node scripts/check-crate-skill.mjs,node scripts/check-skill-bundles.mjsrg-targeted Unit & Protocol Contract Tests):cargo test -p bsk-protocol --locked(182 passed)pnpm --filter @browser-skill/extension exec vitest runon all 12rg-matched unit test suites (531 passed across 3 consecutive runs)node scripts/run-browser-tests.mjs src/entrypoints/__tests__/runtime-injection.browser.test.ts src/content/__tests__/cooperation-capture.browser.test.ts(2 suites passed, 0 skipped)node scripts/run-browser-tests.mjs src/cooperation/hidden-frames.browser.test.ts src/content/__tests__/record-input-buttons.browser.test.ts(2 suites / 11 tests passed, 0 skipped)