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
Post on another site after a correction; answer leave prompts after a chrome:// start
Claude59f2ea0b3872
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex df38ad501..c1027b8e9 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -7,6 +7,8 @@ This changelog was generated from the repository Git history and release tags. V## [Unreleased]### Fixed+- Posting on another site after a correction: after a Mastodon post, "ok now on X" no longer leaves WebBrain going back and forth between the two sites, typing the X post again each time. It counted X as the same platform as Mastodon, because it reads account names only on X and Bluesky, and asked to find the Mastodon post on X itself, which can never happen. The site a post was made on now names its platform when no account name was read, so the X post goes ahead once the earlier post's result is known. A post on the same site still has to find the earlier one first, and x.com and twitter.com are one platform.+- Chrome: a page's "Leave site?" prompt no longer waits for you when WebBrain navigates away during a task that started on a page the debugger cannot attach to, such as chrome://extensions, or whose debugger connection dropped. WebBrain arms its dialog handling again at the next debugger attach and around each of its own navigations, and answers Leave for its own navigation as it already did on other runs. If you cancel the debugger, prompts stay yours to answer. Firefox offers extensions no way to answer these prompts.- Chat sites such as WhatsApp: a request that points at the open chat instead of naming the person, such as "send some test messages to this one" or "message this user", now sends there instead of asking "which contact, and what text?". The planner never sees the page, and its rules counted only words like "reply here" as the open chat, so it asked the same question every time without reading the page. WebBrain still reads the open chat's header itself and binds every send to that one contact, and stops if no single chat is open. The planner is also told it cannot see the page, no longer reads a note about a screenshot it is never given, and leaves the wording of described messages, such as test messages or a thank-you, to the agent. One request can now cover the open chat and someone named besides it, as in "test messages here, then thank Rustem Bey": the open chat needs no confirmation, the reviewed plan shows the named person, and that person is confirmed once on WebBrain's card before the first send to them. Words that refer back to someone named earlier still mean that person, and on mail sites the people named besides "reply here" are handled as before. On WhatsApp, where a contact is confirmed through its contact drawer, one run still confirms only one chat's contact, so the second chat of such a request needs a request of its own; the agent is now told so, instead of being sent to re-read the page and retry.- A subscription, registration or sign-in wall in front of a news article is now recognized in any language, by a model reading the wall's text once, instead of only when it used English phrases such as "Subscribe to continue reading". A Turkish "Okumaya devam etmek için abone olun" overlay now keeps WebBrain from reading the article hidden behind it, as an English one did, while an offer to subscribe beside text you can still read is not taken for a wall. A wall inside the article is found also after a long preview, and everything after the wall's text stays withheld; the preview before it stays readable, except the short passage just before the wall's text. If a page cannot be read again after its wall was recognized, the read fails rather than return what the wall hides. A wall whose number changes on every read, such as a countdown, stays a wall while its new text is read, and needs no more readings once two of its numbers were read as the wall, while a count that stops being a wall when its number changes reads as what it is once read; a wall whose other text keeps changing makes the read fail rather than leak, and the agent may read the page once more in case the wall went away.- A dialog asking you to prove you are human now pauses the run's page actions in any language, not only when it says "Security verification", "Verify you are human" or another English phrase. Its title is read by a model once, the decision model first; LinkedIn's Turkish "Güvenlik doğrulaması" now counts, while a cookie notice or a form dialog does not. A dialog naming a CAPTCHA product still counts without any reading. A title no model can answer stops nothing and is asked about again only after half a minute, so page actions do not each wait for it.diff --git a/docs/architecture.md b/docs/architecture.mdindex e3e925315..97d231a67 100644--- a/docs/architecture.md+++ b/docs/architecture.md@@ -97,7 +97,12 @@ correction, searches and in-form toggles need no reconciliation. A form withoutrecord identity is bound by its action and values: an identical resubmission isreported as already made, a corrected in-place save needs the observed earlierresult and authorization under the latest request, and a different target-(another form or platform) needs a known earlier outcome. Whether a correction+(another form or platform) needs a known earlier outcome. Account names, read+on X and Bluesky only, name a post's platform; a post or form anywhere else,+such as Mastodon, is named by the site it was made on, so "ok now on X" after a+Mastodon post is a post on another platform and is never sent to look for the+Mastodon post on X. Hosts that share their last two labels count as one site,+and x.com and twitter.com as one platform. Whether a correctionasks to delete the earlier post or record first is a fixed-choice questionthat a model answers from the correction as the user wrote it, in any language(see "Language decisions" below): removing characters, words or hashtags from a@@ -1242,6 +1247,11 @@ Other navigation warnings choose Stay. Dialog text is never treated as instructiThe handler runs independently of blocked page commands and is removed onStop, completion, or detach, even when Dev diagnostics retain the debugger.+A run whose start page the debugger cannot attach to, such as+chrome://extensions, or whose debugger connection drops, keeps its wish to+answer dialogs: the next debugger attach arms it, and each navigation and+history navigation arms it before dispatch and again on the page it reaches.+The person cancelling the debugger ends it for the run.Ask mode and idle tabs do not auto-answer dialogs. Already-observed dialogs areresolved before startup commands. Dialogs opened before debugger attachmentmay need manual dismissal. Startup responds to Stop and times out after fivediff --git a/package.json b/package.jsonindex 419331b33..5dc8716de 100644--- a/package.json+++ b/package.json@@ -59,7 +59,7 @@"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: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/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-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/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/trusted-field-preparation.mjs test/draftjs-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/permission-steering-wakeup.mjs test/pure-calculation-reply.mjs test/pure-calculation-tools.mjs test/page-feedback.mjs test/page-feedback-progress.mjs test/ask-response-scope.mjs test/ask-completion-churn.mjs test/page-feedback-policy.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/completion-current-execution-evidence.mjs test/monitor-intervention-contract.mjs test/monitor-owned-geometry.mjs test/monitor-viewport-remainder.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/lifecycle-planner-digest.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/workflow-native-targets.mjs test/native-whatsapp-chat.mjs test/native-chat-context-identity.mjs test/native-whatsapp-contact.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/page-monitor-ui.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/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/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-deletion-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/anchored-action-mv3.mjs && node test/quality/inline-social-composer-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: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/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-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/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/trusted-field-preparation.mjs test/draftjs-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/permission-steering-wakeup.mjs test/pure-calculation-reply.mjs test/pure-calculation-tools.mjs test/page-feedback.mjs test/page-feedback-progress.mjs test/ask-response-scope.mjs test/ask-completion-churn.mjs test/page-feedback-policy.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/completion-current-execution-evidence.mjs test/monitor-intervention-contract.mjs test/monitor-owned-geometry.mjs test/monitor-viewport-remainder.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/lifecycle-planner-digest.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/workflow-native-targets.mjs test/native-whatsapp-chat.mjs test/native-chat-context-identity.mjs test/native-whatsapp-contact.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/page-monitor-ui.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/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/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-deletion-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/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/draftjs-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/ask-response-scope.mjs test/ask-completion-churn.mjs test/page-feedback-policy.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/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-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-dispatch-boundary.mjs && node test/message-recipient-upload.mjs && node test/message-recipient-clarify-binding.mjs && node --test test/message-recipient-whatsapp.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",@@ -95,7 +95,7 @@"test:shard:browser-a": "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/workflow-native-targets.mjs test/native-whatsapp-chat.mjs test/native-chat-context-identity.mjs test/native-whatsapp-contact.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/recipient-confirmation-ui.mjs test/assistant-message-visibility-ui.mjs test/page-monitor-ui.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/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-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-dispatch-boundary.mjs test/delivery-stop-compound.mjs test/guards-control-classification.mjs test/guards-unbound-deletion.mjs test/submit-probe-readings.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/literal-calculate-midrun-mv3.mjs && node test/quality/ask-completion-churn-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/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",- "test:shard:browser-c": "node test/quality/literal-frame-mv3.mjs && node test/quality/mastodon-publication-mv3.mjs && node test/quality/mastodon-deletion-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/anchored-action-mv3.mjs && node test/quality/inline-social-composer-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:shard:browser-c": "node test/quality/literal-frame-mv3.mjs && node test/quality/mastodon-publication-mv3.mjs && node test/quality/mastodon-deletion-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/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:shard:tail": "node test/run.js && node test/selection-scope-restoration.mjs && node scripts/benchmark-offline-relevance.mjs && npm run test:security","test:composer-context": "node --test test/page-monitor-inline-post.mjs test/bluesky-composer-context.mjs && node test/quality/inline-social-composer-mv3.mjs && node test/quality/bluesky-composer-mv3.mjs","test:bot-memory": "node --test test/bot-memory.mjs test/bot-memory-registries.mjs test/bot-memory-cloud-controller.mjs && node test/bot-memory-dom.mjs && node test/quality/cloud-bot-memory-mv3.mjs",diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex 61c92e72f..1a6e9f9a3 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -5730,6 +5730,20 @@ export class Agent extends LoopDetector {: !!subject.resourceUrl && entry.resourceUrl === subject.resourceUrl)) || null;}+ // The platform a post or form belongs to, named by the site it was made on:+ // X and Bluesky as their account identities name them, any other site by the+ // last two labels of its host. Hosts that share them count as one site, so+ // an unfamiliar subdomain never makes a post on the same site look like one+ // on another platform. No usable address names no platform.+ _publicationSiteOf(url) {+ let host = '';+ try { host = new URL(String(url || '')).hostname.toLowerCase().replace(/\.$/, ''); } catch { return ''; }+ const labels = host.split('.').filter(Boolean);+ if (labels.length < 2 || labels.every(label => /^\d+$/.test(label))) return host;+ const site = labels.slice(-2).join('.');+ return site === 'x.com' || site === 'twitter.com' ? 'twitter' : site === 'bsky.app' ? 'bluesky' : site;+ }+async _resourceMutationPreSubmitBlock(tabId, name, args, detected, provider = this._activeProvider(tabId)) {const guard = this._planExecutionGuards.get(tabId);const deletion = detected?.mutationKind === 'delete';@@ -5768,10 +5782,14 @@ export class Agent extends LoopDetector {const priorSnapshot = prior?.publicationSnapshot || prior?.workflowBinding?.socialPublication?.snapshot;// An account belongs to its platform's namespace. A post on another// platform is a separate publication bound to its own contract action,- // not a replacement of the earlier post under a changed account.+ // not a replacement of the earlier post under a changed account. Account+ // names are read on X and Bluesky only; for a post or form anywhere else,+ // such as Mastodon, the site it was made on names its platform, so a post+ // on another site is never sent to look for the earlier one on its own page.const platformOf = account => String(account || '').split(':')[0];- const crossPlatform = publication && !!priorSnapshot?.account && !!detected.publicationSnapshot?.account- && platformOf(priorSnapshot.account) !== platformOf(detected.publicationSnapshot.account);+ const priorPlatform = platformOf(priorSnapshot?.account) || this._publicationSiteOf(prior?.originatingUrl || prior?.currentUrl);+ const currentPlatform = platformOf(detected.publicationSnapshot?.account) || this._publicationSiteOf(detected.url);+ const crossPlatform = publication && !!priorPlatform && !!currentPlatform && priorPlatform !== currentPlatform;if (publication && priorSnapshot?.account && detected.publicationSnapshot?.account !== priorSnapshot.account && !crossPlatform) {const account = String(detected.publicationSnapshot?.account || '').split(':').slice(1).join(':');if (!account || !latest.toLowerCase().includes(account.toLowerCase())) return blocked('replacement_account_changed');@@ -5860,9 +5878,10 @@ export class Agent extends LoopDetector {&& this._steeringPriorEffectObserved(tabId, prior)) observedKind = 'form_observation';}if (prior.dispatched !== true || (matching.length !== 1 && !deletedVerifiedResource && !observedKind)) {+ const priorHost = (() => { try { return new URL(prior.originatingUrl || prior.currentUrl || '').hostname; } catch { return ''; } })();return blocked('prior_effect_unreconciled', publication && !crossPlatform? 'The earlier post from before the latest correction has not been matched yet. Read it on this platform (its permalink or the account\'s recent posts), then retry; do not repeat an uncertain publication.'- : 'The earlier submission from before the latest correction has not been observed yet. Read the page that shows its result, then retry; do not repeat an uncertain mutation.');+ : `The earlier submission from before the latest correction${crossPlatform && priorHost ? `, on ${priorHost},` : ''} has not been observed yet. Read the page that shows its result, then retry; do not repeat an uncertain mutation.`);}if (matching.length === 1 || deletedVerifiedResource) {guard.steeringPriorSubmissionReconciliation = { verified: true, verificationKind: 'resource_identity', taskKey: guard.taskKey,@@ -40019,6 +40038,10 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d};try {+ // The page's leave prompt is answered only through the run's debugger+ // connection: arm it again when the run started where none was+ // possible, such as chrome://extensions, or the connection dropped.+ await cdpClient.ensureDialogHandling(tabId);releaseDialogNavigation = cdpClient.authorizeNavigationDialog(tabId, beforeUrl, earlyCdpAbortSignal);await beforePageAgentDispatch(globalThis.chrome, tabId, { kind: 'navigate', url: rawUrl });await chrome.tabs.update(tabId, { url: rawUrl });@@ -40047,6 +40070,9 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d}}removeNavigationListener();+ // The page reached may raise its own dialogs. A run that could not arm+ // dialog handling on the page it left arms it on this one.+ await cdpClient.ensureDialogHandling(tabId);let finalUrl = rawUrl;let finalStatus = '';let readbackVerified = false;@@ -40225,6 +40251,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dtry {try {const delta = direction === 'back' ? -steps : steps;+ await cdpClient.ensureDialogHandling(tabId);await beforePageAgentDispatch(globalThis.chrome, tabId, { kind: 'navigate', history: true });historyDispatchArmed = true;dispatched = true;@@ -40261,6 +40288,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d}}removeNavigationListeners();+ await cdpClient.ensureDialogHandling(tabId);let afterUrl = navigationWaitResult.url || probe.before;let finalStatus = '';diff --git a/src/chrome/src/cdp/cdp-client.js b/src/chrome/src/cdp/cdp-client.jsindex d791c42d8..f4e332b0c 100644--- a/src/chrome/src/cdp/cdp-client.js+++ b/src/chrome/src/cdp/cdp-client.js@@ -494,6 +494,7 @@ export class CDPClient {this.runtimeContexts = new Map(); // tabId -> session/context key -> default contextthis.pendingDialogs = new Map(); // tabId -> sessionId -> current native dialogthis.dialogRuns = new Map(); // tabId -> active action-run owner+ this.dialogIntents = new Map(); // tabId -> the run's wish to answer dialogs, across debugger connectionsthis.fileChooserGuards = new Map(); // tabId -> temporary protocol interceptionthis._debuggerListenersRegistered = false;this._onDebuggerEvent = (source, method, params) => {@@ -523,7 +524,11 @@ export class CDPClient {pendingAttach.detached = true;this.attachGenerations.set(tabId, (this.attachGenerations.get(tabId) || 0) + 1);}- this.stopDialogHandling(tabId);+ // A dropped connection ends this connection's dialog handling but not+ // the run's: the next attach or navigation arms it again. The person+ // cancelling the debugger ends it for the run.+ if (reason === 'canceled_by_user') this.stopDialogHandling(tabId);+ else this._disarmDialogHandling(tabId);this.pendingDialogs.delete(tabId);this._dropWebMCPSession(tabId, `Debugger detached: ${reason || 'unknown reason'}`);this.sessions.delete(tabId);@@ -654,7 +659,9 @@ export class CDPClient {});this.attachPromises.set(tabId, attachPromise);try {- return await attachPromise;+ const session = await attachPromise;+ this._resumeDialogHandling(tabId);+ return session;} finally {if (this.attachPromises.get(tabId) === attachPromise) {this.attachPromises.delete(tabId);@@ -724,16 +731,42 @@ export class CDPClient {/** Native dialogs pause renderer commands, so resolve them from the debugger* event callback rather than queuing behind the click/evaluate they blocked.* Firefox has no equivalent WebExtension API; never patch page JS to fake it.+ *+ * A run's wish to answer dialogs outlives one debugger connection. A run+ * that starts where the debugger cannot attach, such as chrome://extensions,+ * or whose connection drops, is armed again at its next debugger attach and+ * whenever ensureDialogHandling is asked before a navigation, so a page's+ * leave prompt never waits for the person while WebBrain works. Stop, abort,+ * the run's end and the person cancelling the debugger end that wish.*/async startDialogHandling(tabId, { signal, onHandled, timeoutMs = 5000 } = {}) {this.stopDialogHandling(tabId);if (signal?.aborted) return;- const owner = { signal, onHandled };+ const intent = { signal, onHandled, timeoutMs };+ intent.onAbort = () => {+ if (this.dialogIntents.get(tabId) === intent) this.stopDialogHandling(tabId);+ };+ this.dialogIntents.set(tabId, intent);+ signal?.addEventListener('abort', intent.onAbort, { once: true });+ return this._armDialogHandling(tabId, intent);+ }++ // Arms the run's dialog handling on the tab's current debugger connection.+ // A failure leaves the run's wish in place for a later connection.+ _armDialogHandling(tabId, intent) {+ this._disarmDialogHandling(tabId);+ if (intent.signal?.aborted || this.dialogIntents.get(tabId) !== intent) return Promise.resolve();+ const owner = { signal: intent.signal, onHandled: intent.onHandled };owner.onAbort = () => {if (this.dialogRuns.get(tabId) === owner) this.stopDialogHandling(tabId);};this.dialogRuns.set(tabId, owner);- signal?.addEventListener('abort', owner.onAbort, { once: true });+ owner.signal?.addEventListener('abort', owner.onAbort, { once: true });+ owner.arming = this._armDialogOwner(tabId, owner, intent.timeoutMs ?? 5000);+ return owner.arming;+ }++ async _armDialogOwner(tabId, owner, timeoutMs) {let timer;const markPendingAttachCancelled = () => {const pendingAttach = this.attachPromises.get(tabId);@@ -770,7 +803,7 @@ export class CDPClient {} catch (error) {if (error?.code === 'page_feedback_pending') throw error;markPendingAttachCancelled();- if (this.dialogRuns.get(tabId) === owner) this.stopDialogHandling(tabId);+ if (this.dialogRuns.get(tabId) === owner) this._disarmDialogHandling(tabId);throw error;} finally {clearTimeout(timer);@@ -778,7 +811,39 @@ export class CDPClient {}}+ /**+ * Makes sure the run's dialog handling is armed on this tab before an+ * action that can raise a dialog, such as a navigation that may meet a+ * leave prompt. Resolves whether it is armed; never throws, so a page the+ * debugger cannot reach still navigates.+ */+ async ensureDialogHandling(tabId) {+ const intent = this.dialogIntents.get(tabId);+ if (!intent || intent.signal?.aborted) return false;+ const owner = this.dialogRuns.get(tabId);+ try {+ if (owner) await owner.arming;+ else await this._armDialogHandling(tabId, intent);+ } catch {}+ return this.dialogIntents.get(tabId) === intent && this.dialogRuns.has(tabId);+ }++ // A fresh debugger connection resumes the dialog handling its run could not+ // arm at its start, or that a dropped connection ended.+ _resumeDialogHandling(tabId) {+ const intent = this.dialogIntents.get(tabId);+ if (!intent || intent.signal?.aborted || this.dialogRuns.has(tabId)) return;+ this._armDialogHandling(tabId, intent).catch(() => {});+ }+stopDialogHandling(tabId) {+ const intent = this.dialogIntents.get(tabId);+ intent?.signal?.removeEventListener('abort', intent.onAbort);+ this.dialogIntents.delete(tabId);+ this._disarmDialogHandling(tabId);+ }++ _disarmDialogHandling(tabId) {const owner = this.dialogRuns.get(tabId);owner?.navigation?.release();owner?.cancelStartup?.();diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex 6d8986d15..9653fe68c 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -5403,6 +5403,20 @@ export class Agent extends LoopDetector {: !!subject.resourceUrl && entry.resourceUrl === subject.resourceUrl)) || null;}+ // The platform a post or form belongs to, named by the site it was made on:+ // X and Bluesky as their account identities name them, any other site by the+ // last two labels of its host. Hosts that share them count as one site, so+ // an unfamiliar subdomain never makes a post on the same site look like one+ // on another platform. No usable address names no platform.+ _publicationSiteOf(url) {+ let host = '';+ try { host = new URL(String(url || '')).hostname.toLowerCase().replace(/\.$/, ''); } catch { return ''; }+ const labels = host.split('.').filter(Boolean);+ if (labels.length < 2 || labels.every(label => /^\d+$/.test(label))) return host;+ const site = labels.slice(-2).join('.');+ return site === 'x.com' || site === 'twitter.com' ? 'twitter' : site === 'bsky.app' ? 'bluesky' : site;+ }+async _resourceMutationPreSubmitBlock(tabId, name, args, detected, provider = this._activeProvider(tabId)) {const guard = this._planExecutionGuards.get(tabId);const deletion = detected?.mutationKind === 'delete';@@ -5441,10 +5455,14 @@ export class Agent extends LoopDetector {const priorSnapshot = prior?.publicationSnapshot || prior?.workflowBinding?.socialPublication?.snapshot;// An account belongs to its platform's namespace. A post on another// platform is a separate publication bound to its own contract action,- // not a replacement of the earlier post under a changed account.+ // not a replacement of the earlier post under a changed account. Account+ // names are read on X and Bluesky only; for a post or form anywhere else,+ // such as Mastodon, the site it was made on names its platform, so a post+ // on another site is never sent to look for the earlier one on its own page.const platformOf = account => String(account || '').split(':')[0];- const crossPlatform = publication && !!priorSnapshot?.account && !!detected.publicationSnapshot?.account- && platformOf(priorSnapshot.account) !== platformOf(detected.publicationSnapshot.account);+ const priorPlatform = platformOf(priorSnapshot?.account) || this._publicationSiteOf(prior?.originatingUrl || prior?.currentUrl);+ const currentPlatform = platformOf(detected.publicationSnapshot?.account) || this._publicationSiteOf(detected.url);+ const crossPlatform = publication && !!priorPlatform && !!currentPlatform && priorPlatform !== currentPlatform;if (publication && priorSnapshot?.account && detected.publicationSnapshot?.account !== priorSnapshot.account && !crossPlatform) {const account = String(detected.publicationSnapshot?.account || '').split(':').slice(1).join(':');if (!account || !latest.toLowerCase().includes(account.toLowerCase())) return blocked('replacement_account_changed');@@ -5533,9 +5551,10 @@ export class Agent extends LoopDetector {&& this._steeringPriorEffectObserved(tabId, prior)) observedKind = 'form_observation';}if (prior.dispatched !== true || (matching.length !== 1 && !deletedVerifiedResource && !observedKind)) {+ const priorHost = (() => { try { return new URL(prior.originatingUrl || prior.currentUrl || '').hostname; } catch { return ''; } })();return blocked('prior_effect_unreconciled', publication && !crossPlatform? 'The earlier post from before the latest correction has not been matched yet. Read it on this platform (its permalink or the account\'s recent posts), then retry; do not repeat an uncertain publication.'- : 'The earlier submission from before the latest correction has not been observed yet. Read the page that shows its result, then retry; do not repeat an uncertain mutation.');+ : `The earlier submission from before the latest correction${crossPlatform && priorHost ? `, on ${priorHost},` : ''} has not been observed yet. Read the page that shows its result, then retry; do not repeat an uncertain mutation.`);}if (matching.length === 1 || deletedVerifiedResource) {guard.steeringPriorSubmissionReconciliation = { verified: true, verificationKind: 'resource_identity', taskKey: guard.taskKey,diff --git a/test/browser-dialogs.mjs b/test/browser-dialogs.mjsindex a636248c5..ba034de08 100644--- a/test/browser-dialogs.mjs+++ b/test/browser-dialogs.mjs@@ -479,3 +479,170 @@ test('go_back authorizes beforeunload for the current page and cleans up on compelse globalThis.browser = previousBrowser;}});++// Your trace: a run that started on chrome://extensions, where the debugger+// cannot attach, left every later "Leave site?" prompt for the person to+// answer, the first one for 70 seconds. The run's dialog handling is armed+// again once it can be: before and after its own navigations, and at any+// later debugger attach.+function navigationFixture(tabId, startUrl) {+ const area = { get: async () => ({}), set: async () => {}, remove: async () => {} };+ const event = () => {+ const listeners = new Set();+ return { addListener: fn => listeners.add(fn), removeListener: fn => listeners.delete(fn),+ emit: (...args) => [...listeners].forEach(fn => fn(...args)) };+ };+ const events = { committed: event(), errors: event(), updated: event() };+ const state = { url: startUrl, leavePrompt: false, calls: [] };+ state.answers = () => state.calls.filter(call => call[1] === 'Page.handleJavaScriptDialog').map(call => call[2]);+ state.chrome = {+ storage: { local: area, session: area }, runtime: { getURL: value => value },+ tabs: {+ get: async id => ({ id, url: state.url, status: 'complete' }),+ onUpdated: events.updated,+ // A page with an unsent draft asks before it is left. The browser+ // leaves only once the prompt is answered with Leave.+ update: async (_id, { url }) => {+ if (state.leavePrompt) {+ const before = state.answers().length;+ state.client._onDebuggerEvent({ tabId }, 'Page.javascriptDialogOpening', { type: 'beforeunload', url: state.url });+ await new Promise(resolve => setTimeout(resolve, 0));+ const answer = state.answers()[before];+ // An unanswered prompt waits for the person; here it is closed+ // unanswered, so the page stays.+ state.client._onDebuggerEvent({ tabId }, 'Page.javascriptDialogClosed', {});+ if (!answer?.accept) return {};+ }+ state.url = url;+ events.committed.emit({ tabId, frameId: 0, url });+ return {};+ },+ },+ webNavigation: { onCommitted: events.committed, onErrorOccurred: events.errors },+ scripting: { executeScript: async () => [{ result: { attachedFiles: 0, dirtyFields: 0 } }] },+ };+ return state;+}++async function withNavigationFixture(tabId, startUrl, body) {+ const previousChrome = globalThis.chrome, previousBrowser = globalThis.browser;+ delete globalThis.browser;+ const state = navigationFixture(tabId, startUrl);+ globalThis.chrome = state.chrome;+ const { Agent } = await import('../src/chrome/src/agent/agent.js');+ const { cdpClient } = await import('../src/chrome/src/cdp/cdp-client.js');+ state.client = cdpClient;+ const originalAttach = cdpClient.attach, originalSend = cdpClient.sendCommand;+ try {+ // The debugger cannot attach to chrome:// pages.+ cdpClient.attach = async id => {+ if (/^chrome:/.test(state.url)) throw new Error('Cannot access a chrome:// URL');+ cdpClient.sessions.set(id, { tabId: id });+ return cdpClient.sessions.get(id);+ };+ cdpClient.sendCommand = async (...args) => { state.calls.push(args); return {}; };+ await body({ state, cdpClient, agent: new Agent({ getActive: () => ({ promptTier: 'full' }) }) });+ } finally {+ cdpClient.stopDialogHandling(tabId);+ cdpClient.sessions.delete(tabId);+ cdpClient.attach = originalAttach;+ cdpClient.sendCommand = originalSend;+ globalThis.chrome = previousChrome;+ if (previousBrowser === undefined) delete globalThis.browser;+ else globalThis.browser = previousBrowser;+ }+}++test('a run that starts where the debugger cannot attach answers its leave prompts once it reaches a page', async () => {+ const tabId = 4301;+ await withNavigationFixture(tabId, 'chrome://extensions/', async ({ state, cdpClient, agent }) => {+ await assert.rejects(cdpClient.startDialogHandling(tabId), /chrome:\/\//);+ assert.equal(cdpClient.dialogRuns.has(tabId), false, 'Nothing is armed on chrome://extensions');+ const arrived = await agent.executeTool(tabId, 'navigate', { url: 'https://mastoturk.org/publish' });+ assert.equal(arrived.success, true, arrived.error);+ assert.equal(cdpClient.dialogRuns.has(tabId), true, 'The first page the debugger can reach arms the run');+ state.leavePrompt = true;+ const left = await agent.executeTool(tabId, 'navigate', { url: 'https://x.com/home' });+ assert.equal(left.success, true, left.error);+ assert.deepEqual(state.answers(), [{ accept: true }], 'WebBrain answered Leave for its own navigation');+ assert.equal(state.url, 'https://x.com/home');+ // Once the run ends, a page's leave prompt is the person's again.+ cdpClient.stopDialogHandling(tabId);+ const after = await agent.executeTool(tabId, 'navigate', { url: 'https://mastoturk.org/home' });+ assert.equal(after.success, false);+ assert.equal(after.confirmationPossible, true);+ assert.deepEqual(state.answers(), [{ accept: true }], 'No answer after the run ended');+ });+});++for (const reason of ['target_closed', 'canceled_by_user']) {+ test(`a debugger connection that drops (${reason}) ${reason === 'canceled_by_user' ? 'stays off once the person cancelled it' : 'is armed again for the next navigation'}`, async () => {+ const tabId = reason === 'target_closed' ? 4302 : 4303;+ await withNavigationFixture(tabId, 'https://x.com/home', async ({ state, cdpClient, agent }) => {+ await cdpClient.startDialogHandling(tabId);+ assert.equal(cdpClient.dialogRuns.has(tabId), true);+ cdpClient._onDebuggerDetach({ tabId }, reason);+ assert.equal(cdpClient.dialogRuns.has(tabId), false);+ state.leavePrompt = true;+ const left = await agent.executeTool(tabId, 'navigate', { url: 'https://mastoturk.org/home' });+ if (reason === 'target_closed') {+ assert.equal(left.success, true, left.error);+ assert.deepEqual(state.answers(), [{ accept: true }]);+ } else {+ assert.equal(left.success, false);+ assert.deepEqual(state.answers(), [], 'The person who cancelled the debugger answers the prompt');+ assert.equal(cdpClient.dialogRuns.has(tabId), false);+ }+ });+ });+}++test('any later debugger attach arms the dialog handling its run could not arm at its start', async () => {+ const previousChrome = globalThis.chrome;+ const sent = [];+ let attaches = 0, eventListener = null;+ globalThis.chrome = {+ runtime: { getURL: value => value, lastError: undefined },+ debugger: {+ attach: (_target, _version, callback) => {+ const attempt = ++attaches;+ setTimeout(() => {+ // The run starts on chrome://extensions; a later page allows it.+ if (attempt === 1) globalThis.chrome.runtime.lastError = { message: 'Cannot access a chrome:// URL' };+ callback();+ globalThis.chrome.runtime.lastError = undefined;+ }, 0);+ },+ detach: (_target, callback) => callback?.(),+ sendCommand: (_target, method, params, callback) => { sent.push([method, params]); callback({}); },+ onEvent: { addListener: fn => { eventListener = fn; }, removeListener: () => {} },+ onDetach: { addListener: () => {}, removeListener: () => {} },+ },+ };+ try {+ const client = new CDPClient();+ await assert.rejects(client.startDialogHandling(51), /chrome:\/\//);+ assert.equal(client.dialogRuns.has(51), false);+ // A page with no run is never armed by an attach.+ await client.attach(52);+ await tick();+ assert.equal(client.dialogRuns.has(52), false);+ // A CDP tool attaches on a page the debugger can reach.+ await client.attach(51);+ await tick();+ assert.equal(client.dialogRuns.has(51), true);+ assert.ok(sent.some(([method]) => method === 'Page.enable'));+ // The page's own question no longer waits for the person; it is refused.+ eventListener({ tabId: 51 }, 'Page.javascriptDialogOpening', { type: 'confirm', url: 'https://mastoturk.org/home' });+ await tick();+ assert.deepEqual(sent.filter(([method]) => method === 'Page.handleJavaScriptDialog').map(([, params]) => params), [{ accept: false }]);+ // Stop ends it: a later attach arms nothing.+ client.stopDialogHandling(51);+ client.sessions.delete(51);+ await client.attach(51);+ await tick();+ assert.equal(client.dialogRuns.has(51), false);+ } finally {+ globalThis.chrome = previousChrome;+ }+});diff --git a/test/guards-steering-receipts.mjs b/test/guards-steering-receipts.mjsindex 089e1be2d..dfb130170 100644--- a/test/guards-steering-receipts.mjs+++ b/test/guards-steering-receipts.mjs@@ -160,6 +160,67 @@ for (const build of ['chrome', 'firefox']) {}});+ // Your trace: a Mastodon post whose Publish click was delivered while the+ // page moved on, then "ok now on X". WebBrain reads account names only on+ // X and Bluesky, so the site each post is made on decides whether the+ // second post is on another platform.+ const mastodonCompose = { isSubmit: true, validationSubmitEvidence: 'strong', url: 'https://mastoturk.org/publish',+ host: 'mastoturk.org', formRef: 'ref_5', method: 'POST', actionUrl: '', frameDocumentIdentity: 'https://mastoturk.org/publish|1',+ fields: [{ label: 'Aklında ne var?', type: 'textarea', value: 'WebBrain test gönderisi' }] };+ const formOn = url => ({ ...mastodonCompose, url, host: new URL(url).hostname, frameDocumentIdentity: `${url}|1` });+ const publishOn = (url, account) => ({ ...publish(snap('WebBrain test post', account)), url, host: new URL(url).hostname });+ const deliveredUnobserved = { success: false, dispatched: true, outcomeUnknown: true, nativeInputAcknowledged: true };++ test(`${build}: a post on another site after a correction goes ahead once the earlier result is known, without an account reader there`, async () => {+ const cases = {+ // The trace itself, with the next automatic screenshot read after it.+ 'mastodon-then-x': { earlier: mastodonCompose, at: 'https://mastoturk.org/publish', read: true,+ now: publishOn('https://x.com/home', 'twitter:emresokullu'), allowed: true },+ // Nothing was read after the Mastodon click: its result is unknown.+ 'mastodon-unread': { earlier: mastodonCompose, at: 'https://mastoturk.org/publish', read: false,+ now: publishOn('https://x.com/home', 'twitter:emresokullu'), reason: 'prior_effect_unreconciled', guidance: /has not been observed yet/ },+ // An X post, then Bluesky whose account could not be read.+ 'x-then-bluesky': { earlierReceipt: true, read: true, now: publishOn('https://bsky.app/', ''), allowed: true },+ // The same platform stays the same, whatever the host is called.+ 'twitter-form-then-x': { earlier: formOn('https://mobile.twitter.com/settings/profile'), at: 'https://mobile.twitter.com/settings/profile',+ read: true, now: publishOn('https://x.com/home', 'twitter:alice'), reason: 'prior_effect_unreconciled', guidance: /on this platform/ },+ 'same-site-www': { earlier: formOn('https://www.mastoturk.org/publish'), at: 'https://www.mastoturk.org/publish', read: true,+ now: publishOn('https://mastoturk.org/publish', ''), reason: 'prior_effect_unreconciled', guidance: /on this platform/ },+ 'x-then-x-unread-account': { earlierReceipt: true, read: true, now: publishOn('https://x.com/home', ''), reason: 'replacement_account_changed' },+ };+ for (const [variant, spec] of Object.entries(cases)) {+ const h = await fixture('go to mastoturk.org and try to post something', { pageUrl: spec.now.url });+ try {+ // An X post's receipt, as the X tests above build it, carries its own+ // page read; the others are recorded the way a real click records them.+ if (spec.earlierReceipt) h.agent._completionSubmitStates.set(h.tab, structuredClone(publicationReceipt({ observed: spec.read })));+ else h.agent._recordCompletionSubmitAttempt(h.tab, spec.earlier, 'click_ax', { ref_id: 'ref_50' }, spec.at,+ spec.at.replace(/\/[^/]*$/, '/home'), deliveredUnobserved, 'earlier-doc', 'earlier-doc');+ const guard = await h.steer('ok now on X');+ assert.equal(guard.steeringPriorSubmission?.dispatched, true, variant);+ // The next page read, here the automatic screenshot after the+ // navigation, is what makes the earlier result known.+ if (spec.read && !spec.earlierReceipt) h.agent._recordCompletionToolResult(h.tab, 'auto_screenshot', {},+ { success: true, method: 'image_attach', _attachImage: true, pageUrl: spec.now.url });+ const blocked = await h.check(spec.now);+ if (spec.allowed) {+ assert.equal(blocked, null, `${variant}: ${blocked?.error}`);+ assert.equal(guard.steeringPriorSubmissionReconciliation.verificationKind, 'cross_platform', variant);+ assert.equal(guard.steeringPriorSubmissionReconciliation.resourceUrl, '', variant);+ assert.equal(h.audits.length, 1, variant);+ assert.equal(h.audits[0].input.action, 'publish', variant);+ assert.equal(h.steeringBlock(spec.now), null, `${variant}: the steering gate accepts the authorized post`);+ } else {+ assert.equal(blocked?.noDispatch, true, variant);+ assert.equal(blocked.actionGuard.reason, spec.reason, `${variant}: ${blocked.error}`);+ if (spec.guidance) assert.match(blocked.error, spec.guidance, variant);+ assert.equal(h.audits.length, 0, variant);+ assert.equal(h.steeringBlock(spec.now)?.noDispatch, true, variant);+ }+ } finally { h.close(); }+ }+ });+test(`${build}: an unchanged post under a revision reports the earlier publication instead of repeating it`, async () => {for (const variant of ['found-on-page', 'not-found', 'verified-outcome']) {const h = await fixture('Post "Hello world" on X.', { pageUrl: 'https://x.com/home' });diff --git a/test/quality/correction-cross-site-mv3.mjs b/test/quality/correction-cross-site-mv3.mjsnew file mode 100644index 000000000..e88435412--- /dev/null+++ b/test/quality/correction-cross-site-mv3.mjs@@ -0,0 +1,310 @@+import assert from 'node:assert/strict';+import fs from 'node:fs/promises';+import http from 'node:http';+import { createRequire } from 'node:module';+import os from 'node:os';+import path from 'node:path';+import { chromium } from 'playwright';+import { sharedGuardXHtml } from '../fixtures/shared-action-guards-x.mjs';+import { conformFixtureCompletionCall } from './completion-provider-contract.mjs';+import { fixedChoiceQuestion, fixtureFixedChoiceReply, fixturePageTextReply } from '../semantic-decision-stub.mjs';++// Your trace: "go to mastoturk.org and try to post something", the Mastodon+// post sent, then "ok now on X". Through the installed MV3 extension, with+// the run started on chrome://extensions as it was there:+// mastodon-then-x: the X post goes ahead once, instead of being held to+// find the Mastodon post on X while WebBrain went back and forth.+// leave-prompt: WebBrain leaves a page with an unsent draft, and the+// page's "Leave site?" prompt is answered by WebBrain for its own+// navigation instead of waiting for the person.+// Pages, posts and the model are owned local fixtures; nothing leaves the host.+const require = createRequire(import.meta.url);+const library = (name, file) => fs.readFile(path.join(path.dirname(require.resolve(`${name}/package.json`)), file), 'utf8');+const libraryFiles = [['react.js', 'react', 'umd/react.development.js'], ['react-dom.js', 'react-dom', 'umd/react-dom.development.js'],+ ['immutable.js', 'immutable', 'dist/immutable.js'], ['draft.js', 'draft-js', 'dist/Draft.js']];+const assets = new Map(await Promise.all(libraryFiles.map(async ([name, module, file]) => [name, await library(module, file)])));+const xHtml = sharedGuardXHtml({ account: 'ownedqa', draftCss: await library('draft-js', 'dist/Draft.css'), libraryFiles });+const mastodonCompose = `<!doctype html><meta charset="utf-8"><title>Yeni gönderi - MastoTurk</title>+<style>body{font:16px sans-serif;margin:24px} textarea{width:500px;height:120px} button{padding:10px 18px}</style>+<h1>Yeni gönderi</h1><form id="compose" action="/api/v1/statuses" method="post">+<textarea name="status" aria-label="Aklında ne var?" placeholder="Aklında ne var?"></textarea>+<p><button type="submit">Gönder</button></p></form>+<script>+document.querySelector('#compose').addEventListener('submit', async event => {+ event.preventDefault();+ const response = await fetch('/api/v1/statuses', { method: 'POST', headers: { 'Content-Type': 'application/json' },+ body: JSON.stringify({ status: document.querySelector('textarea').value }) });+ // Mastodon moves to the home timeline as soon as the post is accepted.+ if (response.ok) location.href = '/home';+});+</script>`;+const mastodonHome = posts => `<!doctype html><meta charset="utf-8"><title>Anasayfa - MastoTurk</title>+<h1>Anasayfa</h1><div role="feed" aria-label="Anasayfa">${posts.map((post, index) =>+ `<article aria-label="esokullu"><a href="/@esokullu/${1000 + index}">esokullu</a><p>${post.replace(/</g, '<')}</p></article>`).join('')}</div>`;+// X asks before a page with an unsent draft is left.+const leavePrompt = () => {+ if (location.hostname !== 'x.com') return;+ addEventListener('beforeunload', event => {+ if (document.querySelector('[data-testid="tweetTextarea_0"]')?.textContent.trim()) { event.preventDefault(); event.returnValue = ''; }+ });+};++const textOf = content => typeof content === 'string' ? content : Array.isArray(content)+ ? content.filter(part => part?.type === 'text').map(part => part.text || '').join('\n') : '';+function objectFrom(content) {+ const text = textOf(content);+ for (let start = text.indexOf('{'); start >= 0; start = text.indexOf('{', start + 1)) {+ let depth = 0, quoted = false, escaped = false;+ for (let index = start; index < text.length; index++) {+ const character = text[index];+ if (quoted) { if (escaped) escaped = false; else if (character === '\\') escaped = true; else if (character === '"') quoted = false; }+ else if (character === '"') quoted = true;+ else if (character === '{') depth++;+ else if (character === '}' && --depth === 0) {+ try { return JSON.parse(text.slice(start, index + 1)); } catch { break; }+ }+ }+ }+ return null;+}+const toolMessages = messages => {+ const names = new Map((messages || []).flatMap(message => (message.tool_calls || []).map(call => [call.id, call.function?.name])));+ return (messages || []).filter(message => message.role === 'tool')+ .map(message => ({ id: message.tool_call_id, name: names.get(message.tool_call_id), result: objectFrom(message.content) }));+};+const refFrom = (tree, pattern) => String(tree?.result?.pageContent || '').split('\n').find(line => pattern.test(line))?.match(/\[(ref_\d+)\]/)?.[1];++const request = 'go to mastoturk.org and try to post something';+const correction = 'ok now on X';+const variants = {+ 'mastodon-then-x': {+ before: [+ () => ({ name: 'navigate', args: { url: 'https://mastoturk.org/publish' } }),+ () => ({ name: 'get_accessibility_tree', args: { filter: 'all' } }),+ tree => ({ name: 'set_field', args: { ref_id: refFrom(tree, /textbox "Aklında ne var\?"/), text: 'WebBrain test gönderisi', submit: false } }),+ () => ({ name: 'get_accessibility_tree', args: { filter: 'all' } }),+ tree => ({ name: 'click_ax', args: { ref_id: refFrom(tree, /button "Gönder"/) } }),+ // The correction arrives once the Mastodon post was sent.+ async (_tree, run) => { await run.steer(); return { name: 'get_accessibility_tree', args: { filter: 'all' } }; },+ () => ({ name: 'get_accessibility_tree', args: { filter: 'all' } }),+ ],+ after: [+ () => ({ name: 'navigate', args: { url: 'https://x.com/home' } }),+ () => ({ name: 'get_accessibility_tree', args: { filter: 'all' } }),+ tree => ({ name: 'type_ax', args: { ref_id: refFrom(tree, /textbox "Post text"/), text: 'WebBrain test post', clear: true } }),+ () => ({ name: 'get_accessibility_tree', args: { filter: 'all' } }),+ tree => ({ name: 'click_ax', args: { ref_id: refFrom(tree, /button "Post"/) } }),+ () => ({ name: 'get_accessibility_tree', args: { filter: 'all' } }),+ () => ({ name: 'done', args: { outcome: 'success', summary: 'Posted on mastoturk.org, then on X.' } }),+ ],+ },+ 'leave-prompt': {+ before: [+ () => ({ name: 'navigate', args: { url: 'https://x.com/home' } }),+ () => ({ name: 'get_accessibility_tree', args: { filter: 'all' } }),+ tree => ({ name: 'type_ax', args: { ref_id: refFrom(tree, /textbox "Post text"/), text: 'Unsent WebBrain draft', clear: true } }),+ () => ({ name: 'navigate', args: { url: 'https://mastoturk.org/home' } }),+ () => ({ name: 'done', args: { outcome: 'success', summary: 'Left the unsent X draft and opened the MastoTurk home timeline.' } }),+ ],+ after: [],+ },+};++const only = process.env.WEBBRAIN_QUALITY_CASE_FILTER ? new RegExp(process.env.WEBBRAIN_QUALITY_CASE_FILTER) : null;+for (const [variant, script] of Object.entries(variants)) if (!only || only.test(variant)) await runVariant(variant, script);++async function runVariant(variant, script) {+ const out = path.resolve(process.env.WEBBRAIN_QUALITY_ARTIFACTS+ ? path.join(process.env.WEBBRAIN_QUALITY_ARTIFACTS, variant)+ : `ci/artifacts/quality-audit-2026-10-15/correction-cross-site-mv3/${variant}`);+ await fs.mkdir(out, { recursive: true });+ const task = variant === 'leave-prompt'+ ? 'open x.com, write a draft post without posting it, then go to mastoturk.org/home' : request;+ const mastodonPosts = [], xPosts = [], unknownPrompts = [], dialogs = [], settleDialogs = [];+ let steered = false, judgeCalls = 0, blockedRemote = 0, base = '', harnessAnswered = 0;+ const phase = { name: 'before', index: 0, lastId: null, emitted: 0 };+ const completionRecovery = { reads: 0 };+ const intent = () => ({ request_kind: 'execute', scope_relation: 'new', requires_state_change: true,+ requires_submission: variant !== 'leave-prompt', messaging: null,+ deliverables: [variant === 'leave-prompt' ? 'An unsent X draft, then the MastoTurk home timeline open'+ : steered ? 'A post on X' : 'A post on mastoturk.org'],+ completion_requirements: { download: false }, allows_planner_shaped_result: false, allows_app_state_tool_evidence: false,+ read_scope: 'visible_page', summary: steered ? 'Post something on X.' : 'Post something on mastoturk.org.',+ steps: [{ id: '1', action: steered ? 'Compose and publish a post on X, then verify it.' : 'Compose and publish a post, then verify it.' }],+ memory: { use_progress_ledger: false, progress_action: null }, scheduling: null, risks: [] });+ const contract = input => {+ if (!steered) return { version: 1, status: 'none', actions: [], requirements: null, prohibited: [],+ reason: 'No X or Bluesky publication is requested.' };+ const { sources } = JSON.parse(textOf(input.messages.find(message => message.role === 'user')?.content));+ const [source] = Object.entries(sources).find(([key, value]) => ['request', 'task'].includes(key) && value.includes('try to post something'));+ return { version: 1, status: 'ready', actions: [{ id: 'p1', platform: 'twitter', account: null,+ posts: [{ body: { kind: 'compose', source: { source, start: 'try to post something', end: 'try to post something' } },+ media: { kind: 'count', type: 'any', format: null, min: 0, max: 0 }, context: { kind: 'post', target: null } }] }],+ requirements: 'p1', prohibited: [], reason: 'The latest correction moves the requested post to X.' };+ };+ let context, page, panel, tabId = null;+ const run = {+ async steer() {+ for (let wait = 0; !mastodonPosts.length && wait < 50; wait++) await new Promise(resolve => setTimeout(resolve, 100));+ assert.equal(mastodonPosts.length, 1, 'The Mastodon post was sent before the correction');+ const accepted = await panel.evaluate(({ tabId, text }) => chrome.runtime.sendMessage({ target: 'background', action: 'chat_steer',+ tabId, requestId: 'owned-cross-site', messageId: 'owned-ok-now-on-x', text }), { tabId, text: correction });+ assert.equal(accepted?.accepted, true, JSON.stringify(accepted));+ steered = true;+ },+ };+ const server = http.createServer(async (incoming, response) => {+ if (incoming.url !== '/v1/chat/completions') { response.writeHead(404).end(); return; }+ let raw = ''; for await (const part of incoming) raw += part;+ const input = JSON.parse(raw), system = textOf(input.messages?.[0]?.content);+ let completion;+ try {+ if (system.startsWith('Extract stable user preferences')) completion = { role: 'assistant', content: '{"memories":[]}' };+ // The provider check made when the provider is saved.+ else if (system === 'Hi' || textOf(input.messages?.at(-1)?.content) === 'Hi') completion = { role: 'assistant', content: 'Hello' };+ // "Post something" names no exact body, so no exact Mastodon post can be+ // identified for later verification.+ else if (system.startsWith('Identify only the exact plain public Mastodon post')) completion = { role: 'assistant',+ content: JSON.stringify({ kind: 'unsupported', body: null, account: null }) };+ else if (system.startsWith("Compile the user's social-publication intent")) completion = { role: 'assistant', content: JSON.stringify(contract(input)) };+ else if (fixturePageTextReply(input.messages)) completion = { role: 'assistant', content: fixturePageTextReply(input.messages) };+ else if (fixedChoiceQuestion(input.messages)) {+ completion = { role: 'assistant', content: /^- "mode_claim":/m.test(system) ? JSON.stringify({ choice: 'result', evidence: '' })+ : fixtureFixedChoiceReply(input.messages, { deletion_prerequisite: 'keep_previous' }) };+ } else if (system.startsWith('Check one separately proposed consequential action')) {+ const trusted = JSON.parse(textOf(input.messages[1].content)), proposed = objectFrom(input.messages[2].content);+ completion = { role: 'assistant', content: JSON.stringify({ key: proposed.key, authorized: true,+ latestRequestEvidence: trusted.latestAcceptedRequest }) };+ } else if (system.startsWith('Independently check whether the authentic user request authorizes')) {+ const audit = JSON.parse(textOf(input.messages.find(message => message.role === 'user')?.content));+ completion = { role: 'assistant', content: JSON.stringify({ key: audit.key, actionId: audit.action.id, authorized: true,+ reason: 'The latest correction asks for a post on X, and the draft is a post.' }) };+ } else if (system.startsWith('Evaluate only the observable requirements')) {+ judgeCalls++;+ completion = { role: 'assistant', content: JSON.stringify({ outcome: 'succeeded', reason: 'The requested pages show the expected result.' }) };+ } else if (!input.tools?.length) {+ if (!system.startsWith('You are the intent and compact planning subsystem') && !system.startsWith('You are the planning subsystem')) {+ unknownPrompts.push(system.slice(0, 120));+ }+ completion = { role: 'assistant', content: JSON.stringify(intent()) };+ } else {+ // A step advances only once its result is back; a call superseded+ // before it ran is asked again.+ const tools = toolMessages(input.messages);+ if (steered && phase.name === 'before' && JSON.stringify(input.messages).includes(correction)) Object.assign(phase, { name: 'after', index: 0, lastId: null });+ else if (phase.lastId && tools.some(tool => tool.id === phase.lastId)) phase.index++;+ const steps = script[phase.name];+ const tree = tools.findLast(tool => tool.name === 'get_accessibility_tree' && tool.result?.pageContent);+ const step = steps[Math.min(phase.index, steps.length - 1)];+ const call = conformFixtureCompletionCall(input, await step(tree, run), completionRecovery);+ assert.ok(Object.values(call.args).every(value => value !== undefined), `${variant}: a step found no ref in ${JSON.stringify(tree?.result?.pageContent || '').slice(0, 400)}`);+ phase.lastId = `owned-${variant}-${phase.name}-${phase.index}-${++phase.emitted}`;+ completion = { role: 'assistant', content: '', tool_calls: [{ id: phase.lastId, type: 'function',+ function: { name: call.name, arguments: JSON.stringify(call.args) } }] };+ }+ } catch (error) {+ unknownPrompts.push(`provider error: ${error.message}`);+ response.writeHead(500, { 'Content-Type': 'application/json' }); response.end(JSON.stringify({ error: error.message })); return;+ }+ response.writeHead(200, { 'Content-Type': 'application/json' });+ response.end(JSON.stringify({ id: `response-${phase.emitted}`, choices: [{ message: completion,+ finish_reason: completion.tool_calls ? 'tool_calls' : 'stop' }], usage: { prompt_tokens: 100, completion_tokens: 30 } }));+ });+ await new Promise(resolve => server.listen(0, '127.0.0.1', resolve));+ base = `http://127.0.0.1:${server.address().port}`;+ const profile = await fs.mkdtemp(path.join(os.tmpdir(), 'webbrain-cross-site-mv3-'));+ try {+ const extension = path.join(profile, 'extension'); await fs.cp(path.resolve('src/chrome'), extension, { recursive: true });+ await fs.appendFile(path.join(extension, 'src/background.js'), '\nglobalThis.crossSiteFixtureAgent = agent;\n');+ context = await chromium.launchPersistentContext(path.join(profile, 'user'), { headless: true, channel: 'chromium',+ args: [`--disable-extensions-except=${extension}`, `--load-extension=${extension}`,+ '--host-resolver-rules=MAP * ~NOTFOUND, EXCLUDE 127.0.0.1'] });+ await context.route('**/*', async route => {+ const routed = route.request(), requested = new URL(routed.url());+ if (requested.hostname === '127.0.0.1' && requested.port === String(server.address().port)) return route.continue();+ if (requested.origin === 'https://mastoturk.org') {+ if (requested.pathname === '/api/v1/statuses' && routed.method() === 'POST') {+ mastodonPosts.push(JSON.parse(routed.postData() || '{}').status);+ return route.fulfill({ status: 200, contentType: 'application/json', body: '{"id":"1000"}' });+ }+ if (requested.pathname === '/publish') return route.fulfill({ contentType: 'text/html', body: mastodonCompose });+ if (requested.pathname === '/home') return route.fulfill({ contentType: 'text/html', body: mastodonHome(mastodonPosts) });+ return route.fulfill({ status: 404, body: '' });+ }+ if (requested.origin === 'https://x.com') {+ if (requested.pathname.startsWith('/owned-fixture/') && assets.has(requested.pathname.split('/').at(-1)))+ return route.fulfill({ contentType: 'text/javascript', body: assets.get(requested.pathname.split('/').at(-1)) });+ if (requested.pathname === '/owned-fixture/post' && routed.method() === 'POST') {+ xPosts.push(JSON.parse(routed.postData() || '{}').body);+ return route.fulfill({ status: 200, contentType: 'application/json', body: '{"ok":true}' });+ }+ if (routed.isNavigationRequest()) return route.fulfill({ contentType: 'text/html', body: xHtml });+ return route.fulfill({ status: 404, body: '' });+ }+ if (/^https?:$/.test(requested.protocol)) { blockedRemote++; return route.abort('blockedbyclient'); }+ return route.continue();+ });+ const worker = context.serviceWorkers()[0] || await context.waitForEvent('serviceworker', { timeout: 30_000 });+ const extensionOrigin = `chrome-extension://${new URL(worker.url()).host}`;+ const settings = await context.newPage(); await settings.goto(`${extensionOrigin}/src/ui/settings.html`);+ panel = await context.newPage(); await panel.goto(`${extensionOrigin}/src/ui/sidepanel.html`);+ const message = (action, data = {}) => settings.evaluate(({ action, data }) => chrome.runtime.sendMessage({ target: 'background', action, ...data }), { action, data });+ await settings.evaluate(() => chrome.storage.local.set({ helpImproveWebBrain: false, userMemoryEnabled: false, tracingEnabled: false,+ autoScreenshot: false, screenshotFallback: false, planBeforeActMode: 'off', planBeforeAct: false, planReviewMode: 'never',+ maxAgentSteps: 30, systemOneEnabled: false, agentAllowLocalNetwork: true, askBeforeConsequentialActions: false,+ openaiAskStreamingEnabled: false }));+ assert.equal((await message('update_provider', { providerId: 'openrouter', config: { apiKey: 'owned-fixture-fake-key',+ baseUrl: `${base}/v1`, model: 'minimax/minimax-m3', enabled: true, contextWindow: 1000000,+ supportsAskStreaming: false, supportsVision: false } })).ok, true);+ assert.equal((await message('set_active_provider', { providerId: 'openrouter' })).ok, true);+ await worker.evaluate(() => { crossSiteFixtureAgent.clarifyTimeoutSec = -1; });+ // The run starts where the debugger cannot attach, as in the trace.+ page = await context.newPage();+ await page.addInitScript(leavePrompt);+ // A prompt WebBrain does not answer waits; after eight seconds the+ // harness closes it the way a person would, and that counts against it.+ page.on('dialog', dialog => {+ dialogs.push(dialog.type());+ const timer = setTimeout(() => dialog.dismiss().then(() => { harnessAnswered++; }, () => {}), 8000);+ // Playwright still counts a prompt WebBrain answered over its own+ // connection as open; settle it quietly before the browser closes.+ settleDialogs.push(() => { clearTimeout(timer); return dialog.dismiss().catch(() => {}); });+ });+ await page.goto('chrome://extensions/');+ tabId = await settings.evaluate(async () => (await chrome.tabs.query({})).find(tab => tab.url.startsWith('chrome://extensions'))?.id);+ assert.ok(tabId, 'The run starts on chrome://extensions');+ const result = await message('chat', { tabId, text: task, mode: 'act', requestId: 'owned-cross-site', locale: 'en' });+ const toolResults = (result.updates || []).filter(event => event.type === 'tool_result').map(event => ({ name: event.data?.name,+ success: event.data?.result?.success, reason: event.data?.result?.actionGuard?.reason || event.data?.result?.reasonCode || null,+ error: event.data?.result?.error || null }));+ const evidence = { variant, toolResults, mastodonPosts, xPosts, dialogs, harnessAnswered, steered, unknownPrompts, judgeCalls,+ blockedRemote, finalUrl: page.url(), done: result.updates?.findLast(event => event.type === 'tool_result' && event.data?.name === 'done')?.data?.result || null };+ await fs.writeFile(path.join(out, 'evidence.json'), JSON.stringify(evidence, null, 2));+ assert.deepEqual(unknownPrompts, [], 'Every model question was one the fixture answers');+ const held = toolResults.filter(item => item.reason === 'prior_effect_unreconciled');+ if (variant === 'mastodon-then-x') {+ assert.deepEqual(mastodonPosts, ['WebBrain test gönderisi'], 'One Mastodon post');+ assert.equal(steered, true);+ assert.deepEqual(held, [], `No post was held to find the Mastodon post on X: ${JSON.stringify(held)}`);+ assert.deepEqual(xPosts, ['WebBrain test post'], `One X post: ${JSON.stringify(toolResults)}`);+ const navigations = toolResults.filter(item => item.name === 'navigate');+ assert.equal(navigations.length, 2, `No back and forth between the sites: ${JSON.stringify(navigations)}`);+ assert.equal(harnessAnswered, 0);+ } else {+ assert.ok(dialogs.includes('beforeunload'), `The X page asked before it was left: ${JSON.stringify(dialogs)}`);+ assert.equal(harnessAnswered, 0, 'WebBrain answered the leave prompt for its own navigation; nobody else had to');+ const left = toolResults.filter(item => item.name === 'navigate').at(-1);+ assert.equal(left?.success, true, `The navigation away from the draft arrived: ${JSON.stringify(left)}`);+ assert.equal(new URL(page.url()).origin, 'https://mastoturk.org');+ assert.deepEqual(xPosts, [], 'The draft was never posted');+ }+ console.log(JSON.stringify({ passed: true, installedMV3: true, variant, mastodonPosts: mastodonPosts.length, xPosts: xPosts.length,+ dialogs, harnessAnswered, navigations: toolResults.filter(item => item.name === 'navigate').length, judgeCalls, blockedRemote }));+ } finally {+ for (const settle of settleDialogs) await settle();+ await context?.close(); await new Promise(resolve => server.close(resolve));+ const resolved = path.resolve(profile);+ if (!resolved.startsWith(path.resolve(os.tmpdir()) + path.sep + 'webbrain-cross-site-mv3-')) throw new Error('Unexpected temporary profile path.');+ await fs.rm(resolved, { recursive: true, force: true });+ }+}