Open-source AI browser agent for Chrome and Firefox (monorepo) ðŸ§
JavaScript ai-agentai-agentsai-toolsbrowser-aibrowser-automationbrowser-extensionchrome-aichrome-devtoolschrome-extensionchrome-extensionsfirefox-addonfirefox-addonsfirefox-extensionfirefox-extensionsgemmagemma4minimaxoffline-aioffline-llmqwen
Charge point and focus input to the frame that receives it
Barack Sokulluc13aad47e61a
diff --git a/docs/prompt-injection-defense.md b/docs/prompt-injection-defense.mdindex 682482d64..ded6036e7 100644--- a/docs/prompt-injection-defense.md+++ b/docs/prompt-injection-defense.md@@ -37,6 +37,27 @@ them in sync — the test suite asserts the pure modules are byte-identical.the human is the trust anchor.- Code: `permission-gate.js` (`capabilityFor`, `requiredHosts`,`PermissionManager`); the gate loop in `agent.js _executeToolBatch`.+ - Point and focus input is charged to the document it reaches, not to the+ top-level page. A coordinate click (a vision `click_at` runs as one),+ `type_text` without a selector and `press_keys`+ (`inputReachesReceivingFrame`) go to whatever is under the point or has+ focus, which can be an embedded payment, identity or wallet frame on+ another site. Chrome's CDP input reaches such frames, so before the gate+ `cdp-client.js resolveInputFrame` finds the receiving document (hit test+ or focus, descending into process-isolated frames) and reads its origin;+ focus, scroll offsets and origin are read in an isolated world the page+ cannot redefine. The gate charges that origin's host, so an about:blank+ or srcdoc editor frame stays with the page. A frame it cannot identify+ or attach to (another extension's frame, for example), or one with an+ opaque origin (sandboxed, `data:`), fails closed instead of using the+ page's grant. After a permission card it checks again, and does not send+ the input if the page moved it to another document meanwhile. On Firefox+ this input stays in the top document (or, for a vision click, a+ same-origin frame): synthetic events cannot enter a cross-origin frame,+ and trusted companion input on a frame element is refused (`content.js+ prepareBidiTarget`, the companion's point check). The explicit+ `iframe_click` / `iframe_type` tools charge the frame named by+ `urlFilter`.- User control: the Permissions page (review/revoke grants + the masterswitch "Ask before consequential actions"). The warning button in the side panel'scomposer toolbar toggles the same master switch; it never answers a pending@@ -107,8 +128,10 @@ Map it in `permission-gate.js`:depends on args — see `set_field`/`press_keys`/`fetch_url`);- make sure `hostForCapability` / `requiredHosts` resolves the **real targethost** (destination URL for navigate/network/download; current page for- click/type; the **frame** host for iframe tools; **every** host for a- multi-URL tool like `download_files`);+ click/type on an element WebBrain resolved; the **receiving document** for+ point or focus input, see `inputReachesReceivingFrame`; the **frame** host+ for iframe tools; **every** host for a multi-URL tool like+ `download_files`);- if the host can't be determined, return `''` / `[]` so the gate **failsclosed** (see the iframe-without-`urlFilter` case).@@ -212,25 +235,19 @@ field unwrapped is a hole.These are conscious trade-offs, not oversights.-- **Generic interaction is charged to the top-level page host, not the frame- it lands in.** `click({x,y})` (CDP coordinate clicks), `type_text`, and- `press_keys` go to whatever pixel/element is targeted or focused — which- *can* be inside a cross-origin iframe (e.g. an embedded Stripe/PayPal frame).- The gate charges these to the page host, so a grant for `merchant.com` also- covers a coordinate click that lands in an embedded `stripe.com` frame.- - Why accepted: (1) selector/text clicks **can't** reach cross-origin frames- (same-origin policy blocks `querySelector` from piercing them), so this is- limited to coordinate clicks (Chrome/CDP only — Firefox clicks the- `<iframe>` element, not into it) and focus-based typing; (2) for legitimate- embedded flows the user grants the merchant page *expecting* checkout —- including its payment iframe — to work, so prompting for the provider's- host mid-flow is arguably worse UX than the residual risk. The **explicit**- `iframe_click` / `iframe_type` tools DO gate on the frame host- (`frameHostMatches`), because there the model deliberately names a frame.- - If you want to close it: resolve the target frame for coordinate clicks- (CDP hit-test) and the focused-frame for keystrokes, then gate on that- frame host or fail closed when it's cross-origin. Non-trivial and- Chrome/CDP-specific; needs real-browser testing.+- **Element clicks stay charged to the top-level page host.** A click or+ `type_text` on an element named by selector, text, index or ref is resolved+ in the top document and charged to the page host. On Chrome two edge cases+ can still reach a frame of another host: the CDP selector fallback for+ closed shadow roots also searches same-process (same-site) child documents,+ and a CDP click at the centre of an element that an embedded frame covers+ lands in that frame. Point and focus input (Layer 3) is charged to the+ frame it reaches.++- **The receiving document is checked before dispatch, not at it.** On+ Chrome, a page that moves a frame under the point, or focus into one, after+ the gate's check (or its re-check after a permission card) and before the+ CDP input is sent is not caught.- **`solve_captcha` is ungated** (on the `KNOWN_SAFE_TOOLS` allowlist). Itspends CapSolver quota and injects a token (firing the widget's@@ -247,4 +264,4 @@ These are conscious trade-offs, not oversights.and leaky). The gate is deterministic capability×origin with the human as thetrust anchor.- _Last update: 10/11/2026_+ _Last update: 10/27/2026_diff --git a/firefox-companion/session.mjs b/firefox-companion/session.mjsindex f1e8d3360..fc0c6787d 100644--- a/firefox-companion/session.mjs+++ b/firefox-companion/session.mjs@@ -575,6 +575,9 @@ export class BidiSession {return false;};if (!r.width || !r.height || !reaches(hit, el)) return false;+ // A press over an embedded frame lands in the frame's own document,+ // another site the extension's permission for this page may not cover.+ if ((action === 'click' || action === 'click_at') && /^(IFRAME|FRAME|OBJECT|EMBED)$/i.test(String(hit?.tagName || ''))) return false;}if (action === 'type' || action === 'field' || action === 'key') {el.focus({preventScroll:true});diff --git a/package.json b/package.jsonindex 9e53890ff..485ada52f 100644--- a/package.json+++ b/package.json@@ -70,8 +70,8 @@"benchmark:relevance": "node scripts/benchmark-offline-relevance.mjs --verbose","test:social-contract": "node --test test/social-publish-contract.mjs test/publication-quote-markup.mjs test/publication-prefetch.mjs","test:social-contract:dom": "node test/social-publish-contract-dom.mjs",- "test:runtime-lifecycle": "node test/bot-memory-dom.mjs && node --test test/agent-lifecycle.mjs test/runtime-startup.mjs test/run-ui-scheduled-lifecycle.mjs test/transport-deadlines.mjs test/cdp-worker-restart.mjs test/bot-memory.mjs test/bot-memory-registries.mjs test/bot-memory-cloud-controller.mjs test/cdp-clear-receipt.mjs test/cdp-field-submit-recovery.mjs test/conversation-persistence.mjs test/history-recovery-state.mjs test/history-recovery-scheduler.mjs test/history-recovery-atomic.mjs test/context-live-tool-group.mjs test/integration-races.mjs test/watch-completion-checkpoint.mjs test/runtime-model-identity.mjs test/provider-message-privacy.mjs test/runtime-task-authority.mjs test/planner-repair-authority.mjs test/runtime-progress-continuation.mjs test/chat-resume-chain.mjs test/chat-resume-completion.mjs test/native-chat-execution-ledger.mjs test/chat-send-dispatch-result.mjs test/chat-pre-enter-veto.mjs test/chat-reply-dedup-race.mjs test/memcode-lifecycle.mjs test/runtime-peer-review.mjs test/read-continuation-schema.mjs test/completion-submit-acknowledgement.mjs test/completion-live-status.mjs test/completion-iframe-submit.mjs test/form-validation-alert-readings.mjs test/control-effect-readings.mjs test/guard-reading-carry-over.mjs test/trusted-retry-readings.mjs test/completion-semantic-commit.mjs test/completion-diagnostics.mjs test/mastodon-publication.mjs test/calculator.mjs test/chat-recovery-protocol.mjs test/chat-pending-reconciliation.mjs test/semantic-page-retry.mjs test/pdf-detection.mjs test/runtime-lifecycle.mjs test/collection-read-progress.mjs test/network-lifecycle.mjs test/text-write-cancellation.mjs test/guard-advisory-writes.mjs test/trusted-field-preparation.mjs test/draftjs-text.mjs test/codemirror-text.mjs test/rich-text-frameworks.mjs test/cdp-managed-text-selection.mjs test/firefox-rich-text-readback.mjs test/contenteditable-beforeinput.mjs test/trusted-field-preparation-ownership.mjs test/typing-preparation-geometry.mjs test/chat-steering.mjs test/lifecycle-steering-restart.mjs test/resource-mutation-guards.mjs test/completion-steering-receipt-authority.mjs test/steering-revision-recovery.mjs test/pending-clarification-hydration.mjs test/run-ui-hidden-panel.mjs test/clarify-timeout-policy.mjs test/guard-ask-cards.mjs test/permission-steering-wakeup.mjs test/pure-calculation-reply.mjs test/pure-calculation-tools.mjs test/page-feedback.mjs test/page-feedback-progress.mjs test/page-feedback-unbindable-target.mjs test/guard-advisory-actions.mjs test/rich-text-preflight-page-change.mjs test/keyboard-receiver-frame.mjs test/ask-response-scope.mjs test/ask-completion-churn.mjs test/page-feedback-policy.mjs test/research-escalation-page-feedback.mjs test/page-feedback-transport-races.mjs test/page-feedback-recovery.mjs test/telegram-read-preparation-agent.mjs test/media-download-agent-handler.mjs test/code-scanning-url-recipient.mjs test/apocalypse-comm-parsing.mjs test/apocalypse-scalar-decoding.mjs test/bitgpu-chat-security.mjs test/social-media-url-upgrades.mjs test/downloaded-file-saved-bytes.mjs test/downloaded-file-local-probe.mjs test/formless-verification-recovery.mjs test/file-upload-accept.mjs test/file-upload-accept-agent.mjs test/workflow-route-generic-completion.mjs test/release-publication-completion.mjs test/workflow-implicit-metadata.mjs test/workflow-field-readings.mjs test/workflow-field-anchors.mjs test/user-turn-kind.mjs test/follow-up-task-context.mjs test/completion-current-execution-evidence.mjs test/monitor-intervention-contract.mjs test/monitor-owned-geometry.mjs test/monitor-viewport-remainder.mjs test/monitor-scroll-churn.mjs test/monitor-local-attribution.mjs test/monitor-lifecycle-leaks.mjs test/feedback-automatic-churn.mjs test/feedback-navigation-idle.mjs test/feedback-run-boundaries.mjs test/feedback-ask-viewing.mjs test/lifecycle-terminal-done.mjs test/incomplete-completion-recovery.mjs test/guard-advisory-completion.mjs test/guard-policy.mjs test/lean-mode.mjs test/prompt-unverified-pages.mjs test/prompt-missing-values.mjs test/lifecycle-planner-digest.mjs test/planner-clarify-loop.mjs test/lifecycle-vision-fallback.mjs test/guards-control-classification.mjs test/guards-unbound-deletion.mjs test/guards-steering-receipts.mjs && node test/ui-content-lifecycle.mjs && node --test test/native-telegram-chat.mjs test/native-telegram-recipient.mjs test/telegram-native-baseline.mjs test/telegram-native-latest.mjs test/native-chat-pre-enter-draft.mjs test/chat-draft-dispatch-ownership.mjs test/native-telegram-alias-preparation.mjs test/telegram-read-preparation-content.mjs test/queued-composer-ownership.mjs test/onboarding-provider-ready.mjs test/sidepanel-permission-gate-ui.mjs test/workflow-native-targets.mjs test/native-whatsapp-chat.mjs test/native-chat-context-identity.mjs test/native-whatsapp-contact.mjs test/whatsapp-chat-selection.mjs test/whatsapp-native-bootstrap.mjs test/whatsapp-drawer-identity.mjs test/whatsapp-read-latest.mjs test/whatsapp-read-preparation.mjs test/whatsapp-chat-completion.mjs test/whatsapp-chat-restart.mjs test/chat-goal-lifecycle.mjs test/chat-completion.mjs test/chat-generic-dispatch.mjs test/completion-live-status-browser.mjs test/native-confirmation-visibility.mjs test/read-continuation-browser.mjs test/iframe-preparation-focus.mjs test/contenteditable-literal.mjs test/native-chat-empty-editor.mjs test/native-chat-trusted-clear.mjs test/chat-steering-ui.mjs test/recipient-confirmation-ui.mjs test/assistant-message-visibility-ui.mjs test/slash-command-timeline-ui.mjs test/history-recovery.mjs test/history-recovery-ui.mjs test/page-monitor-ui.mjs test/x-compose-trusted-typing.mjs test/page-monitor-dialog.mjs test/page-monitor-dialog-native.mjs test/page-monitor-inline-post.mjs test/bluesky-composer-context.mjs test/page-monitor-anchored.mjs test/page-monitor-upload-owner.mjs test/page-monitor-upload-release.mjs test/page-monitor-native-controls.mjs test/page-monitor-native-preparation.mjs test/native-preparation-cold.mjs test/page-monitor-navigation.mjs test/page-monitor-main-owner.mjs test/page-monitor-collateral-controls.mjs test/accessibility-tree-scoped-budget.mjs test/ax-reference-origin.mjs test/page-monitor-decorative-hit.mjs test/social-ui-navigation.mjs test/native-resource-deletion-binding.mjs test/native-mastodon-confirmation.mjs test/dropdown-menu-inventory.mjs test/page-monitor-passive-progress.mjs test/page-monitor-feed-items.mjs test/media-download-binding.mjs test/media-download-capture-integration.mjs test/social-media-downloader-reinjection.mjs test/upload-file-local-state-guidance.mjs && node test/message-recipient-upload.mjs && node test/message-recipient-clarify-binding.mjs && node --test test/message-recipient-whatsapp.mjs test/message-control-readings.mjs && node test/quality/integration-mv3.mjs --full-form && node test/quality/literal-calculate-midrun-mv3.mjs && node test/quality/ask-completion-churn-mv3.mjs && node test/quality/ask-person-activity-mv3.mjs && node test/quality/telegram-cold-preparation-mv3.mjs && node test/quality/native-chat-mv3.mjs && node test/quality/native-chat-presubmit-mv3.mjs && node test/quality/cloud-bot-memory-mv3.mjs && node test/quality/whatsapp-contact-matrix.mjs && node test/quality/pdf-detection-mv3.mjs && node test/quality/download-upload-mv3.mjs && node test/quality/upload-release-binding-mv3.mjs && node test/quality/release-review-world-mv3.mjs && node test/quality/downloaded-file-saved-bytes-mv3.mjs && node test/quality/file-upload-accept-mv3.mjs && node test/quality/bulk-resume-mv3.mjs && node test/quality/literal-frame-mv3.mjs && node test/quality/mastodon-publication-mv3.mjs && node test/quality/mastodon-reply-route-mv3.mjs && node test/quality/mastodon-deletion-mv3.mjs && node test/quality/mastodon-delete-confirmation-mv3.mjs && node test/quality/mastodon-delete-confirmation-mv3.mjs --menu-read && node test/quality/mastodon-delete-confirmation-mv3.mjs --vague && node test/quality/mastodon-delete-after-correction-mv3.mjs && node test/quality/unbound-deletion-mv3.mjs && node test/quality/recipient-clarify-mv3.mjs && node test/quality/open-chat-recipients-mv3.mjs && node test/quality/correction-cross-site-mv3.mjs && node test/quality/anchored-action-mv3.mjs && node test/quality/inline-social-composer-mv3.mjs && node test/quality/x-compose-dialog-mv3.mjs && node test/quality/bluesky-composer-mv3.mjs && node test/quality/dropdown-menu-matrix.mjs && node test/quality/mastodon-deletion-navigation-mv3.mjs && node test/quality/semantic-navigation-matrix.mjs && node test/quality/workflow-replay-mv3.mjs && node test/quality/generative-media-mv3.mjs && node test/quality/cdp-worker-restart-mv3.mjs && node test/quality/steering-worker-restart-mv3.mjs",- "test:page-feedback": "node --test test/trusted-field-preparation.mjs test/guard-advisory-writes.mjs test/draftjs-text.mjs test/codemirror-text.mjs test/rich-text-frameworks.mjs test/cdp-managed-text-selection.mjs test/firefox-rich-text-readback.mjs test/contenteditable-beforeinput.mjs test/trusted-field-preparation-ownership.mjs test/typing-preparation-geometry.mjs test/pure-calculation-reply.mjs test/pure-calculation-tools.mjs test/page-feedback.mjs test/page-feedback-progress.mjs test/page-feedback-unbindable-target.mjs test/guard-advisory-actions.mjs test/rich-text-preflight-page-change.mjs test/keyboard-receiver-frame.mjs test/ask-response-scope.mjs test/ask-completion-churn.mjs test/page-feedback-policy.mjs test/research-escalation-page-feedback.mjs test/page-feedback-transport-races.mjs test/page-feedback-recovery.mjs test/telegram-read-preparation-agent.mjs test/media-download-agent-handler.mjs test/page-monitor-ui.mjs test/x-compose-trusted-typing.mjs test/page-monitor-dialog.mjs test/page-monitor-dialog-native.mjs test/page-monitor-inline-post.mjs test/bluesky-composer-context.mjs test/page-monitor-anchored.mjs test/page-monitor-upload-owner.mjs test/page-monitor-upload-release.mjs test/page-monitor-native-controls.mjs test/page-monitor-passive-progress.mjs test/page-monitor-feed-items.mjs test/media-download-binding.mjs test/media-download-capture-integration.mjs test/monitor-intervention-contract.mjs test/monitor-owned-geometry.mjs test/monitor-viewport-remainder.mjs test/monitor-scroll-churn.mjs test/monitor-local-attribution.mjs test/monitor-lifecycle-leaks.mjs test/feedback-automatic-churn.mjs test/feedback-navigation-idle.mjs test/feedback-run-boundaries.mjs test/feedback-ask-viewing.mjs test/delivery-click-ax-response-loss.mjs test/delivery-stop-compound.mjs test/delivery-cdp-input.mjs test/delivery-click-locks.mjs test/delivery-native-button-geometry.mjs test/delivery-hover-transition.mjs test/delivery-native-button-route.mjs test/delivery-dispatch-boundary.mjs && node test/message-recipient-upload.mjs && node test/message-recipient-clarify-binding.mjs && node --test test/message-recipient-whatsapp.mjs test/page-feedback-held-time.mjs test/page-monitor-held-observation.mjs",+ "test:runtime-lifecycle": "node test/bot-memory-dom.mjs && node --test test/agent-lifecycle.mjs test/runtime-startup.mjs test/run-ui-scheduled-lifecycle.mjs test/transport-deadlines.mjs test/cdp-worker-restart.mjs test/bot-memory.mjs test/bot-memory-registries.mjs test/bot-memory-cloud-controller.mjs test/cdp-clear-receipt.mjs test/cdp-field-submit-recovery.mjs test/conversation-persistence.mjs test/history-recovery-state.mjs test/history-recovery-scheduler.mjs test/history-recovery-atomic.mjs test/context-live-tool-group.mjs test/integration-races.mjs test/watch-completion-checkpoint.mjs test/runtime-model-identity.mjs test/provider-message-privacy.mjs test/runtime-task-authority.mjs test/planner-repair-authority.mjs test/runtime-progress-continuation.mjs test/chat-resume-chain.mjs test/chat-resume-completion.mjs test/native-chat-execution-ledger.mjs test/chat-send-dispatch-result.mjs test/chat-pre-enter-veto.mjs test/chat-reply-dedup-race.mjs test/memcode-lifecycle.mjs test/runtime-peer-review.mjs test/read-continuation-schema.mjs test/completion-submit-acknowledgement.mjs test/completion-live-status.mjs test/completion-iframe-submit.mjs test/form-validation-alert-readings.mjs test/control-effect-readings.mjs test/guard-reading-carry-over.mjs test/trusted-retry-readings.mjs test/completion-semantic-commit.mjs test/completion-diagnostics.mjs test/mastodon-publication.mjs test/calculator.mjs test/chat-recovery-protocol.mjs test/chat-pending-reconciliation.mjs test/semantic-page-retry.mjs test/pdf-detection.mjs test/runtime-lifecycle.mjs test/collection-read-progress.mjs test/network-lifecycle.mjs test/text-write-cancellation.mjs test/guard-advisory-writes.mjs test/trusted-field-preparation.mjs test/draftjs-text.mjs test/codemirror-text.mjs test/rich-text-frameworks.mjs test/cdp-managed-text-selection.mjs test/firefox-rich-text-readback.mjs test/contenteditable-beforeinput.mjs test/trusted-field-preparation-ownership.mjs test/typing-preparation-geometry.mjs test/chat-steering.mjs test/lifecycle-steering-restart.mjs test/resource-mutation-guards.mjs test/completion-steering-receipt-authority.mjs test/steering-revision-recovery.mjs test/pending-clarification-hydration.mjs test/run-ui-hidden-panel.mjs test/clarify-timeout-policy.mjs test/guard-ask-cards.mjs test/permission-steering-wakeup.mjs test/pure-calculation-reply.mjs test/pure-calculation-tools.mjs test/page-feedback.mjs test/page-feedback-progress.mjs test/page-feedback-unbindable-target.mjs test/guard-advisory-actions.mjs test/rich-text-preflight-page-change.mjs test/keyboard-receiver-frame.mjs test/input-receiving-frame.mjs test/ask-response-scope.mjs test/ask-completion-churn.mjs test/page-feedback-policy.mjs test/research-escalation-page-feedback.mjs test/page-feedback-transport-races.mjs test/page-feedback-recovery.mjs test/telegram-read-preparation-agent.mjs test/media-download-agent-handler.mjs test/code-scanning-url-recipient.mjs test/apocalypse-comm-parsing.mjs test/apocalypse-scalar-decoding.mjs test/bitgpu-chat-security.mjs test/social-media-url-upgrades.mjs test/downloaded-file-saved-bytes.mjs test/downloaded-file-local-probe.mjs test/formless-verification-recovery.mjs test/file-upload-accept.mjs test/file-upload-accept-agent.mjs test/workflow-route-generic-completion.mjs test/release-publication-completion.mjs test/workflow-implicit-metadata.mjs test/workflow-field-readings.mjs test/workflow-field-anchors.mjs test/user-turn-kind.mjs test/follow-up-task-context.mjs test/completion-current-execution-evidence.mjs test/monitor-intervention-contract.mjs test/monitor-owned-geometry.mjs test/monitor-viewport-remainder.mjs test/monitor-scroll-churn.mjs test/monitor-local-attribution.mjs test/monitor-lifecycle-leaks.mjs test/feedback-automatic-churn.mjs test/feedback-navigation-idle.mjs test/feedback-run-boundaries.mjs test/feedback-ask-viewing.mjs test/lifecycle-terminal-done.mjs test/incomplete-completion-recovery.mjs test/guard-advisory-completion.mjs test/guard-policy.mjs test/lean-mode.mjs test/prompt-unverified-pages.mjs test/prompt-missing-values.mjs test/lifecycle-planner-digest.mjs test/planner-clarify-loop.mjs test/lifecycle-vision-fallback.mjs test/guards-control-classification.mjs test/guards-unbound-deletion.mjs test/guards-steering-receipts.mjs && node test/ui-content-lifecycle.mjs && node --test test/native-telegram-chat.mjs test/native-telegram-recipient.mjs test/telegram-native-baseline.mjs test/telegram-native-latest.mjs test/native-chat-pre-enter-draft.mjs test/chat-draft-dispatch-ownership.mjs test/native-telegram-alias-preparation.mjs test/telegram-read-preparation-content.mjs test/queued-composer-ownership.mjs test/onboarding-provider-ready.mjs test/sidepanel-permission-gate-ui.mjs test/workflow-native-targets.mjs test/native-whatsapp-chat.mjs test/native-chat-context-identity.mjs test/native-whatsapp-contact.mjs test/whatsapp-chat-selection.mjs test/whatsapp-native-bootstrap.mjs test/whatsapp-drawer-identity.mjs test/whatsapp-read-latest.mjs test/whatsapp-read-preparation.mjs test/whatsapp-chat-completion.mjs test/whatsapp-chat-restart.mjs test/chat-goal-lifecycle.mjs test/chat-completion.mjs test/chat-generic-dispatch.mjs test/completion-live-status-browser.mjs test/native-confirmation-visibility.mjs test/read-continuation-browser.mjs test/iframe-preparation-focus.mjs test/contenteditable-literal.mjs test/native-chat-empty-editor.mjs test/native-chat-trusted-clear.mjs test/chat-steering-ui.mjs test/recipient-confirmation-ui.mjs test/assistant-message-visibility-ui.mjs test/slash-command-timeline-ui.mjs test/history-recovery.mjs test/history-recovery-ui.mjs test/page-monitor-ui.mjs test/x-compose-trusted-typing.mjs test/page-monitor-dialog.mjs test/page-monitor-dialog-native.mjs test/page-monitor-inline-post.mjs test/bluesky-composer-context.mjs test/page-monitor-anchored.mjs test/page-monitor-upload-owner.mjs test/page-monitor-upload-release.mjs test/page-monitor-native-controls.mjs test/page-monitor-native-preparation.mjs test/native-preparation-cold.mjs test/page-monitor-navigation.mjs test/page-monitor-main-owner.mjs test/page-monitor-collateral-controls.mjs test/accessibility-tree-scoped-budget.mjs test/ax-reference-origin.mjs test/page-monitor-decorative-hit.mjs test/social-ui-navigation.mjs test/native-resource-deletion-binding.mjs test/native-mastodon-confirmation.mjs test/dropdown-menu-inventory.mjs test/page-monitor-passive-progress.mjs test/page-monitor-feed-items.mjs test/media-download-binding.mjs test/media-download-capture-integration.mjs test/social-media-downloader-reinjection.mjs test/upload-file-local-state-guidance.mjs && node test/message-recipient-upload.mjs && node test/message-recipient-clarify-binding.mjs && node --test test/message-recipient-whatsapp.mjs test/message-control-readings.mjs && node test/quality/integration-mv3.mjs --full-form && node test/quality/literal-calculate-midrun-mv3.mjs && node test/quality/ask-completion-churn-mv3.mjs && node test/quality/ask-person-activity-mv3.mjs && node test/quality/telegram-cold-preparation-mv3.mjs && node test/quality/native-chat-mv3.mjs && node test/quality/native-chat-presubmit-mv3.mjs && node test/quality/cloud-bot-memory-mv3.mjs && node test/quality/whatsapp-contact-matrix.mjs && node test/quality/pdf-detection-mv3.mjs && node test/quality/download-upload-mv3.mjs && node test/quality/upload-release-binding-mv3.mjs && node test/quality/release-review-world-mv3.mjs && node test/quality/downloaded-file-saved-bytes-mv3.mjs && node test/quality/file-upload-accept-mv3.mjs && node test/quality/bulk-resume-mv3.mjs && node test/quality/literal-frame-mv3.mjs && node test/quality/mastodon-publication-mv3.mjs && node test/quality/mastodon-reply-route-mv3.mjs && node test/quality/mastodon-deletion-mv3.mjs && node test/quality/mastodon-delete-confirmation-mv3.mjs && node test/quality/mastodon-delete-confirmation-mv3.mjs --menu-read && node test/quality/mastodon-delete-confirmation-mv3.mjs --vague && node test/quality/mastodon-delete-after-correction-mv3.mjs && node test/quality/unbound-deletion-mv3.mjs && node test/quality/recipient-clarify-mv3.mjs && node test/quality/open-chat-recipients-mv3.mjs && node test/quality/correction-cross-site-mv3.mjs && node test/quality/anchored-action-mv3.mjs && node test/quality/inline-social-composer-mv3.mjs && node test/quality/x-compose-dialog-mv3.mjs && node test/quality/bluesky-composer-mv3.mjs && node test/quality/dropdown-menu-matrix.mjs && node test/quality/mastodon-deletion-navigation-mv3.mjs && node test/quality/semantic-navigation-matrix.mjs && node test/quality/workflow-replay-mv3.mjs && node test/quality/generative-media-mv3.mjs && node test/quality/cdp-worker-restart-mv3.mjs && node test/quality/steering-worker-restart-mv3.mjs",+ "test:page-feedback": "node --test test/trusted-field-preparation.mjs test/guard-advisory-writes.mjs test/draftjs-text.mjs test/codemirror-text.mjs test/rich-text-frameworks.mjs test/cdp-managed-text-selection.mjs test/firefox-rich-text-readback.mjs test/contenteditable-beforeinput.mjs test/trusted-field-preparation-ownership.mjs test/typing-preparation-geometry.mjs test/pure-calculation-reply.mjs test/pure-calculation-tools.mjs test/page-feedback.mjs test/page-feedback-progress.mjs test/page-feedback-unbindable-target.mjs test/guard-advisory-actions.mjs test/rich-text-preflight-page-change.mjs test/keyboard-receiver-frame.mjs test/input-receiving-frame.mjs test/ask-response-scope.mjs test/ask-completion-churn.mjs test/page-feedback-policy.mjs test/research-escalation-page-feedback.mjs test/page-feedback-transport-races.mjs test/page-feedback-recovery.mjs test/telegram-read-preparation-agent.mjs test/media-download-agent-handler.mjs test/page-monitor-ui.mjs test/x-compose-trusted-typing.mjs test/page-monitor-dialog.mjs test/page-monitor-dialog-native.mjs test/page-monitor-inline-post.mjs test/bluesky-composer-context.mjs test/page-monitor-anchored.mjs test/page-monitor-upload-owner.mjs test/page-monitor-upload-release.mjs test/page-monitor-native-controls.mjs test/page-monitor-passive-progress.mjs test/page-monitor-feed-items.mjs test/media-download-binding.mjs test/media-download-capture-integration.mjs test/monitor-intervention-contract.mjs test/monitor-owned-geometry.mjs test/monitor-viewport-remainder.mjs test/monitor-scroll-churn.mjs test/monitor-local-attribution.mjs test/monitor-lifecycle-leaks.mjs test/feedback-automatic-churn.mjs test/feedback-navigation-idle.mjs test/feedback-run-boundaries.mjs test/feedback-ask-viewing.mjs test/delivery-click-ax-response-loss.mjs test/delivery-stop-compound.mjs test/delivery-cdp-input.mjs test/delivery-click-locks.mjs test/delivery-native-button-geometry.mjs test/delivery-hover-transition.mjs test/delivery-native-button-route.mjs test/delivery-dispatch-boundary.mjs && node test/message-recipient-upload.mjs && node test/message-recipient-clarify-binding.mjs && node --test test/message-recipient-whatsapp.mjs test/page-feedback-held-time.mjs test/page-monitor-held-observation.mjs","test:history-recovery": "node --test test/history-recovery.mjs test/history-recovery-ui.mjs test/history-recovery-state.mjs test/history-recovery-scheduler.mjs test/history-recovery-atomic.mjs test/conversation-persistence.mjs","test:chat-steering": "node --test test/chat-steering.mjs test/chat-steering-ui.mjs test/recipient-confirmation-ui.mjs test/lifecycle-steering-latency.mjs test/lifecycle-steering-restart.mjs test/lifecycle-run-ui.mjs test/lifecycle-menu-prompts-held.mjs","test:rich-text-dom": "node test/ui-content-lifecycle.mjs --dom",@@ -105,7 +105,7 @@"test:chat-draft-recovery": "node --test test/native-chat-pre-enter-draft.mjs test/chat-draft-dispatch-ownership.mjs && node test/quality/native-chat-presubmit-mv3.mjs","test:upload-owner": "node --test test/page-monitor-upload-owner.mjs test/page-monitor-upload-release.mjs","test:shard:quick": "npm run test:cms && npm run test:markdown && npm run test:generative-media && npm run test:systemone && npm run test:systemone:fast && node --test test/guard-policy.mjs test/browser-dialogs.mjs test/capsolver-cloud-broker.mjs test/captcha-providers.mjs test/captcha-weighted-fallback.mjs test/captcha-hcaptcha-providers.mjs test/captcha-native-providers.mjs test/captcha-runtime-policy.mjs test/captcha-callback-bridge.mjs test/captcha-bridge-registration.mjs test/cookie-banner-host.mjs test/captcha-aws-recovery.mjs test/captcha-documented-contracts.mjs test/huggingface-signup-recovery.mjs test/trace-full-export.mjs test/slash-command-tab-ownership.mjs test/feedback-traces.mjs && npm run test:firefox-bidi && npm run test:billing-notice && npm run test:compass-quota && npm run test:provider-limits && npm run test:provider-catalog && npm run test:provider-instances:ui && npm run test:settings-pages:ui && npm run test:openrouter-capabilities && npm run test:anthropic && npm run test:browser-batch && npm run test:accessibility-tree-benchmark && npm run test:toolbar-guard && npm run test:cloud-bridge-approval && npm run test:discord && npm run test:pdf-read && npm run test:pdf-selection && npm run test:social-contract && npm run test:safesocial && npm run test:build-unpacked && npm run test:attachment-drop && npm run test:workflow-editor && node --test test/profile-sync-stats.mjs && node --test test/memcode-recall.mjs",- "test:shard:runtime-unit": "node --test test/skill-download-wait.mjs && node --test test/agent-lifecycle.mjs test/runtime-startup.mjs test/run-ui-scheduled-lifecycle.mjs test/transport-deadlines.mjs test/cdp-worker-restart.mjs test/bot-memory.mjs test/bot-memory-click-guard.mjs test/bot-memory-registries.mjs test/bot-memory-cloud-controller.mjs test/cdp-clear-receipt.mjs test/cdp-field-submit-recovery.mjs test/conversation-persistence.mjs test/context-live-tool-group.mjs test/integration-races.mjs test/watch-completion-checkpoint.mjs test/runtime-model-identity.mjs test/provider-message-privacy.mjs test/runtime-task-authority.mjs test/planner-repair-authority.mjs test/runtime-progress-continuation.mjs test/chat-resume-chain.mjs test/chat-resume-completion.mjs test/native-chat-execution-ledger.mjs test/chat-send-dispatch-result.mjs test/chat-pre-enter-veto.mjs test/chat-reply-dedup-race.mjs test/memcode-lifecycle.mjs test/runtime-peer-review.mjs test/read-continuation-schema.mjs test/completion-submit-acknowledgement.mjs test/completion-live-status.mjs test/completion-iframe-submit.mjs test/form-validation-alert-readings.mjs test/control-effect-readings.mjs test/guard-reading-carry-over.mjs test/trusted-retry-readings.mjs test/completion-semantic-commit.mjs test/completion-diagnostics.mjs test/mastodon-publication.mjs test/calculator.mjs test/chat-recovery-protocol.mjs test/chat-pending-reconciliation.mjs test/semantic-page-retry.mjs test/pdf-detection.mjs test/runtime-lifecycle.mjs test/collection-read-progress.mjs test/network-lifecycle.mjs test/text-write-cancellation.mjs test/guard-advisory-writes.mjs test/trusted-field-preparation.mjs test/draftjs-text.mjs test/codemirror-text.mjs test/rich-text-frameworks.mjs test/cdp-managed-text-selection.mjs test/firefox-rich-text-readback.mjs test/contenteditable-beforeinput.mjs test/trusted-field-preparation-ownership.mjs test/typing-preparation-geometry.mjs test/chat-steering.mjs test/resource-mutation-guards.mjs test/completion-steering-receipt-authority.mjs test/steering-revision-recovery.mjs test/pending-clarification-hydration.mjs test/run-ui-hidden-panel.mjs test/clarify-timeout-policy.mjs test/guard-ask-cards.mjs test/permission-steering-wakeup.mjs test/pure-calculation-reply.mjs test/pure-calculation-tools.mjs test/page-feedback.mjs test/page-feedback-progress.mjs test/page-feedback-unbindable-target.mjs test/guard-advisory-actions.mjs test/rich-text-preflight-page-change.mjs test/keyboard-receiver-frame.mjs test/ask-response-scope.mjs test/auto-mode.mjs test/plan-when-needed.mjs test/model-picker-icon.mjs test/ask-completion-churn.mjs test/page-feedback-policy.mjs test/research-escalation-page-feedback.mjs test/page-feedback-transport-races.mjs test/page-feedback-recovery.mjs test/telegram-read-preparation-agent.mjs test/media-download-agent-handler.mjs test/code-scanning-url-recipient.mjs test/apocalypse-comm-parsing.mjs test/apocalypse-scalar-decoding.mjs test/bitgpu-chat-security.mjs test/social-media-url-upgrades.mjs test/downloaded-file-saved-bytes.mjs test/downloaded-file-local-probe.mjs test/formless-verification-recovery.mjs test/file-upload-accept.mjs test/file-upload-accept-agent.mjs test/workflow-route-generic-completion.mjs test/release-publication-completion.mjs test/workflow-implicit-metadata.mjs test/workflow-field-readings.mjs test/workflow-field-anchors.mjs test/user-turn-kind.mjs test/follow-up-task-context.mjs test/completion-current-execution-evidence.mjs test/video-upload-attachment.mjs test/feedback-automatic-churn.mjs test/feedback-navigation-idle.mjs test/feedback-run-boundaries.mjs test/feedback-ask-viewing.mjs test/lifecycle-terminal-done.mjs test/incomplete-completion-recovery.mjs test/guard-advisory-completion.mjs test/lean-mode.mjs test/prompt-unverified-pages.mjs test/prompt-missing-values.mjs test/lifecycle-planner-digest.mjs test/planner-clarify-loop.mjs test/lifecycle-steering-latency.mjs test/lifecycle-steering-restart.mjs test/lifecycle-vision-fallback.mjs test/delivery-click-locks.mjs test/guards-steering-receipts.mjs test/terminal-user-messages.mjs test/improver-providers.mjs test/improver-providers-agent.mjs test/improver-guards-ledger.mjs test/improver-guards-tools.mjs test/improver-clarify.mjs test/improver-clarify-scheduler.mjs test/improver-misc.mjs test/improver-forms.mjs test/improver-forms-strict-secrets.mjs test/improver-content-press-keys-hint.mjs && npm run test:plan-notifications",+ "test:shard:runtime-unit": "node --test test/skill-download-wait.mjs && node --test test/agent-lifecycle.mjs test/runtime-startup.mjs test/run-ui-scheduled-lifecycle.mjs test/transport-deadlines.mjs test/cdp-worker-restart.mjs test/bot-memory.mjs test/bot-memory-click-guard.mjs test/bot-memory-registries.mjs test/bot-memory-cloud-controller.mjs test/cdp-clear-receipt.mjs test/cdp-field-submit-recovery.mjs test/conversation-persistence.mjs test/context-live-tool-group.mjs test/integration-races.mjs test/watch-completion-checkpoint.mjs test/runtime-model-identity.mjs test/provider-message-privacy.mjs test/runtime-task-authority.mjs test/planner-repair-authority.mjs test/runtime-progress-continuation.mjs test/chat-resume-chain.mjs test/chat-resume-completion.mjs test/native-chat-execution-ledger.mjs test/chat-send-dispatch-result.mjs test/chat-pre-enter-veto.mjs test/chat-reply-dedup-race.mjs test/memcode-lifecycle.mjs test/runtime-peer-review.mjs test/read-continuation-schema.mjs test/completion-submit-acknowledgement.mjs test/completion-live-status.mjs test/completion-iframe-submit.mjs test/form-validation-alert-readings.mjs test/control-effect-readings.mjs test/guard-reading-carry-over.mjs test/trusted-retry-readings.mjs test/completion-semantic-commit.mjs test/completion-diagnostics.mjs test/mastodon-publication.mjs test/calculator.mjs test/chat-recovery-protocol.mjs test/chat-pending-reconciliation.mjs test/semantic-page-retry.mjs test/pdf-detection.mjs test/runtime-lifecycle.mjs test/collection-read-progress.mjs test/network-lifecycle.mjs test/text-write-cancellation.mjs test/guard-advisory-writes.mjs test/trusted-field-preparation.mjs test/draftjs-text.mjs test/codemirror-text.mjs test/rich-text-frameworks.mjs test/cdp-managed-text-selection.mjs test/firefox-rich-text-readback.mjs test/contenteditable-beforeinput.mjs test/trusted-field-preparation-ownership.mjs test/typing-preparation-geometry.mjs test/chat-steering.mjs test/resource-mutation-guards.mjs test/completion-steering-receipt-authority.mjs test/steering-revision-recovery.mjs test/pending-clarification-hydration.mjs test/run-ui-hidden-panel.mjs test/clarify-timeout-policy.mjs test/guard-ask-cards.mjs test/permission-steering-wakeup.mjs test/pure-calculation-reply.mjs test/pure-calculation-tools.mjs test/page-feedback.mjs test/page-feedback-progress.mjs test/page-feedback-unbindable-target.mjs test/guard-advisory-actions.mjs test/rich-text-preflight-page-change.mjs test/keyboard-receiver-frame.mjs test/input-receiving-frame.mjs test/ask-response-scope.mjs test/auto-mode.mjs test/plan-when-needed.mjs test/model-picker-icon.mjs test/ask-completion-churn.mjs test/page-feedback-policy.mjs test/research-escalation-page-feedback.mjs test/page-feedback-transport-races.mjs test/page-feedback-recovery.mjs test/telegram-read-preparation-agent.mjs test/media-download-agent-handler.mjs test/code-scanning-url-recipient.mjs test/apocalypse-comm-parsing.mjs test/apocalypse-scalar-decoding.mjs test/bitgpu-chat-security.mjs test/social-media-url-upgrades.mjs test/downloaded-file-saved-bytes.mjs test/downloaded-file-local-probe.mjs test/formless-verification-recovery.mjs test/file-upload-accept.mjs test/file-upload-accept-agent.mjs test/workflow-route-generic-completion.mjs test/release-publication-completion.mjs test/workflow-implicit-metadata.mjs test/workflow-field-readings.mjs test/workflow-field-anchors.mjs test/user-turn-kind.mjs test/follow-up-task-context.mjs test/completion-current-execution-evidence.mjs test/video-upload-attachment.mjs test/feedback-automatic-churn.mjs test/feedback-navigation-idle.mjs test/feedback-run-boundaries.mjs test/feedback-ask-viewing.mjs test/lifecycle-terminal-done.mjs test/incomplete-completion-recovery.mjs test/guard-advisory-completion.mjs test/lean-mode.mjs test/prompt-unverified-pages.mjs test/prompt-missing-values.mjs test/lifecycle-planner-digest.mjs test/planner-clarify-loop.mjs test/lifecycle-steering-latency.mjs test/lifecycle-steering-restart.mjs test/lifecycle-vision-fallback.mjs test/delivery-click-locks.mjs test/guards-steering-receipts.mjs test/terminal-user-messages.mjs test/improver-providers.mjs test/improver-providers-agent.mjs test/improver-guards-ledger.mjs test/improver-guards-tools.mjs test/improver-clarify.mjs test/improver-clarify-scheduler.mjs test/improver-misc.mjs test/improver-forms.mjs test/improver-forms-strict-secrets.mjs test/improver-content-press-keys-hint.mjs && npm run test:plan-notifications","test:shard:browser-a": "node --test test/captcha-draft-content.mjs test/captcha-challenge-surfaces.mjs && node test/bot-memory-dom.mjs && node test/bot-memory-click-dom.mjs && node test/ui-content-lifecycle.mjs && node --test test/native-telegram-chat.mjs test/native-telegram-recipient.mjs test/telegram-native-baseline.mjs test/telegram-native-latest.mjs test/native-chat-pre-enter-draft.mjs test/chat-draft-dispatch-ownership.mjs test/native-telegram-alias-preparation.mjs test/telegram-read-preparation-content.mjs test/queued-composer-ownership.mjs test/onboarding-provider-ready.mjs test/sidepanel-permission-gate-ui.mjs test/model-picker-status-ui.mjs test/workflow-native-targets.mjs test/native-whatsapp-chat.mjs test/native-chat-context-identity.mjs test/native-whatsapp-contact.mjs test/whatsapp-chat-selection.mjs test/whatsapp-native-bootstrap.mjs test/whatsapp-drawer-identity.mjs test/whatsapp-read-latest.mjs test/whatsapp-read-preparation.mjs test/whatsapp-chat-completion.mjs test/whatsapp-chat-restart.mjs test/chat-goal-lifecycle.mjs test/chat-completion.mjs test/chat-generic-dispatch.mjs test/completion-live-status-browser.mjs test/native-confirmation-visibility.mjs test/native-button-preparation.mjs test/read-continuation-browser.mjs test/iframe-preparation-focus.mjs test/contenteditable-literal.mjs test/native-chat-empty-editor.mjs test/native-chat-trusted-clear.mjs test/chat-steering-ui.mjs test/activity-brain-ui.mjs test/recipient-confirmation-ui.mjs test/assistant-message-visibility-ui.mjs test/slash-command-timeline-ui.mjs test/page-monitor-ui.mjs test/x-compose-trusted-typing.mjs test/page-monitor-dialog.mjs test/page-monitor-dialog-native.mjs test/page-monitor-inline-post.mjs test/bluesky-composer-context.mjs test/page-monitor-anchored.mjs test/page-monitor-upload-owner.mjs test/page-monitor-upload-release.mjs test/page-monitor-native-controls.mjs test/page-monitor-native-preparation.mjs test/native-preparation-cold.mjs test/page-monitor-navigation.mjs test/page-monitor-main-owner.mjs test/page-monitor-collateral-controls.mjs test/accessibility-tree-scoped-budget.mjs test/ax-reference-origin.mjs test/page-monitor-decorative-hit.mjs test/social-ui-navigation.mjs test/native-resource-deletion-binding.mjs test/native-mastodon-confirmation.mjs test/dropdown-menu-inventory.mjs test/page-monitor-passive-progress.mjs test/page-monitor-feed-items.mjs test/media-download-binding.mjs test/media-download-capture-integration.mjs test/social-media-downloader-reinjection.mjs test/upload-file-local-state-guidance.mjs test/monitor-intervention-contract.mjs test/monitor-owned-geometry.mjs test/monitor-viewport-remainder.mjs test/monitor-scroll-churn.mjs test/monitor-local-attribution.mjs test/monitor-lifecycle-leaks.mjs test/lifecycle-run-ui.mjs test/lifecycle-menu-prompts-held.mjs test/delivery-cdp-input.mjs test/delivery-click-ax-response-loss.mjs test/delivery-native-button-geometry.mjs test/delivery-hover-transition.mjs test/delivery-native-button-route.mjs test/delivery-dispatch-boundary.mjs test/delivery-stop-compound.mjs test/guards-control-classification.mjs test/guards-unbound-deletion.mjs test/submit-probe-readings.mjs test/declined-submission-identity.mjs test/improver-content-account-chrome.mjs test/improver-content-recipient.mjs test/improver-content-truncated-replacement.mjs test/improver-forms-probe.mjs test/improver-misc-trace-browser.mjs test/page-feedback-held-time.mjs test/page-monitor-held-observation.mjs","test:shard:browser-b1": "node test/message-recipient-upload.mjs && node test/message-recipient-clarify-binding.mjs && node --test test/message-recipient-whatsapp.mjs test/message-control-readings.mjs && node test/quality/integration-mv3.mjs --full-form && node test/quality/integration-mv3.mjs --batch && node test/quality/literal-calculate-midrun-mv3.mjs && node test/quality/ask-completion-churn-mv3.mjs && node test/quality/ask-person-activity-mv3.mjs && node test/quality/telegram-cold-preparation-mv3.mjs && node test/quality/native-chat-mv3.mjs && node test/quality/native-chat-presubmit-mv3.mjs && node test/quality/cloud-bot-memory-mv3.mjs","test:shard:browser-b2": "node test/quality/whatsapp-contact-matrix.mjs && node test/quality/pdf-detection-mv3.mjs && node test/quality/download-upload-mv3.mjs && node test/quality/upload-release-binding-mv3.mjs && node test/quality/upload-release-binding-mv3.mjs --selector-recovery && node test/quality/upload-release-binding-mv3.mjs --sequential-assets && node test/quality/release-review-world-mv3.mjs && node test/quality/downloaded-file-saved-bytes-mv3.mjs && node test/quality/file-upload-accept-mv3.mjs && node test/quality/bulk-resume-mv3.mjs && node test/quality/shared-action-guards-mv3.mjs && node test/quality/video-upload-attachment-mv3.mjs && node --test test/iframe-probe-match-index.mjs",diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex 8ddfe71de..1b2026921 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -134,7 +134,7 @@ import {normalizeCloudflareManagedChallengeState,} from './cloudflare-managed-challenge.js';import { getRecordingStateFresh as recorderStateFresh } from '../recorder/host.js';-import { Capability, CAPABILITY_LABEL, SubmitRisk, capabilitiesFor, classifySearchNavigation, classifySubmitRisk, requiredHosts, frameHostMatches, urlFilterHostHint, isNetworkMutation, normalizeHost, registrableHost, PermissionManager, submitActionKey, UNTRUSTED_CONTENT_TOOLS } from './permission-gate.js';+import { Capability, CAPABILITY_LABEL, SubmitRisk, capabilitiesFor, classifySearchNavigation, classifySubmitRisk, requiredHosts, inputReachesReceivingFrame, frameHostMatches, urlFilterHostHint, isNetworkMutation, normalizeHost, registrableHost, PermissionManager, submitActionKey, UNTRUSTED_CONTENT_TOOLS } from './permission-gate.js';import {buildPlannerMessages,buildPlannerAlignmentMessages,@@ -17185,23 +17185,34 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dlet aborted = false;let failClosed = false;let gateDisabled = false;+ // A coordinate click, type_text without a selector and press_keys go+ // to whichever document is under the point or has focus, which can be+ // an embedded cross-origin frame: the gate charges that document's+ // host. A model-supplied _inputFrameUrl is always overwritten.+ const receivingFrameInput = inputReachesReceivingFrame(fnName, fnArgs);+ const inputFrameUrl = receivingFrameInput+ ? await this._inputReceivingFrameUrl(tabId, fnName, fnArgs, curUrl)+ : '';+ let prompted = false;for (const capability of capabilities) {if (!requiresMandatoryWebMCPGates && this._skipPermissionGate) { gateDisabled = true; break; }// /allow-api waives ONLY write-method network egress.if (capability === Capability.NETWORK && isNetworkMutation(fnName, fnArgs) && apiMutationsAllowedForRun()) continue;// Every distinct host the call touches must be granted. Usually one,// but download_files takes a urls[] array that can span many hosts.- const gateArgs = fnName === 'generate_image'+ let gateArgs = fnName === 'generate_image'? { _generativeMediaUrl: imageGenPermissionUrl }: fnName === OTP_EMAIL_TOOL_NAME && otpEmailPermissionArgs? otpEmailPermissionArgs: this._skillPermissionArgsForCapability(skillCallTool, capability, fnArgs);+ if (receivingFrameInput) gateArgs = { ...gateArgs, _inputFrameUrl: inputFrameUrl };const hosts = requiredHosts(capability, gateArgs, curUrl, fnName);if (hosts.length === 0) { failClosed = true; break; }for (const host of hosts) {if (!requiresMandatoryWebMCPGates && this._skipPermissionGate) { gateDisabled = true; break; }const verdict = this.permissions.check(host, capability, tabId);if (verdict.allowed) continue;+ if (verdict.needsPrompt) prompted = true;const choice = verdict.needsPrompt? await this._promptPermission(tabId, capability, host, onUpdate): 'deny'; // a standing "deny" grant for this (capability, host)@@ -17240,13 +17251,37 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dcontent: JSON.stringify({success: false,denied: true,- error: `Cannot run ${fnName}: the target frame/host couldn't be identified, so it can't be permission-checked. Pass a urlFilter naming the iframe's domain (read it first with iframe_read / get_accessibility_tree) and retry.`,+ error: receivingFrameInput+ ? `Cannot run ${fnName}: WebBrain could not identify the site of the document ${fnName === 'click' ? 'under that point' : 'that has keyboard focus'}, so the input can't be permission-checked. Nothing was sent. Look at the page again before retrying; for a field inside an embedded frame, use iframe_click / iframe_type with a urlFilter naming the frame's domain.`+ : `Cannot run ${fnName}: the target frame/host couldn't be identified, so it can't be permission-checked. Pass a urlFilter naming the iframe's domain (read it first with iframe_read / get_accessibility_tree) and retry.`,}),});predispatchBlocked('permissionMs');if (interruptFailedBrowserAction(toolIndex, fnName)) { navNotices.length = 0; break; }continue;}+ // While a card was open the page could move a frame under the point or+ // focus into one; the input would then reach a document the user was+ // not asked about.+ if (receivingFrameInput && prompted && !blocked && !gateDisabled) {+ const currentFrameUrl = await this._inputReceivingFrameUrl(tabId, fnName, fnArgs, await this._currentUrl(tabId));+ if (!normalizeHost(currentFrameUrl) || normalizeHost(currentFrameUrl) !== normalizeHost(inputFrameUrl)) {+ messages.push({+ role: 'tool',+ tool_call_id: tc.id,+ content: JSON.stringify({+ success: false,+ denied: true,+ noDispatch: true,+ error: `Not sent: while the permission card was open, the document ${fnName === 'click' ? 'under that point' : 'with keyboard focus'} changed to one on ${normalizeHost(currentFrameUrl) || 'an unidentified site'}. Look at the page again before retrying.`,+ }),+ });+ onUpdate('warning', { message: 'Input not sent: the page moved it to another document while the permission card was open.' });+ predispatchBlocked('permissionMs');+ if (interruptFailedBrowserAction(toolIndex, fnName)) { navNotices.length = 0; break; }+ continue;+ }+ }if (blocked) {messages.push({role: 'tool',@@ -37866,6 +37901,22 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dthis._persist(tabId);}+ // The URL whose host the gate charges for point or focus input+ // (permission-gate.js inputReachesReceivingFrame): the tab's address while+ // the input stays in the top document, the embedded frame's effective URL+ // when it would land in one, and '' when CDP cannot establish the receiving+ // document or its site, which fails the gate closed.+ async _inputReceivingFrameUrl(tabId, fnName, fnArgs, curUrl) {+ try {+ const frame = await cdpClient.resolveInputFrame(tabId, fnName === 'click'+ ? { x: Number(fnArgs?.x), y: Number(fnArgs?.y) }+ : { focused: true });+ return frame?.topDocument === true ? String(curUrl || '') : String(frame?.url || '');+ } catch {+ return '';+ }+ }+_skillPermissionArgsForCapability(skillTool, capability, args) {if (isTrustedChromeWebStoreSkillTool(skillTool)diff --git a/src/chrome/src/agent/permission-gate.js b/src/chrome/src/agent/permission-gate.jsindex ac2b0772d..83d7b3941 100644--- a/src/chrome/src/agent/permission-gate.js+++ b/src/chrome/src/agent/permission-gate.js@@ -648,6 +648,20 @@ export function urlFilterHostHint(urlFilter, frameUrls = []) {: '';}+/**+ * Does this call's input go to whichever document is under a viewport point+ * or holds keyboard focus, rather than to an element WebBrain resolved in the+ * top document? A coordinate click (a vision click_at runs as one), type_text+ * without a selector and press_keys do: native input lands in an embedded+ * frame there, a cross-origin payment, identity or wallet frame included.+ */+export function inputReachesReceivingFrame(toolName, args) {+ args = args || {};+ if (toolName === 'click') return args.x != null && args.y != null;+ if (toolName === 'type_text') return !args.selector;+ return toolName === 'press_keys';+}+/** Resolve a URL (relative / protocol-relative / absolute) to a host against a* base page URL — exactly what the browser handler does (new URL(raw, base)). */function resolveHostAgainst(url, base) {@@ -663,7 +677,8 @@ function resolveHostAgainst(url, base) {/*** Which host does this capability act on? Navigate/network/download target the* destination URL (resolved against the current page); click/type/execute/- * record target the current page. Returns '' for an iframe action whose frame+ * record target the current page (or the frame that receives point/focus+ * input). Returns '' for an iframe action or point/focus input whose frame* can't be identified, so the caller fails closed. For the MULTI-host case* (download_files with a urls[] array) use requiredHosts() instead.*/@@ -694,6 +709,13 @@ export function hostForCapability(capability, args, currentUrlOrHost, toolName)if (toolName === 'iframe_click' || toolName === 'iframe_type' || toolName === 'promote_iframe') {return normalizeHost(args.urlFilter);}+ // Point and focus input reaches the receiving document, not necessarily the+ // top-level page. agent.js always overwrites _inputFrameUrl with that+ // document's URL before the gate runs; '' (it could not be identified)+ // fails closed instead of borrowing the top-level page's grant.+ if ((capability === Capability.CLICK || capability === Capability.TYPE) && inputReachesReceivingFrame(toolName, args)) {+ return normalizeHost(args._inputFrameUrl);+ }if (capability === Capability.NAVIGATE || capability === Capability.NETWORK || capability === Capability.DOWNLOAD) {if (typeof args.url === 'string' && args.url) {const h = resolveHostAgainst(args.url, currentUrlOrHost);diff --git a/src/chrome/src/cdp/cdp-client.js b/src/chrome/src/cdp/cdp-client.jsindex 5814d7fff..800a4a181 100644--- a/src/chrome/src/cdp/cdp-client.js+++ b/src/chrome/src/cdp/cdp-client.js@@ -1087,6 +1087,123 @@ export class CDPClient {}}+ /**+ * The document native input reaches: the one under a viewport point (a+ * coordinate click) or the one holding keyboard focus (type_text without a+ * selector, press_keys). Chrome delivers that input into embedded frames,+ * process-isolated cross-origin ones included, so the permission gate+ * charges this document's site rather than the top-level page's. The walk+ * follows _pageAgentInputTarget, but focus, scroll offsets and the frame's+ * origin are read in an isolated world, where the page cannot redefine+ * activeElement, scrollX or origin. Returns { topDocument: true } for the+ * tab's own document, else { topDocument: false, url } with url '' when the+ * frame has no web origin (a sandboxed or data: document). Throws when the+ * receiving document cannot be established.+ */+ async resolveInputFrame(tabId, target = {}) {+ const keyboard = target.focused === true;+ let x = Number(target.x), y = Number(target.y);+ if (!keyboard && (!Number.isFinite(x) || !Number.isFinite(y))) throw new Error('Input point is not a number');+ await this.attach(tabId);+ let sessionId = '';+ const temporarySessions = [];+ const isolatedContext = async frameId => (await this.sendCommand(tabId, 'Page.createIsolatedWorld',+ { frameId, worldName: 'webbrain-input-frame' }, sessionId)).executionContextId;+ try {+ for (let depth = 0; depth < 16; depth++) {+ const tree = await this.getAllFrames(tabId, sessionId);+ const frames = new Map(tree.map(frame => [String(frame.id), frame]));+ const rootFrameId = String(tree[0]?.id || '');+ if (!rootFrameId) throw new Error('Cannot read the input frame tree');+ let frameId = rootFrameId;+ let contextId = await isolatedContext(frameId);+ let contextFrameId = frameId;+ // A process-isolated child, entered through its own session next.+ let remoteFrameId = '';+ if (keyboard) {+ for (let local = 0; local < 16; local++) {+ const focused = await this.sendCommand(tabId, 'Runtime.evaluate', {+ expression: '(() => { let el = document.activeElement; while (el?.shadowRoot?.activeElement) el = el.shadowRoot.activeElement; return el; })()',+ contextId,+ }, sessionId);+ const objectId = focused?.result?.objectId;+ if (!objectId) break;+ let node;+ try { ({ node } = await this.sendCommand(tabId, 'DOM.describeNode', { objectId }, sessionId)); }+ finally { this.releaseObject(tabId, objectId, sessionId); }+ // Focus inside a frame shows in its parent as the frame element;+ // <object> and <embed> can host a cross-origin document too.+ if (!node?.frameId || !/^(IFRAME|FRAME|OBJECT|EMBED)$/.test(node.nodeName)) break;+ if (!frames.has(String(node.frameId))) { remoteFrameId = String(node.frameId); break; }+ frameId = String(node.frameId);+ contextId = await isolatedContext(frameId);+ contextFrameId = frameId;+ }+ } else {+ const offset = await this.sendCommand(tabId, 'Runtime.evaluate', {+ expression: '({ x: scrollX, y: scrollY })', returnByValue: true, contextId,+ }, sessionId);+ const scroll = offset?.result?.value;+ if (!Number.isFinite(scroll?.x) || !Number.isFinite(scroll?.y)) throw new Error('Cannot resolve input document coordinates');+ const hit = await this.sendCommand(tabId, 'DOM.getNodeForLocation', { x: Math.round(x + scroll.x), y: Math.round(y + scroll.y) }, sessionId);+ frameId = String(hit?.frameId || rootFrameId);+ const { node } = await this.sendCommand(tabId, 'DOM.describeNode', { backendNodeId: hit.backendNodeId }, sessionId);+ // The hit test already enters same-process frames, so a frame element+ // here is a process-isolated frame (or the point is on a frame's+ // border); either way the frame is taken as the receiver.+ if (node?.frameId && /^(IFRAME|FRAME|OBJECT|EMBED)$/.test(node.nodeName)) {+ if (frames.has(String(node.frameId))) frameId = String(node.frameId);+ else {+ remoteFrameId = String(node.frameId);+ const owner = await this.sendCommand(tabId, 'DOM.resolveNode', {+ backendNodeId: hit.backendNodeId,+ executionContextId: frameId === rootFrameId ? contextId : await isolatedContext(frameId),+ }, sessionId);+ let quads, size;+ try {+ ({ quads } = await this.sendCommand(tabId, 'DOM.getContentQuads', { backendNodeId: hit.backendNodeId }, sessionId));+ size = (await this.sendCommand(tabId, 'Runtime.callFunctionOn', { objectId: owner.object.objectId,+ functionDeclaration: 'function () { return { width: this.clientWidth, height: this.clientHeight }; }', returnByValue: true }, sessionId))?.result?.value;+ } finally { this.releaseObject(tabId, owner?.object?.objectId, sessionId); }+ const q = quads?.[0];+ if (!q || !size?.width || !size?.height) throw new Error('Cannot resolve the input frame');+ const ax = q[2] - q[0], ay = q[3] - q[1], bx = q[6] - q[0], by = q[7] - q[1];+ const determinant = ax * by - ay * bx, dx = x - q[0], dy = y - q[1];+ if (!determinant) throw new Error('Cannot resolve the input frame');+ x = (dx * by - dy * bx) / determinant * size.width;+ y = (ax * dy - ay * dx) / determinant * size.height;+ }+ }+ }+ if (remoteFrameId) {+ const existing = [...(this.runtimeContexts.get(tabId)?.values() || [])].find(context => context.frameId === remoteFrameId && context.sessionId);+ if (existing) sessionId = existing.sessionId;+ else {+ const attached = await this.sendCommand(tabId, 'Target.attachToTarget', { targetId: remoteFrameId, flatten: true });+ sessionId = attached.sessionId; temporarySessions.push(sessionId);+ }+ continue;+ }+ if (!sessionId && frameId === rootFrameId) return { topDocument: true };+ const frame = frames.get(frameId);+ if (!frame) throw new Error('The input frame is not in the frame tree');+ // The frame tree derives securityOrigin from the URL, which hides the+ // origin an about:blank or srcdoc document inherits and the opaque+ // origin of a sandboxed one; the document's own origin decides.+ const origin = await this.sendCommand(tabId, 'Runtime.evaluate', {+ expression: 'self.origin', returnByValue: true,+ contextId: contextFrameId === frameId ? contextId : await isolatedContext(frameId),+ }, sessionId);+ return { topDocument: false, url: this._webMCPSafeFrameUrl({ url: frame.url, securityOrigin: String(origin?.result?.value || 'null') }) };+ }+ throw new Error('Input frame nesting exceeds the limit');+ } finally {+ for (const id of temporarySessions.reverse()) {+ try { await this.sendCommand(tabId, 'Target.detachFromTarget', { sessionId: id }); } catch {}+ }+ }+ }+/*** Register an event handler.*/diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex a175c03d3..fbbb12398 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -126,7 +126,7 @@ import {cloudflareManagedChallengeStorageKey,normalizeCloudflareManagedChallengeState,} from './cloudflare-managed-challenge.js';-import { Capability, CAPABILITY_LABEL, SubmitRisk, capabilitiesFor, classifySearchNavigation, classifySubmitRisk, requiredHosts, frameHostMatches, urlFilterHostHint, isNetworkMutation, normalizeHost, registrableHost, PermissionManager, submitActionKey, UNTRUSTED_CONTENT_TOOLS } from './permission-gate.js';+import { Capability, CAPABILITY_LABEL, SubmitRisk, capabilitiesFor, classifySearchNavigation, classifySubmitRisk, requiredHosts, inputReachesReceivingFrame, frameHostMatches, urlFilterHostHint, isNetworkMutation, normalizeHost, registrableHost, PermissionManager, submitActionKey, UNTRUSTED_CONTENT_TOOLS } from './permission-gate.js';import {buildPlannerMessages,buildPlannerAlignmentMessages,@@ -15332,17 +15332,28 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dlet aborted = false;let failClosed = false;let gateDisabled = false;+ // A coordinate click, type_text without a selector and press_keys are+ // charged to the document that receives them (permission-gate.js+ // inputReachesReceivingFrame). On Firefox that is the top document, or+ // for a vision click a same-origin frame that shares its host: the+ // content script dispatches synthetic events there, and trusted+ // companion input on an embedded frame is refused (content.js+ // prepareBidiTarget, firefox-companion/session.mjs). Chrome's CDP input+ // does reach cross-origin frames, so its agent.js resolves the frame.+ // A model-supplied _inputFrameUrl is always overwritten.+ const receivingFrameInput = inputReachesReceivingFrame(fnName, fnArgs);for (const capability of capabilities) {if (this._skipPermissionGate) { gateDisabled = true; break; }// /allow-api waives ONLY write-method network egress.if (capability === Capability.NETWORK && isNetworkMutation(fnName, fnArgs) && apiMutationsAllowedForRun()) continue;// Every distinct host the call touches must be granted. Usually one,// but download_files takes a urls[] array that can span many hosts.- const gateArgs = fnName === 'generate_image'+ let gateArgs = fnName === 'generate_image'? { _generativeMediaUrl: imageGenPermissionUrl }: fnName === OTP_EMAIL_TOOL_NAME && otpEmailPermissionArgs? otpEmailPermissionArgs: this._skillPermissionArgsForCapability(skillCallTool, capability, fnArgs);+ if (receivingFrameInput) gateArgs = { ...gateArgs, _inputFrameUrl: curUrl };const hosts = requiredHosts(capability, gateArgs, curUrl, fnName);if (hosts.length === 0) { failClosed = true; break; }for (const host of hosts) {@@ -15387,7 +15398,9 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dcontent: JSON.stringify({success: false,denied: true,- error: `Cannot run ${fnName}: the target frame/host couldn't be identified, so it can't be permission-checked. Pass a urlFilter naming the iframe's domain (read it first with iframe_read / get_accessibility_tree) and retry.`,+ error: receivingFrameInput+ ? `Cannot run ${fnName}: WebBrain could not identify the site of the document ${fnName === 'click' ? 'under that point' : 'that has keyboard focus'}, so the input can't be permission-checked. Nothing was sent. Look at the page again before retrying; for a field inside an embedded frame, use iframe_click / iframe_type with a urlFilter naming the frame's domain.`+ : `Cannot run ${fnName}: the target frame/host couldn't be identified, so it can't be permission-checked. Pass a urlFilter naming the iframe's domain (read it first with iframe_read / get_accessibility_tree) and retry.`,}),});predispatchBlocked('permissionMs');diff --git a/src/firefox/src/agent/permission-gate.js b/src/firefox/src/agent/permission-gate.jsindex cc60c20aa..6e6912600 100644--- a/src/firefox/src/agent/permission-gate.js+++ b/src/firefox/src/agent/permission-gate.js@@ -633,6 +633,20 @@ export function urlFilterHostHint(urlFilter, frameUrls = []) {: '';}+/**+ * Does this call's input go to whichever document is under a viewport point+ * or holds keyboard focus, rather than to an element WebBrain resolved in the+ * top document? A coordinate click (a vision click_at runs as one), type_text+ * without a selector and press_keys do: native input lands in an embedded+ * frame there, a cross-origin payment, identity or wallet frame included.+ */+export function inputReachesReceivingFrame(toolName, args) {+ args = args || {};+ if (toolName === 'click') return args.x != null && args.y != null;+ if (toolName === 'type_text') return !args.selector;+ return toolName === 'press_keys';+}+/** Resolve a URL (relative / protocol-relative / absolute) to a host against a* base page URL — exactly what the browser handler does (new URL(raw, base)). */function resolveHostAgainst(url, base) {@@ -648,7 +662,8 @@ function resolveHostAgainst(url, base) {/*** Which host does this capability act on? Navigate/network/download target the* destination URL (resolved against the current page); click/type/execute/- * record target the current page. Returns '' for an iframe action whose frame+ * record target the current page (or the frame that receives point/focus+ * input). Returns '' for an iframe action or point/focus input whose frame* can't be identified, so the caller fails closed. For the MULTI-host case* (download_files with a urls[] array) use requiredHosts() instead.*/@@ -679,6 +694,13 @@ export function hostForCapability(capability, args, currentUrlOrHost, toolName)if (toolName === 'iframe_click' || toolName === 'iframe_type' || toolName === 'promote_iframe') {return normalizeHost(args.urlFilter);}+ // Point and focus input reaches the receiving document, not necessarily the+ // top-level page. agent.js always overwrites _inputFrameUrl with that+ // document's URL before the gate runs; '' (it could not be identified)+ // fails closed instead of borrowing the top-level page's grant.+ if ((capability === Capability.CLICK || capability === Capability.TYPE) && inputReachesReceivingFrame(toolName, args)) {+ return normalizeHost(args._inputFrameUrl);+ }if (capability === Capability.NAVIGATE || capability === Capability.NETWORK || capability === Capability.DOWNLOAD) {if (typeof args.url === 'string' && args.url) {const h = resolveHostAgainst(args.url, currentUrlOrHost);diff --git a/src/firefox/src/content/content.js b/src/firefox/src/content/content.jsindex 9f5dfc9b6..138a4d406 100644--- a/src/firefox/src/content/content.js+++ b/src/firefox/src/content/content.js@@ -3759,8 +3759,10 @@const clickedRect = rememberInteractionPoint(el, 'click');if (actionDeadlineExpired()) return deadlineFailure();if (params._bidiPrepare) {+ const prepared = prepareBidiTarget(el, params._bidiPrepare);+ if (!prepared.bidiPrepared) return prepared;const coordinateClick = !params.text && !params.selector && params.index == null && Number.isFinite(params.x) && Number.isFinite(params.y);- return { ...prepareBidiTarget(el, params._bidiPrepare),+ return { ...prepared,...(coordinateClick ? { point: { x: Math.round(params.x), y: Math.round(params.y) } } : {}),_filePickerGuardId: clickWithoutNativeFilePicker(() => {}).guardId };}@@ -4561,7 +4563,10 @@? focusedTarget: document;- if (params._bidiPrepare) return prepareBidiTarget(focusedTarget || document.body, params._bidiPrepare);+ // Tab and Escape stay ungated (permission-gate.js capabilityFor) and may+ // reach a frame that has focus; any other key may not.+ if (params._bidiPrepare) return prepareBidiTarget(focusedTarget || document.body, params._bidiPrepare,+ { allowEmbeddedFrame: key === 'Tab' || key === 'Escape' });const moveTabFocus = () => {const focusables = Array.from(document.querySelectorAll(@@ -7028,10 +7033,18 @@// conversation before a message can be sent. It deliberately ignores input// values and ordinary page text: a searched recipient name is not proof that// the corresponding conversation is active.- function prepareBidiTarget(el, token) {+ function prepareBidiTarget(el, token, { allowEmbeddedFrame = false } = {}) {if (!/^[a-f0-9-]{36}$/.test(token || '') || !el?.isConnected) {return { success: false, dispatched: false, noDispatch: true, error: 'Invalid trusted-input target' };}+ // Trusted input on a frame element (a click on it, or keys while focus is+ // inside it) acts in the frame's own document, which can be another site+ // (a payment, identity or wallet frame) that the permission for this page+ // does not cover. The iframe tools charge that frame's host instead.+ if (!allowEmbeddedFrame && /^(IFRAME|FRAME|OBJECT|EMBED)$/i.test(String(el.tagName || ''))) {+ return { success: false, dispatched: false, noDispatch: true, embeddedFrameTarget: true,+ error: 'Not sent: the target is an embedded frame, and trusted input there would act in the frame\'s own document. Use iframe_click or iframe_type with a urlFilter naming the frame\'s domain.' };+ }el.setAttribute('data-webbrain-bidi', token);setTimeout(() => { if (el.getAttribute('data-webbrain-bidi') === token) el.removeAttribute('data-webbrain-bidi'); }, 10000);const rect = el.getBoundingClientRect();@@ -10685,7 +10698,8 @@const r = el.getBoundingClientRect();const cx = r.left + r.width / 2;const cy = r.top + r.height / 2;- if (msg.params?._bidiPrepare) return prepareBidiTarget(el, msg.params._bidiPrepare);+ // Hover is ungated, like Tab and Escape (pressKeys).+ if (msg.params?._bidiPrepare) return prepareBidiTarget(el, msg.params._bidiPrepare, { allowEmbeddedFrame: true });const eventInit = { bubbles: true, cancelable: true, view: window, clientX: cx, clientY: cy };const dispatchHover = (EventType, type) => {if (actionDeadlineExpired()) return false;diff --git a/test/firefox-bidi.mjs b/test/firefox-bidi.mjsindex d0df838c1..d12a011c7 100644--- a/test/firefox-bidi.mjs+++ b/test/firefox-bidi.mjs@@ -713,6 +713,26 @@ test('trusted target validation descends through open shadow roots', async () =>assert.match(validation, /shadowRoot\.elementFromPoint/);assert.match(validation, /node\.parentNode \|\| node\.host/);});+test('a trusted click over an embedded frame is refused before any input', async () => {+ // The marked element is a container whose point is covered by a frame:+ // the press would land in the frame's own document, another site.+ for (const action of ['click', 'click_at']) {+ const session = new BidiSession(); const runId = id(); const token = id(); const sent = [];+ const el = { isConnected: true, tagName: 'DIV', disabled: false,+ getAttribute: name => name === 'data-webbrain-bidi' ? token : null, removeAttribute() {},+ getBoundingClientRect: () => ({ x: 0, y: 0, width: 300, height: 200 }) };+ const frame = { tagName: 'IFRAME', parentNode: el };+ session.runs.set(runId, { context: 'tab' });+ session.locate = async () => ({ context: 'tab', node: { sharedId: 'container' } });+ session.call = async (_match, declaration, args = []) => ({ result: { value: vm.runInNewContext(`(${declaration})`, {+ document: { elementFromPoint: () => frame }, innerWidth: 800, innerHeight: 600,+ })(el, ...args.map(arg => arg.type === 'null' ? null : arg.value)) } });+ session.send = async method => { sent.push(method); return {}; };+ await assert.rejects(session.perform(runId, action, { token, point: { x: 40, y: 40 } }),+ error => /Target changed or is covered/.test(error.message) && error.dispatchState.noDispatch === true, action);+ assert.deepEqual(sent, [], action);+ }+});test('keyboard validation does not require pointer geometry', async () => {const session = new BidiSession(); const runId = id(); const calls = [];session.runs.set(runId, { context: 'tab' });diff --git a/test/input-receiving-frame.mjs b/test/input-receiving-frame.mjsnew file mode 100644index 000000000..3b47603aa--- /dev/null+++ b/test/input-receiving-frame.mjs@@ -0,0 +1,212 @@+import assert from 'node:assert/strict';+import { randomUUID } from 'node:crypto';+import { readFile } from 'node:fs/promises';+import { test } from 'node:test';+import { chromium } from 'playwright';+import { cdpClient } from '../src/chrome/src/cdp/cdp-client.js';++// A coordinate click, type_text without a selector and press_keys reach the+// document under the point or holding focus. The permission gate charges that+// document's host, so the production CDP resolver must find an embedded+// cross-origin (process-isolated) frame the way Chrome delivers the input, and+// not be talked out of it by the top page. Only chrome.debugger is bridged to+// Playwright's CDP sessions; no website is contacted.+const TAB = 31;+const MERCHANT = 'https://merchant.invalid/checkout';+const WALLET = 'https://wallet.invalid/pay';+const SANDBOXED = 'https://wallet.invalid/sandboxed';+const OBJECT = 'https://wallet.invalid/object';+const top = `<!doctype html><style>+body{margin:0;height:1800px}iframe{position:absolute;left:20px;width:320px;border:3px solid;padding:0}+#topField{position:absolute;left:20px;top:50px;width:200px;height:30px}+</style><input id="topField" aria-label="Top field">+<iframe id="wallet" src="${WALLET}" style="top:100px;height:150px"></iframe>+<iframe id="same" srcdoc="<style>body{margin:0}</style><input id=inner style='margin:20px;width:200px;height:30px'>" style="top:300px;height:100px"></iframe>+<iframe id="sandboxed" sandbox="allow-scripts" src="${SANDBOXED}" style="top:450px;height:100px"></iframe>+<object id="object" type="text/html" data="${OBJECT}" style="position:absolute;left:400px;top:100px;width:320px;height:150px"></object>`;+const walletHtml = '<!doctype html><style>body{margin:0}</style><input id="card" aria-label="Card" style="margin:30px;width:200px;height:30px">';++test('Chrome: the input receiving frame is the embedded frame under the point or holding focus', { timeout: 60000 }, async t => {+ const saved = { chrome: globalThis.chrome, attach: cdpClient.attach };+ const browser = await chromium.launch({ headless: true, args: ['--site-per-process'] });+ const children = new Map(); // fake sessionId -> Playwright CDP session of an OOPIF+ const frameByTarget = new Map();+ let session;+ let attaches = 0;+ const send = async (target, method, params) => {+ if (!target.sessionId && method === 'Target.attachToTarget') {+ const frame = frameByTarget.get(params.targetId);+ if (!frame) throw new Error(`No target ${params.targetId}`);+ const sessionId = `child-${++attaches}`;+ children.set(sessionId, await frame.page().context().newCDPSession(frame));+ return { sessionId };+ }+ if (!target.sessionId && method === 'Target.detachFromTarget') {+ await children.get(params.sessionId)?.detach();+ children.delete(params.sessionId);+ return {};+ }+ return (target.sessionId ? children.get(target.sessionId) : session).send(method, params);+ };+ globalThis.chrome = {+ runtime: {},+ debugger: { sendCommand: (target, method, params, callback) => {+ send(target, method, params).then(callback, error => {+ chrome.runtime.lastError = { message: error.message }; callback(); delete chrome.runtime.lastError;+ });+ } },+ };+ cdpClient.attach = async () => cdpClient.sessions.set(TAB, {});+ try {+ const context = await browser.newContext({ viewport: { width: 900, height: 700 } });+ await context.route('**/*', route => {+ const url = route.request().url();+ if (url === MERCHANT) return route.fulfill({ contentType: 'text/html', body: top });+ if (url === WALLET || url === SANDBOXED || url === OBJECT) return route.fulfill({ contentType: 'text/html', body: walletHtml });+ return route.abort();+ });+ const page = await context.newPage();+ await page.goto(MERCHANT);+ session = await context.newCDPSession(page);+ // Playwright gives no content frame for an <object>; find it by address.+ const frameOf = async selector => (await (await page.locator(selector).elementHandle()).contentFrame())+ || page.frames().find(frame => frame.url() === OBJECT);+ for (const id of ['wallet', 'sandboxed', 'object']) {+ const frame = await frameOf(`#${id}`);+ await frame.waitForSelector('#card');+ const { result } = await session.send('Runtime.evaluate', { expression: `document.getElementById(${JSON.stringify(id)})` });+ const { node } = await session.send('DOM.describeNode', { objectId: result.objectId });+ frameByTarget.set(node.frameId, frame);+ }+ const wallet = await (await page.locator('#wallet').elementHandle()).contentFrame();+ const same = await (await page.locator('#same').elementHandle()).contentFrame();+ await same.waitForSelector('#inner');+ // Scroll the top page so viewport points differ from document points.+ await page.evaluate(() => scrollTo(0, 30));+ const centre = async (frameSelector, fieldSelector) => {+ const box = await page.locator(frameSelector).evaluate(node => {+ const rect = node.getBoundingClientRect(); return { left: rect.left + 3, top: rect.top + 3 };+ });+ const frame = await frameOf(frameSelector);+ const field = await frame.locator(fieldSelector).evaluate(node => {+ const rect = node.getBoundingClientRect(); return { x: rect.left + rect.width / 2, y: rect.top + rect.height / 2 };+ });+ return { x: box.left + field.x, y: box.top + field.y };+ };++ await t.test('a point on the top document stays with the top document', async () => {+ const point = await page.locator('#topField').evaluate(node => {+ const rect = node.getBoundingClientRect(); return { x: rect.left + 5, y: rect.top + 5 };+ });+ assert.deepEqual(await cdpClient.resolveInputFrame(TAB, point), { topDocument: true });+ });++ await t.test('a point over a process-isolated cross-origin frame resolves to that frame', async () => {+ const frame = await cdpClient.resolveInputFrame(TAB, await centre('#wallet', '#card'));+ assert.equal(frame.topDocument, false);+ assert.equal(new URL(frame.url).hostname, 'wallet.invalid');+ assert.equal(children.size, 0, 'temporary child sessions are detached');+ });++ await t.test('an <object> hosting another site is a frame like an <iframe>', async () => {+ const frame = await cdpClient.resolveInputFrame(TAB, await centre('#object', '#card'));+ assert.equal(frame.topDocument, false);+ assert.equal(new URL(frame.url).hostname, 'wallet.invalid');+ });++ await t.test('a srcdoc frame keeps the origin it inherits from the top site', async () => {+ const frame = await cdpClient.resolveInputFrame(TAB, await centre('#same', '#inner'));+ assert.equal(frame.topDocument, false);+ assert.equal(new URL(frame.url).hostname, 'merchant.invalid');+ });++ await t.test('a sandboxed frame has no web origin to charge, so the gate fails closed', async () => {+ const frame = await cdpClient.resolveInputFrame(TAB, await centre('#sandboxed', '#card'));+ assert.deepEqual(frame, { topDocument: false, url: '' });+ });++ await t.test('focus resolves to the document that holds it', async () => {+ await page.locator('#topField').focus();+ assert.deepEqual(await cdpClient.resolveInputFrame(TAB, { focused: true }), { topDocument: true });+ await wallet.locator('#card').focus();+ const frame = await cdpClient.resolveInputFrame(TAB, { focused: true });+ assert.equal(frame.topDocument, false);+ assert.equal(new URL(frame.url).hostname, 'wallet.invalid');+ });++ await t.test('the top page cannot redefine activeElement or the scroll offset to hide the frame', async () => {+ await wallet.locator('#card').focus();+ await page.evaluate(() => {+ Object.defineProperty(Document.prototype, 'activeElement', { configurable: true, get() { return document.body; } });+ Object.defineProperty(window, 'scrollY', { configurable: true, get() { return 400; } });+ Object.defineProperty(window, 'origin', { configurable: true, get() { return 'https://merchant.invalid'; } });+ });+ const focused = await cdpClient.resolveInputFrame(TAB, { focused: true });+ assert.equal(new URL(focused.url).hostname, 'wallet.invalid');+ const pointed = await cdpClient.resolveInputFrame(TAB, await centre('#wallet', '#card'));+ assert.equal(new URL(pointed.url).hostname, 'wallet.invalid');+ });+ } finally {+ for (const child of children.values()) await child.detach().catch(() => {});+ cdpClient.attach = saved.attach;+ cdpClient.sessions.delete(TAB);+ globalThis.chrome = saved.chrome;+ await browser.close();+ }+});++// Firefox's synthetic input cannot enter a cross-origin frame, but trusted+// companion input (WebDriver BiDi) can. The content script prepares that+// input, so it must not hand over a frame element as the target. Firefox's+// content scripts run in Chromium here, as in other content tests.+test('Firefox: trusted companion input is not prepared on an embedded frame', { timeout: 60000 }, async () => {+ const browser = await chromium.launch({ headless: true, args: ['--site-per-process'] });+ try {+ const context = await browser.newContext({ viewport: { width: 900, height: 700 } });+ const html = `<!doctype html><style>body{margin:0}iframe{position:absolute;left:20px;top:100px;width:320px;height:150px;border:0}+#pay{position:absolute;left:20px;top:20px;width:120px;height:40px}</style>+<button id="pay" type="button">Pay</button><iframe id="wallet" src="${WALLET}"></iframe>`;+ await context.route('**/*', route => {+ const url = route.request().url();+ if (url === MERCHANT) return route.fulfill({ contentType: 'text/html', body: html });+ if (url === WALLET) return route.fulfill({ contentType: 'text/html', body: walletHtml });+ return route.abort();+ });+ const tab = await context.newPage();+ await tab.goto(MERCHANT);+ await tab.evaluate(() => {+ window.fixtureHandlers = [];+ const runtime = { onMessage: { addListener(fn) { window.fixtureHandlers.push(fn); } }, getURL: p => p, sendMessage: async () => ({}) };+ window.chrome = { runtime }; window.browser = { runtime };+ });+ for (const file of ['file-upload-policy.js', 'rich-text-toolbar-heuristic.js', 'accessibility-tree.js', 'content.js']) {+ await tab.addScriptTag({ content: await readFile(new URL(`../src/firefox/src/content/${file}`, import.meta.url), 'utf8') });+ }+ const wallet = await (await tab.locator('#wallet').elementHandle()).contentFrame();+ await wallet.waitForSelector('#card');+ const call = (action, params) => tab.evaluate(message => new Promise(resolve => {+ for (const handler of window.fixtureHandlers) handler(message, {}, resolve);+ }), { target: 'content', action, params: { ...params, _bidiPrepare: randomUUID() } });+ const centre = selector => tab.locator(selector).evaluate(node => {+ const rect = node.getBoundingClientRect(); return { x: rect.left + rect.width / 2, y: rect.top + rect.height / 2 };+ });++ const overFrame = await call('click', await centre('#wallet'));+ assert.equal(overFrame.embeddedFrameTarget, true, JSON.stringify(overFrame));+ assert.equal(overFrame.noDispatch, true);+ assert.equal(overFrame.bidiPrepared, undefined);+ assert.equal(await tab.evaluate(() => document.querySelector('[data-webbrain-bidi]')), null, 'the frame was marked for trusted input');+ const onPage = await call('click', await centre('#pay'));+ assert.equal(onPage.bidiPrepared, true, JSON.stringify(onPage));++ await wallet.locator('#card').focus();+ const enter = await call('press_keys', { key: 'Enter' });+ assert.equal(enter.embeddedFrameTarget, true, JSON.stringify(enter));+ assert.equal(enter.bidiPrepared, undefined);+ // Tab and Escape stay ungated, as on Chrome.+ const escape = await call('press_keys', { key: 'Escape' });+ assert.equal(escape.bidiPrepared, true, JSON.stringify(escape));+ } finally {+ await browser.close();+ }+});diff --git a/test/run.js b/test/run.jsindex 62cf7d479..0261f3f49 100644--- a/test/run.js+++ b/test/run.js@@ -83820,6 +83820,112 @@ test('iframe submit without urlFilter fails before confirmation or dispatch', as}});+// A coordinate click, type_text without a selector and press_keys go to the+// document under the point or with focus. On Chrome (CDP) that can be an+// embedded wallet frame, so a grant for the merchant page must not cover it.+function receivingFrameGateAgent(AgentClass, tabId, { frameUrls = [], choice = 'deny' } = {}) {+ const agent = new AgentClass({ getVisionProvider: async () => null });+ const state = { executed: [], prompts: [], resolved: [] };+ agent._ensureGateSetting = async () => false;+ agent._skipPermissionGate = false;+ agent._currentUrl = async () => 'https://merchant.example/checkout';+ agent._recordProgressObservation = async () => null;+ agent._autoRecordProgressAction = () => null;+ agent._progressWarningForAction = () => '';+ agent._persist = () => { };+ agent._detectLikelySubmitAction = async () => null;+ agent._iframeRectsForCoordinate = async () => [];+ agent.permissions.hydrate = async () => { };+ // The merchant page itself is already allowed for every capability.+ agent.permissions.check = host => host === 'merchant.example'+ ? { allowed: true, needsPrompt: false }+ : { allowed: false, needsPrompt: true };+ agent.permissions.record = async () => { };+ agent._promptPermission = async (_tabId, capability, host) => {+ state.prompts.push({ capability, host });+ return choice;+ };+ agent._inputReceivingFrameUrl = async (_tabId, name) => {+ state.resolved.push(name);+ return frameUrls.length > 1 ? frameUrls.shift() : frameUrls[0];+ };+ agent.executeTool = async (_tabId, name) => {+ state.executed.push(name);+ return { success: true };+ };+ return { agent, state };+}++const RECEIVING_FRAME_CALLS = [+ ['click', { x: 120, y: 80, coordinate_space: 'css' }, 'click'],+ ['type_text', { text: '4242 4242 4242 4242' }, 'type'],+ ['press_keys', { key: 'Enter' }, 'click'],+];++test('Chrome point and focus input is charged to the embedded frame it reaches', async () => {+ for (const [name, args, capability] of RECEIVING_FRAME_CALLS) {+ const { agent, state } = receivingFrameGateAgent(AgentCh, 5121, { frameUrls: ['https://wallet.example/pay'] });+ const messages = [];+ await agent._executeToolBatch(5121, [{ id: `frame_${name}`, function: { name, arguments: JSON.stringify(args) } }],+ messages, () => { }, { supportsVision: false }, '', new Set([name]), 1);+ assert.deepEqual(state.resolved, [name], `${name}: the receiving frame was not resolved before the gate`);+ assert.deepEqual(state.prompts, [{ capability, host: 'wallet.example' }], `${name}: the merchant grant covered the wallet frame`);+ assert.deepEqual(state.executed, [], `${name}: input reached the wallet frame without its permission`);+ assert.match(JSON.parse(messages[0].content).error, /denied permission to .* wallet\.example/, name);+ }+});++test('Chrome point and focus input stays on the page grant while it reaches the top document', async () => {+ for (const [name, args] of RECEIVING_FRAME_CALLS) {+ const { agent, state } = receivingFrameGateAgent(AgentCh, 5122, { frameUrls: ['https://merchant.example/checkout'] });+ await agent._executeToolBatch(5122, [{ id: `top_${name}`, function: { name, arguments: JSON.stringify(args) } }],+ [], () => { }, { supportsVision: false }, '', new Set([name]), 1);+ assert.deepEqual(state.prompts, [], `${name}: a top-document input asked again`);+ assert.deepEqual(state.executed, [name], `${name}: a top-document input did not run`);+ }+});++test('Chrome point and focus input fails closed when its receiving document is unknown', async () => {+ for (const [name, args] of RECEIVING_FRAME_CALLS) {+ const { agent, state } = receivingFrameGateAgent(AgentCh, 5123, { frameUrls: [''] });+ const messages = [];+ await agent._executeToolBatch(5123, [{ id: `unknown_${name}`, function: { name, arguments: JSON.stringify(args) } }],+ messages, () => { }, { supportsVision: false }, '', new Set([name]), 1);+ assert.deepEqual(state.prompts, [], `${name}: an unidentified frame must not borrow a prompt or the page grant`);+ assert.deepEqual(state.executed, [], `${name}: input ran without an identified receiving document`);+ const result = JSON.parse(messages[0].content);+ assert.equal(result.denied, true, name);+ assert.match(result.error, /could not identify the site of the document/, name);+ }+});++test('Chrome point and focus input is not sent when its document changed while the card was open', async () => {+ for (const [name, args] of RECEIVING_FRAME_CALLS) {+ const { agent, state } = receivingFrameGateAgent(AgentCh, 5124, {+ frameUrls: ['https://wallet.example/pay', 'https://attacker.example/'],+ choice: 'once',+ });+ const messages = [];+ await agent._executeToolBatch(5124, [{ id: `moved_${name}`, function: { name, arguments: JSON.stringify(args) } }],+ messages, () => { }, { supportsVision: false }, '', new Set([name]), 1);+ assert.equal(state.prompts.length, 1, name);+ assert.deepEqual(state.resolved, [name, name], `${name}: the receiver was not checked again after the card`);+ assert.deepEqual(state.executed, [], `${name}: input followed the page into a document the user was not asked about`);+ assert.match(JSON.parse(messages[0].content).error, /changed to one on attacker\.example/, name);+ }+});++test('Firefox point and focus input is charged to the top document it stays in', async () => {+ for (const [name, args] of RECEIVING_FRAME_CALLS) {+ const { agent, state } = receivingFrameGateAgent(AgentFx, 5125);+ await agent._executeToolBatch(5125, [{ id: `fx_${name}`, function: { name, arguments: JSON.stringify(args) } }],+ [], () => { }, { supportsVision: false }, '', new Set([name]), 1);+ assert.deepEqual(state.resolved, [], `${name}: Firefox has no CDP receiving-frame resolver`);+ assert.deepEqual(state.prompts, [], name);+ assert.deepEqual(state.executed, [name], name);+ }+});+test('form validation classifier surfaces native and custom submission errors', () => {const url = 'https://addons.mozilla.org/en-US/developers/addon/webbrain/versions/submit/';const invalidField = {@@ -113508,6 +113614,33 @@ test('hostForCapability: navigate/network use target URL, others use current pagassert.equal(hostForCapability(Capability.NAVIGATE, { steps: 2 }, 'https://cur.com', 'go_forward'), 'cur.com');});+test('point and focus input is charged to its receiving document, failing closed without one', () => {+ for (const [label, Cap, reqHosts] of [['firefox', Capability, requiredHosts], ['chrome', CapabilityCh, requiredHostsCh]]) {+ const page = 'https://merchant.example/checkout';+ const wallet = { _inputFrameUrl: 'https://wallet.example/pay' };+ for (const [name, args, capability] of [+ ['click', { x: 10, y: 20, ...wallet }, Cap.CLICK],+ ['type_text', { text: '4242', ...wallet }, Cap.TYPE],+ ['press_keys', { key: 'Enter', ...wallet }, Cap.CLICK],+ ]) {+ assert.deepEqual(reqHosts(capability, args, page, name), ['wallet.example'], `${label}: ${name}`);+ // No receiving document: never fall back to the page's grant.+ const { _inputFrameUrl, ...unresolved } = args;+ assert.deepEqual(reqHosts(capability, unresolved, page, name), [], `${label}: ${name} without a receiver`);+ assert.deepEqual(reqHosts(capability, { ...args, _inputFrameUrl: '' }, page, name), [], `${label}: ${name} with an opaque receiver`);+ }+ // An element WebBrain resolved itself keeps the page host.+ for (const [name, args, capability] of [+ ['click', { selector: '#pay', ...wallet }, Cap.CLICK],+ ['click', { ref_id: 'ref_4', ...wallet }, Cap.CLICK],+ ['type_text', { selector: '#card', text: '4242', ...wallet }, Cap.TYPE],+ ['type_ax', { ref_id: 'ref_5', text: '4242', ...wallet }, Cap.TYPE],+ ]) {+ assert.deepEqual(reqHosts(capability, args, page, name), ['merchant.example'], `${label}: ${name} ${JSON.stringify(args)}`);+ }+ }+});+test('generate_image permission and result trust are bound to the configured provider in both builds', () => {for (const [label, Cap, hostFor, reqHosts, untrustedTools] of [['firefox', Capability, hostForCapability, requiredHosts, UNTRUSTED_CONTENT_TOOLS],