Skip to content

fix(cooperation): skip child frames that host another extension page (#686) - #780

Open
haomint wants to merge 2 commits into
Tencent:mainfrom
haomint:fix/skip-foreign-extension-frames
Open

haomint wants to merge 2 commits into
Tencent:mainfrom
haomint:fix/skip-foreign-extension-frames

Conversation

@haomint

@haomint haomint commented Nov 19, 2026 •

Copy link
Copy Markdown

Summary

Fixes #686.

cooperate sync — and every other CDP-backed command that walks frames (observe, snapshot, navigate, debug start) — failed for the whole tab with Cannot access a chrome-extension:// URL of different extension as soon as any other installed extension injected an iframe into the page (the pattern many shopping, coupon and translate extensions use). The tab, the daemon and the BrowserSkill extension were all healthy; only observation was broken, and disabling the unrelated extension was the only workaround.


Root cause (Why)

chrome.webNavigation.getAllFrames() reports that injected frame like any other child document. collectCooperationFrames() tolerated exactly one rejection kind — a missing receiver:

if (!active || !missingReceiver(error)) throw error;

Chrome refuses tabs.sendMessage into a document owned by a different extension with Cannot access a chrome-extension:// URL of different extension, which is not a missing receiver, so it was rethrown and escaped the collection as a fatal error.

Change

  • unreachableExtensionSubtrees() — child documents that host an extension page, plus every descendant that inherits that origin (about:blank, srcdoc), are marked unreachable. They are excluded from live, so nothing messages them.

  • requireUnreachableFramesHidden() — a URL scheme is not proof that nobody can interact with a document. Before the subtree is left out, the outermost unreachable frames are proven hidden with the existing provenHiddenFrames() machinery (owner geometry, checkVisibility, focus path, pointer-events). An unreachable but displayed frame can hold controls and text fields that no collector watches, so it still fails the collection — now naming the frame instead of forwarding Chrome's raw message:

    {"code":"permission_denied","message":"Page frames cannot be observed: 2 (chrome-extension:)",
     "data":{"reason":"frame_unobservable","effect_state":"none","frames":[{"frame_id":2,"url":"chrome-extension:"}]}}
  • Release skips the proof (COOPERATION_DISABLE), because it must not block on a document it can never reach.

  • The top document stays exempt, so a tab that really is an extension page keeps its existing failure path instead of silently collecting nothing.

Tests

Four cases in browser-bridge.test.ts, all with the frame inventory and owner facts mocked:

Test Asserts
skips a hidden child frame that hosts another extension's page proven hidden → only the root is read, no repair injected, no gap
does not reach documents nested inside an unreachable extension frame an about:blank child of the extension frame is never messaged
still fails, naming the frame, when an extension frame is displayed frame_unobservable with frame_id: 2 instead of the whole sync failing on Chrome's message
releases without proving extension frames hidden COOPERATION_DISABLE never sends an owner probe

Local verification: browser-bridge.test.ts 49 passed; full extension unit suite 4108 passed / 8 skipped (pre-existing); tsc --noEmit clean; biome check clean; bilingual changelog sync passes.

Revision note

The first version skipped any extension-hosted child frame on the strength of its URL alone. Review was right that this hides a real safety hole: CooperationController.humanActive() only scans collected frames, so automation could be authorized while the user was interacting inside a visible foreign widget. The current version keeps that proof requirement.

Notes

An unrelated extension that injects a hidden chrome-extension:// iframe
(the pattern many shopping and translate extensions use) made every
collection for the tab fail with "Cannot access a chrome-extension://
URL of different extension". collectCooperationFrames tolerated only a
missing receiver, so this rejection escaped as a fatal error and
cooperate sync, observe, snapshot, navigate and debug start all failed
while the tab itself was healthy.

Skip child documents that host an extension page before messaging them.
Such a document cannot carry human input, so leaving it out cannot
conceal activity, and the top document is exempt so a tab that really is
an extension page keeps its existing failure path.

Refs Tencent#686
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-19T06:49:35.805423Z 5d21345 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5d213456a7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

gaps.push({ ...frameIdentity(frame), reason: "inactive_document" });
return false;
}
if (isChildExtensionPage(frame)) return false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Retain visibility checks for extension-hosted frames

If another extension injects a visible or focused iframe, this skips it exactly like a hidden one, although extension documents can contain clickable controls and text fields. The parent collector cannot observe events inside that document, and CooperationController.humanActive() only scans collected frames, so a fresh sync can authorize automation while the user is still interacting there. Previously the frame had to be proven hidden by provenHiddenFrames() or collection failed. Keep that hidden/unfocused-owner proof for this exemption instead of treating the URL scheme as proof that human input is impossible.

Useful? React with 👍 / 👎.

gaps.push({ ...frameIdentity(frame), reason: "inactive_document" });
return false;
}
if (isChildExtensionPage(frame)) return false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve hidden ancestry when filtering extension frames

If a hidden extension iframe contains an about:blank child with an inherited extension origin, the outer frame is removed but the child is still read. Once that read fails, provenHiddenFrames() probes the inaccessible extension parent and cannot establish that the child is hidden. With mocked Chrome APIs, the parent commit succeeds for this inventory by proving the outer owner hidden and propagating that proof; this commit throws and aborts the entire collection. Preserve hidden-ancestor handling when excluding the outer frame so nested documents do not reintroduce the tab-wide failure.

Useful? React with 👍 / 👎.

Address both review findings.

A URL scheme is not proof that nobody can interact with a document: an
unreachable but displayed extension iframe can hold controls and text
fields that no collector watches, so a fresh sync could authorize
automation while the user is typing there. The outermost unreachable
frame is now proven hidden with the existing provenHiddenFrames()
machinery, and a displayed one still fails the collection - naming the
frame instead of forwarding Chrome's raw message. Release skips the
proof so it never blocks on a document it cannot reach.

Descendants of an unreachable frame inherit that origin and are
unreachable too, even when their own URL is about:blank. Marking the
whole subtree keeps nested documents from reintroducing the tab-wide
failure the proof would otherwise hit on an unreadable parent.
@haomint

haomint commented Nov 19, 2026

Copy link
Copy Markdown
Author

Both findings were right — addressed in 9f21adb.

P1 (visibility proof). Took the suggestion literally: the exemption no longer rests on the URL scheme. unreachableExtensionSubtrees() only marks the subtree; requireUnreachableFramesHidden() then proves the outermost frame hidden through the existing provenHiddenFrames() path (owner geometry, checkVisibility, focus path, pointer-events) before anything is left out. A displayed extension frame still fails the collection, so humanActive() can no longer authorize automation while the user interacts inside a foreign widget — the error now names the frame (frame_unobservable, chrome-extension:) instead of forwarding Chrome's message. COOPERATION_DISABLE skips the proof so release never blocks on an unreachable document.

P2 (hidden ancestry). Descendants of an unreachable frame inherit its origin, so the whole subtree is marked, not just the outer frame. That also removes the case where an about:blank child was read while its extension parent stayed unprovable: the child is now excluded together with its ancestor and never reaches provenHiddenFrames(), so the tab-wide failure cannot come back through a nested document.

Tests: 49 in browser-bridge.test.ts, including the nested-document case and a displayed frame asserting frame_unobservable; full suite 4108 passed / 8 skipped; tsc and biome clean.

@NianJiuZst

Copy link
Copy Markdown
Collaborator

Great work!

This branch has not been deployed

No deployments
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]: cooperate sync fails with "Cannot access a chrome-extension:// URL of different extension" when another extension injects a hidden iframe

2 participants