Skip to content

Open-source AI browser agent for Chrome and Firefox (monorepo) 🧠

Remember only native form submissions; set_field submits without a button

Clauded95562716109
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index 2a6c29d17..c940f3ec9 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -33371,8 +33371,9 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
// told apart only by hidden IDs, Reject beside Approve), or the same form
// with any value or destination changed (a field past the summary's
// first eight, a password, another file, a hidden record ID, a button's
- // new formaction), still gets its own card. An Enter in a field, or
- // set_field({submit}), submits through the form's default button.
+ // new formaction), still gets its own card. An Enter in a field submits
+ // through the form's default button; set_field({submit}) submits with
+ // no button.
const submissionIdentity = (form, submitControl, pendingEl = null, pendingValue = null) => {
try {
if (!(window.__wbSubmissionIdentities instanceof WeakMap)) {
@@ -33401,18 +33402,44 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
&& /^(?:submit|image)$/i.test(String(el.type || ''))) || null;
} catch { return null; }
};
- const submitter = owner && !typedField
- ? (owner.closest?.('button,input,[role="button"]') || owner)
- : defaultButton();
+ // Only a submission the browser makes from the form itself is
+ // remembered: the form's own submit button, an Enter in one of its
+ // fields, or set_field({submit}) on a plain field. A control that
+ // only runs page script (type=button, a role=button, a click
+ // handler, a form-less composer, a combobox or editor that page
+ // handlers commit) can act on state outside the form, such as the
+ // selected row, so it is never remembered.
+ if (String(form?.tagName || '').toUpperCase() !== 'FORM') return '';
+ const nativeButton = el => /^(?:BUTTON|INPUT)$/i.test(String(el?.tagName || ''))
+ && /^(?:submit|image)$/i.test(String(el?.type || ''));
+ let submitter = null;
+ if (owner && !typedField) {
+ submitter = owner.closest?.('button,input,[role="button"]') || owner;
+ if (!nativeButton(submitter) || (submitter.form && submitter.form !== form)) return '';
+ } else if (toolName === 'set_field') {
+ // requestSubmit() without a submitter (content.js): the form's own
+ // action and method apply, not a button's overrides.
+ const role = String(owner?.getAttribute?.('role') || '').toLowerCase();
+ const visiblePopup = () => {
+ try {
+ return Array.from(doc.querySelectorAll('[role="listbox"],[role="menu"]')).some(el => {
+ const rect = el.getBoundingClientRect();
+ return rect.width > 0 && rect.height > 0;
+ });
+ } catch { return true; }
+ };
+ if (!owner || owner.isContentEditable || role === 'searchbox' || role === 'combobox'
+ || owner.getAttribute?.('aria-autocomplete') || owner.getAttribute?.('aria-expanded') === 'true'
+ || owner.getAttribute?.('aria-controls') || visiblePopup()) return '';
+ } else {
+ // An Enter in a field submits through the form's default button.
+ submitter = defaultButton();
+ }
// An image button also sends where it was clicked, which is not
// known here: such a submission is never remembered.
if (String(submitter?.tagName || '').toUpperCase() === 'INPUT' && String(submitter.type || '').toLowerCase() === 'image') return '';
const controls = (() => {
- try {
- return String(form?.tagName || '').toUpperCase() === 'FORM'
- ? Array.from(form.elements || [])
- : Array.from(form?.querySelectorAll?.('input, textarea, select, [contenteditable="true"]') || []);
- } catch { return []; }
+ try { return Array.from(form.elements || []); } catch { return []; }
})();
const valueOf = el => {
// set_field({submit, clear:false}) appends to what the field holds.
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index bb8cfad99..fd9070df1 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -30275,8 +30275,9 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
// told apart only by hidden IDs, Reject beside Approve), or the same form
// with any value or destination changed (a field past the summary's
// first eight, a password, another file, a hidden record ID, a button's
- // new formaction), still gets its own card. An Enter in a field, or
- // set_field({submit}), submits through the form's default button.
+ // new formaction), still gets its own card. An Enter in a field submits
+ // through the form's default button; set_field({submit}) submits with
+ // no button.
const submissionIdentity = (form, submitControl, pendingEl = null, pendingValue = null) => {
try {
if (!(window.__wbSubmissionIdentities instanceof WeakMap)) {
@@ -30305,18 +30306,44 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
&& /^(?:submit|image)$/i.test(String(el.type || ''))) || null;
} catch { return null; }
};
- const submitter = owner && !typedField
- ? (owner.closest?.('button,input,[role="button"]') || owner)
- : defaultButton();
+ // Only a submission the browser makes from the form itself is
+ // remembered: the form's own submit button, an Enter in one of its
+ // fields, or set_field({submit}) on a plain field. A control that
+ // only runs page script (type=button, a role=button, a click
+ // handler, a form-less composer, a combobox or editor that page
+ // handlers commit) can act on state outside the form, such as the
+ // selected row, so it is never remembered.
+ if (String(form?.tagName || '').toUpperCase() !== 'FORM') return '';
+ const nativeButton = el => /^(?:BUTTON|INPUT)$/i.test(String(el?.tagName || ''))
+ && /^(?:submit|image)$/i.test(String(el?.type || ''));
+ let submitter = null;
+ if (owner && !typedField) {
+ submitter = owner.closest?.('button,input,[role="button"]') || owner;
+ if (!nativeButton(submitter) || (submitter.form && submitter.form !== form)) return '';
+ } else if (toolName === 'set_field') {
+ // requestSubmit() without a submitter (content.js): the form's own
+ // action and method apply, not a button's overrides.
+ const role = String(owner?.getAttribute?.('role') || '').toLowerCase();
+ const visiblePopup = () => {
+ try {
+ return Array.from(doc.querySelectorAll('[role="listbox"],[role="menu"]')).some(el => {
+ const rect = el.getBoundingClientRect();
+ return rect.width > 0 && rect.height > 0;
+ });
+ } catch { return true; }
+ };
+ if (!owner || owner.isContentEditable || role === 'searchbox' || role === 'combobox'
+ || owner.getAttribute?.('aria-autocomplete') || owner.getAttribute?.('aria-expanded') === 'true'
+ || owner.getAttribute?.('aria-controls') || visiblePopup()) return '';
+ } else {
+ // An Enter in a field submits through the form's default button.
+ submitter = defaultButton();
+ }
// An image button also sends where it was clicked, which is not
// known here: such a submission is never remembered.
if (String(submitter?.tagName || '').toUpperCase() === 'INPUT' && String(submitter.type || '').toLowerCase() === 'image') return '';
const controls = (() => {
- try {
- return String(form?.tagName || '').toUpperCase() === 'FORM'
- ? Array.from(form.elements || [])
- : Array.from(form?.querySelectorAll?.('input, textarea, select, [contenteditable="true"]') || []);
- } catch { return []; }
+ try { return Array.from(form.elements || []); } catch { return []; }
})();
const valueOf = el => {
// set_field({submit, clear:false}) appends to what the field holds.
diff --git a/test/declined-submission-identity.mjs b/test/declined-submission-identity.mjs
index f86c2367d..8f30a48a0 100644
--- a/test/declined-submission-identity.mjs
+++ b/test/declined-submission-identity.mjs
@@ -114,6 +114,30 @@ for (const build of ['chrome', 'firefox']) {
assert.equal(image?.isSubmit, true);
assert.equal(image.submissionIdentity, '', 'an image button sends its click position');
});
+
+ await t.test('only a submission the browser makes from the form is remembered', async () => {
+ await page.setContent('<form method="post" action="/search"><input id="q" name="q" aria-label="Query" value="owned">'
+ + '<button id="go" formaction="/elsewhere">Send</button>'
+ + '<button id="script" type="button" onclick="void 0">Delete selected</button>'
+ + '<div id="role" role="button" tabindex="0" onclick="void 0">Save</div></form>'
+ + '<section><textarea id="draft" aria-label="Draft">Hello</textarea><button id="composer" type="button" onclick="void 0">Send</button></section>');
+ await page.evaluate(() => { window.__wb_ax_lookup = ref => (ref === 'ref_q' ? document.querySelector('#q') : null); });
+ // set_field({submit}) submits with no button, so the button's
+ // formaction does not apply: another submission than clicking it.
+ const button = (await probe('click', { selector: '#go' })).submissionIdentity;
+ const field = (await probe('set_field', { ref_id: 'ref_q', text: 'owned', submit: true })).submissionIdentity;
+ assert.ok(button && field);
+ assert.notEqual(field, button, 'set_field is not a click on the default button');
+ assert.equal(field.split('/')[1], '', 'no button');
+ // Controls that only run page script are never remembered.
+ for (const selector of ['#script', '#role']) {
+ const result = await probe('click', { selector });
+ assert.equal(result?.isSubmit, true, selector);
+ assert.equal(result.submissionIdentity, '', selector);
+ }
+ const composer = await probe('click', { selector: '#composer' });
+ assert.equal(composer?.submissionIdentity || '', '', 'a form-less composer');
+ });
} finally {
await browser.close();
}