Skip to content

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

Placeholder guard: check every control, however many the form has

Claude99a7a5255eb0
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index 72378aa7f..d0a0eae41 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -32823,7 +32823,9 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
} catch {
return [];
}
- const matches = owned.filter(el => /^(?:INPUT|TEXTAREA)$/i.test(String(el?.tagName || ''))).slice(0, 5000).flatMap(el => {
+ // Every control is checked, however many the form has: only the matches
+ // are kept, and their list is capped below.
+ const matches = owned.filter(el => /^(?:INPUT|TEXTAREA)$/i.test(String(el?.tagName || ''))).flatMap(el => {
const type = String(el.type || '').toLowerCase();
if (['hidden', 'submit', 'button', 'reset', 'image', 'checkbox', 'radio', 'file', 'password'].includes(type)) return [];
// A disabled control, its own or its fieldset's, is not sent.
@@ -33064,7 +33066,9 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
// 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 => {
+ // Every control is checked, however many the form has: only the
+ // matches are kept, and their list is capped below.
+ const matches = owned.filter(el => /^(?:INPUT|TEXTAREA)$/i.test(String(el?.tagName || ''))).flatMap(el => {
const type = String(el.type || '').toLowerCase();
if (['hidden', 'submit', 'button', 'reset', 'image', 'checkbox', 'radio', 'file', 'password'].includes(type)) return [];
// A disabled control, its own or its fieldset's, is not sent.
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index 4b795b0ea..64dadc74e 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -29903,7 +29903,9 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
// 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 => {
+ // Every control is checked, however many the form has: only the
+ // matches are kept, and their list is capped below.
+ const matches = owned.filter(el => /^(?:INPUT|TEXTAREA)$/i.test(String(el?.tagName || ''))).flatMap(el => {
const type = String(el.type || '').toLowerCase();
if (['hidden', 'submit', 'button', 'reset', 'image', 'checkbox', 'radio', 'file', 'password'].includes(type)) return [];
// A disabled control, its own or its fieldset's, is not sent.
diff --git a/test/placeholder-submit-probe.mjs b/test/placeholder-submit-probe.mjs
index 6c502478f..1436750cd 100644
--- a/test/placeholder-submit-probe.mjs
+++ b/test/placeholder-submit-probe.mjs
@@ -74,6 +74,17 @@ for (const build of ['chrome', 'firefox']) {
assert.equal(result.placeholderFields[0]?.changed, true);
});
+ await t.test('any number of controls the scan skips cannot hide an edited field', async () => {
+ await page.setContent('<form method="post" action="/many">'
+ + Array.from({ length: 6000 }, (_, i) => `<input type="hidden" name="h${i}" value="x">`).join('')
+ + Array.from({ length: 200 }, (_, i) => `<input name="d${i}" placeholder="Example" value="Example" disabled>`).join('')
+ + '<input id="email" name="email" aria-label="Email" placeholder="[email protected]"><button id="go">Save</button></form>');
+ await page.evaluate(() => { document.querySelector('#email').value = '[email protected]'; });
+ const result = await probe('click', { selector: '#go' });
+ assert.equal(result?.isSubmit, true);
+ assert.deepEqual(result.placeholderFields.map(field => [field.name, field.changed]), [['email', 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]">');
diff --git a/test/run.js b/test/run.js
index d4a97cc93..1ce39861a 100644
--- a/test/run.js
+++ b/test/run.js
@@ -90573,7 +90573,9 @@ test('chrome CDP submit selector scans its form for placeholder values', async (
tagName: 'INPUT', type: attrs.type || 'text', value, defaultValue,
getAttribute: name => attrs[name] ?? null, matches: () => false,
});
+ // Any number of controls the scan skips comes before the edited field.
const control = { form: { elements: [
+ ...Array.from({ length: 6000 }, (_, i) => input({ name: `h${i}`, type: 'hidden', placeholder: 'x' }, 'x')),
input({ name: 'email', type: 'email', placeholder: '[email protected]' }, '[email protected]'),
input({ name: 'pass', type: 'password', placeholder: 'Password' }, 'Password'),
input({ name: 'city', placeholder: 'Istanbul', value: 'Istanbul' }, 'Istanbul', 'Istanbul'),