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
Remember a declined submission by its form and button elements
Claude11adef445a86
diff --git a/package.json b/package.jsonindex 99cdd3337..3e104baf4 100644--- a/package.json+++ b/package.json@@ -100,7 +100,7 @@"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/captcha-aws-recovery.mjs test/captcha-documented-contracts.mjs test/huggingface-signup-recovery.mjs test/trace-full-export.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-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/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/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/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/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/recipient-confirmation-ui.mjs test/assistant-message-visibility-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/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-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/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/recipient-confirmation-ui.mjs test/assistant-message-visibility-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","test:shard:browser-c": "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",diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex 3e568c9ed..feb8907e4 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -32447,14 +32447,21 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d}// The identity a declined submission is remembered by in a turn, or ''- // when WebBrain did not resolve one: a script or WebMCP callback, or a- // control whose form, fields and action it could not read.+ // when WebBrain did not resolve one: a script or WebMCP callback, a+ // control whose form, fields and action it could not read, or one whose+ // form and button the page probe did not identify. Two forms can post+ // the same visible fields to one endpoint (per-row forms told apart only+ // by hidden IDs), and one form can have several buttons, so the key+ // also names the frame and the form and button elements._declinableSubmissionKey(toolName, submitInfo) {if (!submitInfo || toolName === 'execute_js' || toolName === 'execute_webmcp_tool') return '';const resolved = (Array.isArray(submitInfo.changedFields) && submitInfo.changedFields.length > 0)|| (Array.isArray(submitInfo.fields) && submitInfo.fields.length > 0)|| !!(submitInfo.actionUrl || submitInfo.action);- return resolved ? submitActionKey(submitInfo, submitInfo.url) : '';+ const elements = String(submitInfo.submissionIdentity || '');+ if (!resolved || !elements) return '';+ const frame = Number.isInteger(submitInfo.frameId) ? submitInfo.frameId : 0;+ return [submitActionKey(submitInfo, submitInfo.url), `frame:${frame}`, `elements:${elements}`].join('|');}_fallbackSubmitConfirmationInfo(host, tool, reason, summary = '') {@@ -32587,6 +32594,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dframeDocumentIdentity: sameFrameDocument ? frameBaseline.identity : '',frameStatusMessages: sameFrameDocument ? frameBaseline.messages : [] } : {}),formRef: /^ref_\d+$/.test(String(detected.formRef || '')) ? detected.formRef : '',+ submissionIdentity: String(detected.submissionIdentity || '').slice(0, 80),summary: String(detected.summary || '').slice(0, 1200),fields: Array.isArray(detected.fields) ? detected.fields.slice(0, 12) : [],hiddenFields: Array.isArray(detected.hiddenFields) ? detected.hiddenFields.slice(0, 20) : [],@@ -33353,6 +33361,47 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d} catch { return { complete: false }; }};const transactionOrderSite = /(?:^|\.)12306\.cn$/i.test(host);+ // The form and the button a submission goes through, as identities of+ // the elements this frame holds. A declined submission is remembered by+ // them, so another form or button with the same fields and action+ // (per-row forms told apart only by hidden IDs, Reject beside Approve)+ // still gets its own card. An Enter in a field, or set_field({submit}),+ // submits through the form's default button.+ const submissionIdentity = (form, submitControl) => {+ try {+ if (!(window.__wbSubmissionIdentities instanceof WeakMap)) {+ window.__wbSubmissionIdentities = new WeakMap();+ window.__wbSubmissionIdentityPrefix = Math.random().toString(36).slice(2, 10);+ window.__wbSubmissionIdentityCount = 0;+ }+ const identities = window.__wbSubmissionIdentities;+ const identityOf = el => {+ if (!el || el.nodeType !== 1) return '';+ if (!identities.has(el)) {+ window.__wbSubmissionIdentityCount = (Number(window.__wbSubmissionIdentityCount) || 0) + 1;+ identities.set(el, `${window.__wbSubmissionIdentityPrefix}.${window.__wbSubmissionIdentityCount}`);+ }+ return identities.get(el);+ };+ const owner = submitControl ? (labelControlFor(submitControl) || submitControl) : null;+ const typedField = !!owner && isFormField(owner)+ && !/^(?:submit|image|button|reset)$/i.test(String(owner.type || ''));+ const defaultButton = () => {+ try {+ return Array.from(form?.elements || []).find(el => /^(?:BUTTON|INPUT)$/i.test(String(el?.tagName || ''))+ && /^(?:submit|image)$/i.test(String(el.type || ''))) || null;+ } catch { return null; }+ };+ const submitter = owner && !typedField+ ? (owner.closest?.('button,input,[role="button"]') || owner)+ : defaultButton();+ const formIdentity = identityOf(form);+ const submitterIdentity = identityOf(submitter);+ return formIdentity || submitterIdentity ? `${formIdentity}/${submitterIdentity}` : '';+ } catch {+ return '';+ }+ };const submitInfo = (form, reason, pendingEl = null, pendingValue = null, validationSubmitEvidence = 'strong', submitControl = null) => {const formOrders = transactionOrderSite? transactionOrderScan(form)@@ -33407,6 +33456,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dreason,validationSubmitEvidence,frameDocumentIdentity: [url, performance.timeOrigin].join('|'),+ submissionIdentity: submissionIdentity(form, submitControl),semanticCommit: nativeConfirmationCommit(control),actionResource: resourceProofFor(control),resourceBaseline: resourceProofs().map(resource => resource.url),diff --git a/src/chrome/src/agent/permission-gate.js b/src/chrome/src/agent/permission-gate.jsindex 2f831b155..d414e24e6 100644--- a/src/chrome/src/agent/permission-gate.js+++ b/src/chrome/src/agent/permission-gate.js@@ -787,10 +787,13 @@ export class PermissionManager {/*** A form submission the user declined on WebBrain's own submit card in- * this turn. The key is submitActionKey(): the resolved form, its method- * and the values that changed, hashed. WebBrain does not ask about the- * same submission again in the turn; a changed value, a new turn, a- * correction or the user's own answer on a later card asks again.+ * this turn. The agent keys it by submitActionKey() (the form's action,+ * method and changed values, hashed) together with the frame and the form+ * and button elements the page probe identified, so another form or+ * button with the same fields is a different submission. WebBrain does+ * not ask about the same submission again in the turn; a changed value, a+ * new turn, a correction or the user's own answer on a later card asks+ * again.*/declineSubmission(key, tabId) {const normalizedKey = String(key || '');diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex bfcaea9ac..42b0f2d70 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -29435,14 +29435,21 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d}// The identity a declined submission is remembered by in a turn, or ''- // when WebBrain did not resolve one: a script or WebMCP callback, or a- // control whose form, fields and action it could not read.+ // when WebBrain did not resolve one: a script or WebMCP callback, a+ // control whose form, fields and action it could not read, or one whose+ // form and button the page probe did not identify. Two forms can post+ // the same visible fields to one endpoint (per-row forms told apart only+ // by hidden IDs), and one form can have several buttons, so the key+ // also names the frame and the form and button elements._declinableSubmissionKey(toolName, submitInfo) {if (!submitInfo || toolName === 'execute_js' || toolName === 'execute_webmcp_tool') return '';const resolved = (Array.isArray(submitInfo.changedFields) && submitInfo.changedFields.length > 0)|| (Array.isArray(submitInfo.fields) && submitInfo.fields.length > 0)|| !!(submitInfo.actionUrl || submitInfo.action);- return resolved ? submitActionKey(submitInfo, submitInfo.url) : '';+ const elements = String(submitInfo.submissionIdentity || '');+ if (!resolved || !elements) return '';+ const frame = Number.isInteger(submitInfo.frameId) ? submitInfo.frameId : 0;+ return [submitActionKey(submitInfo, submitInfo.url), `frame:${frame}`, `elements:${elements}`].join('|');}_fallbackSubmitConfirmationInfo(host, tool, reason, summary = '') {@@ -29579,6 +29586,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dframeDocumentIdentity: sameFrameDocument ? frameBaseline.identity : '',frameStatusMessages: sameFrameDocument ? frameBaseline.messages : [] } : {}),formRef: /^ref_\d+$/.test(String(detected.formRef || '')) ? detected.formRef : '',+ submissionIdentity: String(detected.submissionIdentity || '').slice(0, 80),summary: String(detected.summary || '').slice(0, 1200),fields: Array.isArray(detected.fields) ? detected.fields.slice(0, 12) : [],hiddenFields: Array.isArray(detected.hiddenFields) ? detected.hiddenFields.slice(0, 20) : [],@@ -30257,6 +30265,47 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d} catch { return { complete: false }; }};const transactionOrderSite = /(?:^|\.)12306\.cn$/i.test(host);+ // The form and the button a submission goes through, as identities of+ // the elements this frame holds. A declined submission is remembered by+ // them, so another form or button with the same fields and action+ // (per-row forms told apart only by hidden IDs, Reject beside Approve)+ // still gets its own card. An Enter in a field, or set_field({submit}),+ // submits through the form's default button.+ const submissionIdentity = (form, submitControl) => {+ try {+ if (!(window.__wbSubmissionIdentities instanceof WeakMap)) {+ window.__wbSubmissionIdentities = new WeakMap();+ window.__wbSubmissionIdentityPrefix = Math.random().toString(36).slice(2, 10);+ window.__wbSubmissionIdentityCount = 0;+ }+ const identities = window.__wbSubmissionIdentities;+ const identityOf = el => {+ if (!el || el.nodeType !== 1) return '';+ if (!identities.has(el)) {+ window.__wbSubmissionIdentityCount = (Number(window.__wbSubmissionIdentityCount) || 0) + 1;+ identities.set(el, `${window.__wbSubmissionIdentityPrefix}.${window.__wbSubmissionIdentityCount}`);+ }+ return identities.get(el);+ };+ const owner = submitControl ? (labelControlFor(submitControl) || submitControl) : null;+ const typedField = !!owner && isFormField(owner)+ && !/^(?:submit|image|button|reset)$/i.test(String(owner.type || ''));+ const defaultButton = () => {+ try {+ return Array.from(form?.elements || []).find(el => /^(?:BUTTON|INPUT)$/i.test(String(el?.tagName || ''))+ && /^(?:submit|image)$/i.test(String(el.type || ''))) || null;+ } catch { return null; }+ };+ const submitter = owner && !typedField+ ? (owner.closest?.('button,input,[role="button"]') || owner)+ : defaultButton();+ const formIdentity = identityOf(form);+ const submitterIdentity = identityOf(submitter);+ return formIdentity || submitterIdentity ? `${formIdentity}/${submitterIdentity}` : '';+ } catch {+ return '';+ }+ };const submitInfo = (form, reason, pendingEl = null, pendingValue = null, validationSubmitEvidence = 'strong', submitControl = null) => {const formOrders = transactionOrderSite? transactionOrderScan(form)@@ -30311,6 +30360,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dreason,validationSubmitEvidence,frameDocumentIdentity: [url, performance.timeOrigin].join('|'),+ submissionIdentity: submissionIdentity(form, submitControl),semanticCommit: nativeConfirmationCommit(control),actionResource: resourceProofFor(control),resourceBaseline: resourceProofs().map(resource => resource.url),diff --git a/src/firefox/src/agent/permission-gate.js b/src/firefox/src/agent/permission-gate.jsindex 182fb7b41..2e0aa3a1a 100644--- a/src/firefox/src/agent/permission-gate.js+++ b/src/firefox/src/agent/permission-gate.js@@ -772,10 +772,13 @@ export class PermissionManager {/*** A form submission the user declined on WebBrain's own submit card in- * this turn. The key is submitActionKey(): the resolved form, its method- * and the values that changed, hashed. WebBrain does not ask about the- * same submission again in the turn; a changed value, a new turn, a- * correction or the user's own answer on a later card asks again.+ * this turn. The agent keys it by submitActionKey() (the form's action,+ * method and changed values, hashed) together with the frame and the form+ * and button elements the page probe identified, so another form or+ * button with the same fields is a different submission. WebBrain does+ * not ask about the same submission again in the turn; a changed value, a+ * new turn, a correction or the user's own answer on a later card asks+ * again.*/declineSubmission(key, tabId) {const normalizedKey = String(key || '');diff --git a/test/declined-submission-identity.mjs b/test/declined-submission-identity.mjsnew file mode 100644index 000000000..4952d4c92--- /dev/null+++ b/test/declined-submission-identity.mjs@@ -0,0 +1,62 @@+// A submission the user declined is remembered for the rest of the turn by+// the page elements it goes through, as the submit probe identifies them:+// the form and its button. Per-row forms that post the same visible fields to+// one endpoint, told apart only by hidden IDs, and two buttons of one form are+// different submissions. The same form and button, clicked again or reached+// by an Enter in the form's field, is the same submission.+import assert from 'node:assert/strict';+import { test } from 'node:test';+import { chromium, firefox } from 'playwright';+import { fixtureControlEffectReading, probeWithReadings } from './semantic-decision-stub.mjs';++const pageUrl = 'https://rows.example/list';++for (const build of ['chrome', 'firefox']) {+ for (const engine of ['chromium', 'firefox']) {+ test(`${build} build on ${engine}: the submit probe tells forms and buttons apart`, async t => {+ const { Agent } = await import(`../src/${build}/src/agent/agent.js`);+ const browser = await (engine === 'chromium' ? chromium : firefox).launch({ headless: true });+ const context = await browser.newContext({ viewport: { width: 1200, height: 900 } });+ await context.route('**/*', route => route.fulfill({ contentType: 'text/html', body: '<!doctype html><title>fixture</title>' }));+ const page = await context.newPage();+ await page.goto(pageUrl);+ const source = Agent._submitActionProbe.toString();+ const runProbe = (tool, args) => page.evaluate(({ source, tool, args }) => (0, eval)(`(${source})`)(tool, args), { source, tool, args });+ const probe = (tool, args) => probeWithReadings(runProbe, tool, args, fixtureControlEffectReading);+ try {+ await t.test('per-row forms with the same fields and action are different submissions', async () => {+ await page.setContent(['1', '2'].map(row => '<form method="post" action="/rows/save">'+ + `<input type="hidden" name="row" value="${row}"><input name="note" aria-label="Note" value="Done">`+ + `<button id="save-${row}">Save</button></form>`).join(''));+ const first = await probe('click', { selector: '#save-1' });+ const again = await probe('click', { selector: '#save-1' });+ const other = await probe('click', { selector: '#save-2' });+ assert.equal(first?.isSubmit, true);+ assert.ok(first.submissionIdentity, 'the probe identifies the form and button');+ assert.equal(again.submissionIdentity, first.submissionIdentity, 'the same form and button');+ assert.notEqual(other.submissionIdentity, first.submissionIdentity, 'another row');+ // Without the elements, the two rows read the same.+ assert.equal(other.actionUrl, first.actionUrl);+ assert.deepEqual(other.changedFields, first.changedFields);+ });++ await t.test('two buttons of one form differ, and an Enter goes through the default button', async () => {+ await page.setContent('<form method="post" action="/review">'+ + '<input id="comment" name="comment" aria-label="Comment" value="Looks good">'+ + '<button id="save">Save</button><button id="send" name="decision" value="send">Send</button></form>');+ const save = await probe('click', { selector: '#save' });+ const send = await probe('click', { selector: '#send' });+ assert.equal(save?.isSubmit, true);+ assert.equal(send?.isSubmit, true);+ assert.notEqual(send.submissionIdentity, save.submissionIdentity, 'another button of the form');+ await page.focus('#comment');+ const enter = await probe('press_keys', { keys: 'Enter' });+ assert.equal(enter?.isSubmit, true);+ assert.equal(enter.submissionIdentity, save.submissionIdentity, 'an Enter in the field submits through the first button');+ });+ } finally {+ await browser.close();+ }+ });+ }+}diff --git a/test/run.js b/test/run.jsindex 3a3c2d7dd..51933e1c9 100644--- a/test/run.js+++ b/test/run.js@@ -82584,6 +82584,8 @@ test('a declined submission is not asked again in the same turn', async () => {let prompts = 0;let executed = 0;let email = '[email protected]';+ // The form and button the page probe identified, as it reports them.+ let elements = 'form-1/subscribe';const updates = [];agent.conversationModes.set(tabId, 'act');@@ -82603,6 +82605,7 @@ test('a declined submission is not asked again in the same turn', async () => {reason: 'submit button/control activation',summary: `Changed/filled fields: Email: ${email}.`,changedFields: [{ label: 'Email', value: email, changed: true }],+ submissionIdentity: elements,});agent._promptSubmitConfirmation = async () => {prompts += 1;@@ -82661,6 +82664,22 @@ test('a declined submission is not asked again in the same turn', async () => {agent.permissions.beginTurn(tabId);await submit('new-turn');assert.equal(prompts, 4, `${AgentClass.name}: a new turn asks again`);++ // Another form with the same fields and action (a per-row form told+ // apart only by a hidden ID), or another button of the same form, is a+ // different submission and asks on its own card.+ elements = 'form-2/subscribe';+ await submit('other-form');+ assert.equal(prompts, 5, `${AgentClass.name}: a declined form refused another form with the same fields`);+ elements = 'form-1/unsubscribe';+ await submit('other-button');+ assert.equal(prompts, 6, `${AgentClass.name}: a declined button refused another button of the form`);+ // A submission whose form and button the probe did not identify is never+ // remembered: it asks every time.+ elements = '';+ await submit('unidentified-1');+ await submit('unidentified-2');+ assert.equal(prompts, 8, `${AgentClass.name}: an unidentified submission skipped its card`);assert.equal(executed, 0, `${AgentClass.name}: nothing declined was submitted`);// A script has no form identity: each run of one asks on its own card.