Repository navigation
feat(browser): send pages to OpenClaw from the Chrome extension - #111158
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3a8b0569f2
ℹ️ 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".
| content: truncateShareText(normalizedContent, PAGE_SHARE_MAX_CONTENT_CHARS), | ||
| ...(normalizedSelection | ||
| ? { selection: truncateShareText(normalizedSelection, PAGE_SHARE_MAX_CONTENT_CHARS) } |
There was a problem hiding this comment.
Omit full-page content when a selection exists
When a normal page has selected text, capturePageContent returns both the selection and the extracted full page, and this builder preserves both fields; sendPageShareRequest then serializes the entire payload to the Gateway. Although deliverPageShare later ignores content, the rest of the page has already crossed the relay, violating the selection-only privacy promise in docs/tools/chrome-extension.md:148-154. Clear or omit content whenever normalizedSelection is nonempty.
Useful? React with 👍 / 👎.
|
Codex review: needs real behavior proof before merge. Reviewed July 19, 2026, 4:04 AM ET / 08:04 UTC. Summary PR surface: Source +667, Tests +339, Docs +25, Generated 0, Other +2. Total +1033 across 24 files. Reproducibility: yes. from source: focus a child iframe, select text in it, then use the popup or Alt+Shift+S path; the final implementation’s documented tradeoff falls back to top-level extraction rather than preserving that selection. Review metrics: none identified. Stored data model Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Proof guidance:
Risk before merge
Maintainer options:
Next step before merge
Maintainer decision needed
Security Review findings
Review detailsBest possible solution: Make every entry point selection-safe: capture the focused frame’s selection where possible, otherwise stop with a clear instruction to use the selection context menu rather than falling back to full-page extraction. Do we have a high-confidence way to reproduce the issue? Yes, from source: focus a child iframe, select text in it, then use the popup or Alt+Shift+S path; the final implementation’s documented tradeoff falls back to top-level extraction rather than preserving that selection. Is this the best way to solve the issue? No. The relay and external-content wrapper are appropriate, but accepting a full-page fallback for an iframe-owned selection is not the narrowest safe implementation; capture the focused frame or fail closed. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against a8b7290f346c. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +667, Tests +339, Docs +25, Generated 0, Other +2. Total +1033 across 24 files. View PR surface stats
Security concerns:
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
Review history (3 earlier review cycles)
|
3a8b056 to
85b7253
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 85b725314e
ℹ️ 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".
| const pageShare = await import("./browser/extension-relay/page-share.js"); | ||
| // Plugin services start only in the Gateway process. The sink marks this | ||
| // process as able to deliver page shares to the main session. | ||
| pageShare.setPageShareSink(pageShare.createGatewayPageShareSink()); |
There was a problem hiding this comment.
Initialize page sharing from the lazy service wrapper
When OPENCLAW_EAGER_BROWSER_CONTROL_SERVER is unset (the default), createLazyBrowserPluginService.start returns at extensions/browser/plugin-registration.ts:192-195 before loading this service, so this sink registration never runs. The direct Gateway route and browser requests can still lazily start the control service and create a relay whose onPageShare calls deliverPageShare, but pageShareSink remains null; consequently every page share in the default configuration responds with PAGE_SHARE_GATEWAY_REQUIRED_ERROR. Register the sink lifecycle in the default wrapper/Gateway path rather than only in the eager-loaded service.
Useful? React with 👍 / 👎.
| async function sendPageToOpenClaw(tabId, note) { | ||
| await ensureRelayReady(); | ||
| const tab = await chrome.tabs.get(tabId); | ||
| const capture = await capturePageShare(tab); |
There was a problem hiding this comment.
Capture the page before waiting for relay reconnection
When a paired relay is disconnected, this wait can last three seconds before chrome.tabs.get and content capture occur. If the user invokes the page context-menu action, shortcut, or popup send and then navigates, a same-origin navigation sends the new document instead of the page they explicitly shared, while a cross-origin navigation can revoke activeTab and make the share fail. Capture the user-action-time document before reconnecting, as the selection context-menu path already does.
Useful? React with 👍 / 👎.
|
ClawSweeper status: review started. I am starting a fresh review of this pull request: feat(browser): send pages to OpenClaw from the Chrome extension This is item 1/1 in the current shard. Shard 0/1. This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking. Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cc1fe95239
ℹ️ 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".
| if (parsed.hostname !== "docs.google.com") { | ||
| return null; | ||
| } | ||
| return /^\/document\/d\/([^/]+)/u.exec(parsed.pathname)?.[1] ?? null; |
There was a problem hiding this comment.
Handle account-qualified Google Docs URLs
When Google account routing produces a URL such as https://docs.google.com/document/u/1/d/<id>/edit, this matcher returns null because it only accepts /document/d/.... capturePageShare then skips the text export and applies generic DOM extraction to the Docs editor, which can return interface or incomplete canvas content instead of the document promised by this feature. Accept the optional /u/<account-index> path segment before /d/.
Useful? React with 👍 / 👎.
cc1fe95 to
20101e3
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 20101e3987
ℹ️ 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".
|
|
||
| /** Self-contained because chrome.scripting serializes this function source. */ | ||
| function capturePageContent() { | ||
| const selection = window.getSelection()?.toString().trim() ?? ""; |
There was a problem hiding this comment.
Fail closed when a child frame owns the selection
When a user highlights text inside an iframe and invokes the toolbar or Alt+Shift+S instead of the selection context menu, this reads only the top-frame selection, so it returns empty; extraction subsequently removes the iframe and silently sends the surrounding top-level page. This violates the selection-first privacy behavior documented in docs/tools/chrome-extension.md:148-154. This is separate from the already-flagged detected-selection issue because here the selection is never detected; detect a focused child frame and capture it or refuse the share rather than falling back to the full page.
Useful? React with 👍 / 👎.
| await this.onPageShare(payload); | ||
| this.sendPageShareResult({ requestId, ok: true }); |
There was a problem hiding this comment.
Return page-share results to the originating socket
If the MV3 worker reconnects while onPageShare is awaiting delivery, this acknowledgment is sent through the mutable current this.extension, not the socket that submitted the request. A restarted worker resets nextPageShareRequestId to 1, so a delayed success or error for the previous worker's request 1 can resolve or reject the new worker's unrelated request 1, producing a false result. Bind each response to its originating socket or connection generation.
Useful? React with 👍 / 👎.
One-click page share in the OpenClaw Chrome extension: toolbar popup with an optional note, page/selection context menu, and Alt+Shift+S. Capture is selection-first with a readability heuristic, X/Twitter thread extraction, and Google Docs plain-text export via the user's session cookies. Payloads ride the existing paired relay WebSocket as a new pageShare message; the gateway-only page-share sink wraps page text in the external-content safety boundary, then enqueues a main-session system event and requests an immediate heartbeat (hooks/wake semantics). Node-hosted relays report a clear unsupported error. Capture heuristics adapted from Nat Eliason's MIT-licensed send-to-openclaw. Co-authored-by: Codex <[email protected]>
…oundary Review findings: move title/URL inside wrapExternalContent (a hostile <title> must not become trusted header text), prefer the user's selection over the full Google Docs export, and pass the context-menu selectionText through so iframe selections and selections cleared during relay reconnect still win.
Selection shares from the context menu now send the click snapshot directly (no recapture), so navigations during relay reconnect cannot mislabel the source and iframe selections are preserved. The Google Docs selection probe scans all accessible frames before falling back to the full-document export.
All-frame injection rejects wholesale when one frame is inaccessible and returns child frames in nondeterministic order, so the probe now reads the main frame only. Child-frame selections still share correctly through the context menu's click-time selectionText; toolbar/shortcut entry sends the full page for that case (named tradeoff in the code comment).
20101e3 to
0278c7d
Compare
|
Merged via squash.
|
…claw#111158) * feat(browser): send pages to the main session from the Chrome extension One-click page share in the OpenClaw Chrome extension: toolbar popup with an optional note, page/selection context menu, and Alt+Shift+S. Capture is selection-first with a readability heuristic, X/Twitter thread extraction, and Google Docs plain-text export via the user's session cookies. Payloads ride the existing paired relay WebSocket as a new pageShare message; the gateway-only page-share sink wraps page text in the external-content safety boundary, then enqueues a main-session system event and requests an immediate heartbeat (hooks/wake semantics). Node-hosted relays report a clear unsupported error. Capture heuristics adapted from Nat Eliason's MIT-licensed send-to-openclaw. Co-authored-by: Codex <[email protected]> * fix(browser): keep page-controlled metadata inside the share safety boundary Review findings: move title/URL inside wrapExternalContent (a hostile <title> must not become trusted header text), prefer the user's selection over the full Google Docs export, and pass the context-menu selectionText through so iframe selections and selections cleared during relay reconnect still win. * fix(browser): bind context-menu shares to the click-time document Selection shares from the context menu now send the click snapshot directly (no recapture), so navigations during relay reconnect cannot mislabel the source and iframe selections are preserved. The Google Docs selection probe scans all accessible frames before falling back to the full-document export. * test(browser): expect the page-share handler in relay server args * fix(browser): probe only the main frame for Google Docs selections All-frame injection rejects wholesale when one frame is inaccessible and returns child frames in nondeterministic order, so the probe now reads the main frame only. Child-frame selections still share correctly through the context menu's click-time selectionText; toolbar/shortcut entry sends the full page for that case (named tradeoff in the code comment). * fix(browser): satisfy page-share CI gates --------- Co-authored-by: Codex <[email protected]>
…claw#111158) * feat(browser): send pages to the main session from the Chrome extension One-click page share in the OpenClaw Chrome extension: toolbar popup with an optional note, page/selection context menu, and Alt+Shift+S. Capture is selection-first with a readability heuristic, X/Twitter thread extraction, and Google Docs plain-text export via the user's session cookies. Payloads ride the existing paired relay WebSocket as a new pageShare message; the gateway-only page-share sink wraps page text in the external-content safety boundary, then enqueues a main-session system event and requests an immediate heartbeat (hooks/wake semantics). Node-hosted relays report a clear unsupported error. Capture heuristics adapted from Nat Eliason's MIT-licensed send-to-openclaw. Co-authored-by: Codex <[email protected]> * fix(browser): keep page-controlled metadata inside the share safety boundary Review findings: move title/URL inside wrapExternalContent (a hostile <title> must not become trusted header text), prefer the user's selection over the full Google Docs export, and pass the context-menu selectionText through so iframe selections and selections cleared during relay reconnect still win. * fix(browser): bind context-menu shares to the click-time document Selection shares from the context menu now send the click snapshot directly (no recapture), so navigations during relay reconnect cannot mislabel the source and iframe selections are preserved. The Google Docs selection probe scans all accessible frames before falling back to the full-document export. * test(browser): expect the page-share handler in relay server args * fix(browser): probe only the main frame for Google Docs selections All-frame injection rejects wholesale when one frame is inaccessible and returns child frames in nondeterministic order, so the probe now reads the main frame only. Child-frame selections still share correctly through the context menu's click-time selectionText; toolbar/shortcut entry sends the full page for that case (named tradeoff in the code comment). * fix(browser): satisfy page-share CI gates --------- Co-authored-by: Codex <[email protected]>
What Problem This Solves
There was no way to hand the page you are looking at to your OpenClaw agent. The community tool Nateliason/send-to-openclaw proved the demand, but it needs a separate Chrome extension plus a local Express webhook server that shells out to the CLI — an entire second install and token surface that exists only because a vanilla extension has no authenticated path to the Gateway. Our extension already owns one.
Why This Change Was Made
Fold "send this page to my agent" into the official OpenClaw Chrome extension as a third feature next to tab control and the tab copilot, riding the existing paired relay WebSocket:
Alt+Shift+Scommand. Capture is selection-first, with a readability-style heuristic, X/Twitter thread extraction, and Google Docs plain-text export fetched inside the tab so the user's cookies apply (no Google API setup). NewpageShareextension→relay message with correlatedpageShareResultacks.POST /hooks/wakesemantics exactly: system event on the main session + immediate heartbeat.wrapExternalContent(source: "browser"); the user's typed note stays outside the wrapper as their own instruction. System-tag sanitization applies at the queue boundary as usual.resolveMainSessionKeyFromConfigviaopenclaw/plugin-sdk/system-event-runtime) with the surface budget bumped +1/+1 and the ledger comment updated.Capture heuristics adapted from Nat Eliason's MIT-licensed send-to-openclaw (credit: @Nateliason).
User Impact
Pair the extension once, then send any page, Google Doc, X thread, or text selection to your main session in one click/keystroke — no extra server, port, token, or config. The tab does not need to be in the OpenClaw tab group; a share is one-shot and grants no ongoing access. Docs: new "Send a page to OpenClaw" section in
docs/tools/chrome-extension.md.Evidence
node scripts/run-vitest.mjs extensions/browser/src/browser/extension-relay/ extensions/browser/chrome-extension/modules/page-share-core.test.ts extensions/browser/src/plugin-service.test.ts extensions/browser/chrome-extension/background.test.ts→ 9 files, 54 tests passed.pnpm plugin-sdk:surface:checkgreen (8158 exports / 4540 callable, +1/+1 documented).OPENCLAW_STATE_DIR, port 19477): real Chromium + unpacked extension paired over the direct Gateway route ([browser/extension-relay-gateway] extension connected over gateway for profile "chrome"), sent https://example.com with a note → extension received{"ok":true}, which the bridge only sends afterdeliverPageShareresolved (system event enqueued + immediate heartbeat requested in the Gateway process). Driver used a scoped testhost_permissionscopy because scripted messages are not user gestures; real popup/menu/shortcut clicks are gestures, so the shipped manifest needs onlyactiveTab.autoreview clean: no accepted/actionable findings, "patch is correct (0.96)".ROTATED_TOKEN = "b".repeat(64)fixture inrelay-lifecycle.test.ts, so that file's one-line assertion update (onPageShare: expect.any(Function)) landed as its own commit outside the helper bundle and was reviewed by hand.