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
Placeholder scan: include controls associated with form="…"
Claude0c2933e3838f
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex b85c88077..2c342e186 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -32992,7 +32992,12 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d// Passwords and other fields without a typed value are left out.const placeholderFields = (() => {try {- const matches = Array.from(form.querySelectorAll('input, textarea')).slice(0, 5000).flatMap(el => {+ // A form's own controls include ones outside it that name it with+ // form="…", which the browser sends too; a form-less composer has+ // only what it contains.+ const owned = String(form.tagName || '').toUpperCase() === 'FORM' && form.elements+ ? Array.from(form.elements) : Array.from(form.querySelectorAll('input, textarea'));+ const matches = owned.filter(el => /^(?:INPUT|TEXTAREA)$/i.test(String(el?.tagName || ''))).slice(0, 5000).flatMap(el => {const type = String(el.type || '').toLowerCase();if (['hidden', 'submit', 'button', 'reset', 'image', 'checkbox', 'radio', 'file', 'password'].includes(type)) return [];const placeholder = compact(el.getAttribute?.('placeholder') || '', 200);diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex 04998639b..a122044ca 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -29896,7 +29896,12 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d// Passwords and other fields without a typed value are left out.const placeholderFields = (() => {try {- const matches = Array.from(form.querySelectorAll('input, textarea')).slice(0, 5000).flatMap(el => {+ // A form's own controls include ones outside it that name it with+ // form="…", which the browser sends too; a form-less composer has+ // only what it contains.+ const owned = String(form.tagName || '').toUpperCase() === 'FORM' && form.elements+ ? Array.from(form.elements) : Array.from(form.querySelectorAll('input, textarea'));+ const matches = owned.filter(el => /^(?:INPUT|TEXTAREA)$/i.test(String(el?.tagName || ''))).slice(0, 5000).flatMap(el => {const type = String(el.type || '').toLowerCase();if (['hidden', 'submit', 'button', 'reset', 'image', 'checkbox', 'radio', 'file', 'password'].includes(type)) return [];const placeholder = compact(el.getAttribute?.('placeholder') || '', 200);diff --git a/test/placeholder-submit-probe.mjs b/test/placeholder-submit-probe.mjsindex abf428b1a..f684d0d45 100644--- a/test/placeholder-submit-probe.mjs+++ b/test/placeholder-submit-probe.mjs@@ -67,6 +67,16 @@ for (const build of ['chrome', 'firefox']) {assert.equal(result.placeholderFields[0]?.name, 'email', 'the edited field comes first');assert.equal(result.placeholderFields[0]?.changed, true);});++ await t.test('a field outside the form that names it with form= is checked too', async () => {+ await page.setContent('<form id="signup" method="post" action="/signup"><button id="go">Sign up</button></form>'+ + '<input id="email" form="signup" name="email" aria-label="Email" placeholder="[email protected]">');+ await page.evaluate(() => { document.querySelector('#email').value = '[email protected]'; });+ const result = await probe('click', { selector: '#go' });+ assert.equal(result?.isSubmit, true);+ assert.equal(result.placeholderFields?.[0]?.name, 'email');+ assert.equal(result.placeholderFields?.[0]?.changed, true);+ });} finally {await browser.close();}