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 guard: decide on whole values, match long writes
Claude322ebbd1a475
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex 2c342e186..b3edf4096 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -33000,11 +33000,13 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dconst 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);- const value = pendingEl && el === pendingEl ? compact(pendingValue, 200) : compact(el.value || '', 200);- const changed = el === pendingEl || (!!value && value !== defaultValue(el));+ // Whole values decide; only what is returned is shortened.+ const whole = text => String(text ?? '').replace(/\s+/g, ' ').trim();+ const placeholder = whole(el.getAttribute?.('placeholder'));+ const value = whole(pendingEl && el === pendingEl ? pendingValue : el.value);+ const changed = el === pendingEl || (!!value && value !== whole(el.defaultValue ?? el.getAttribute?.('value')));return placeholder && value.toLowerCase() === placeholder.toLowerCase()- ? [{ label: labelFor(el), value, placeholder, changed,+ ? [{ label: labelFor(el), value: compact(value, 200), placeholder: compact(placeholder, 200), changed,ref: typeof window.__wb_ax_ref === 'function' ? String(window.__wb_ax_ref(el) || '') : '',name: compact(el.getAttribute?.('name') || '', 120), id: compact(el.getAttribute?.('id') || '', 120) }] : [];});@@ -52494,10 +52496,15 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dif (!meta || String(meta.type || '').toLowerCase() === 'password') return;const normalize = text => String(text ?? '').replace(/\s+/g, ' ').trim().toLowerCase();const placeholder = normalize(meta.placeholder);- const written = normalize(typeof response.value === 'string' ? response.value : args?.text);+ // The typed text, whole; an append (clear:false) reads the field's+ // result instead, which the receipt reports shortened.+ const appended = args?.clear === false && typeof response.value === 'string';+ const written = normalize(appended ? response.value : (typeof args?.text === 'string' ? args.text : response.value));if (!placeholder || written !== placeholder) return;const ref = [args?.ref_id, response.ref_id].map(value => String(value || '')).find(value => /^ref_\d+$/.test(value)) || '';- const write = { value: written, ref, name: String(meta.name || ''), id: String(meta.id || '') };+ // Kept in the form the submit probe reports a value: its first 200+ // characters.+ const write = { value: normalize(written.slice(0, 200)), ref, name: String(meta.name || ''), id: String(meta.id || '') };if (!write.ref && !write.name && !write.id) return;const runId = this.currentRunId.get(tabId) || null;this._placeholderWrites ??= new Map();diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex a122044ca..b65545c49 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -29904,11 +29904,13 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dconst 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);- const value = pendingEl && el === pendingEl ? compact(pendingValue, 200) : compact(el.value || '', 200);- const changed = el === pendingEl || (!!value && value !== defaultValue(el));+ // Whole values decide; only what is returned is shortened.+ const whole = text => String(text ?? '').replace(/\s+/g, ' ').trim();+ const placeholder = whole(el.getAttribute?.('placeholder'));+ const value = whole(pendingEl && el === pendingEl ? pendingValue : el.value);+ const changed = el === pendingEl || (!!value && value !== whole(el.defaultValue ?? el.getAttribute?.('value')));return placeholder && value.toLowerCase() === placeholder.toLowerCase()- ? [{ label: labelFor(el), value, placeholder, changed,+ ? [{ label: labelFor(el), value: compact(value, 200), placeholder: compact(placeholder, 200), changed,ref: typeof window.__wb_ax_ref === 'function' ? String(window.__wb_ax_ref(el) || '') : '',name: compact(el.getAttribute?.('name') || '', 120), id: compact(el.getAttribute?.('id') || '', 120) }] : [];});@@ -45764,10 +45766,15 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dif (!meta || String(meta.type || '').toLowerCase() === 'password') return;const normalize = text => String(text ?? '').replace(/\s+/g, ' ').trim().toLowerCase();const placeholder = normalize(meta.placeholder);- const written = normalize(typeof response.value === 'string' ? response.value : args?.text);+ // The typed text, whole; an append (clear:false) reads the field's+ // result instead, which the receipt reports shortened.+ const appended = args?.clear === false && typeof response.value === 'string';+ const written = normalize(appended ? response.value : (typeof args?.text === 'string' ? args.text : response.value));if (!placeholder || written !== placeholder) return;const ref = [args?.ref_id, response.ref_id].map(value => String(value || '')).find(value => /^ref_\d+$/.test(value)) || '';- const write = { value: written, ref, name: String(meta.name || ''), id: String(meta.id || '') };+ // Kept in the form the submit probe reports a value: its first 200+ // characters.+ const write = { value: normalize(written.slice(0, 200)), ref, name: String(meta.name || ''), id: String(meta.id || '') };if (!write.ref && !write.name && !write.id) return;const runId = this.currentRunId.get(tabId) || null;this._placeholderWrites ??= new Map();diff --git a/test/placeholder-submit-probe.mjs b/test/placeholder-submit-probe.mjsindex f684d0d45..eee17ba89 100644--- a/test/placeholder-submit-probe.mjs+++ b/test/placeholder-submit-probe.mjs@@ -77,6 +77,21 @@ for (const build of ['chrome', 'firefox']) {assert.equal(result.placeholderFields?.[0]?.name, 'email');assert.equal(result.placeholderFields?.[0]?.changed, true);});++ await t.test('a long prefilled placeholder value the page shipped is not counted as edited', async () => {+ const long = `Describe your request in detail ${'and include every relevant date '.repeat(6)}`.trim();+ await page.setContent('<form method="post" action="/ticket">'+ + `<textarea id="note" name="note" aria-label="Note" placeholder="${long}">${long}</textarea>`+ + `<input id="title" name="title" aria-label="Title" placeholder="${long}" value="${long}"><button id="go">Send</button></form>`);+ const result = await probe('click', { selector: '#go' });+ assert.equal(result?.isSubmit, true);+ assert.ok(long.length > 120);+ assert.deepEqual(result.placeholderFields.map(field => [field.name, field.changed]), [['note', false], ['title', false]]);+ await page.evaluate(text => { document.querySelector('#title').value = `${text} more`; }, long);+ const edited = await probe('click', { selector: '#go' });+ assert.deepEqual(edited.placeholderFields.map(field => [field.name, field.changed]), [['note', false]],+ 'a changed long value no longer equals its placeholder');+ });} finally {await browser.close();}diff --git a/test/run.js b/test/run.jsindex 713405ad0..5fc449a5c 100644--- a/test/run.js+++ b/test/run.js@@ -82779,6 +82779,15 @@ test('a field holding its own placeholder text is not submitted', async () => {await submit('other-field');assert.equal(prompts, 7, `${AgentClass.name}: a write to one field counted for another`);field = { label: 'Email', placeholder: '[email protected]', value: '[email protected]', changed: false, ref: 'ref_101', name: 'email', id: '' };+ // A long typed value is matched by the first 200 characters the probe+ // reports, though the write's receipt shortens what it read back.+ const longText = `Tell us about your project ${'in as much detail as you can '.repeat(8)}`.trim();+ agent.currentRunId.set(tabId, 'long-run');+ agent._rememberPlaceholderWrite(tabId, 'set_field', { ref_id: 'ref_303', text: longText },+ { success: true, value: longText.slice(0, 100), fieldMeta: { type: 'textarea', name: 'about', id: null, placeholder: longText } });+ field = { label: 'About', placeholder: longText.slice(0, 200), value: longText.slice(0, 200), changed: false, ref: 'ref_303', name: 'about', id: '' };+ assert.equal((await submit('long-write')).placeholderValue, true, `${AgentClass.name}: a long write was missed`);+ field = { label: 'Email', placeholder: '[email protected]', value: '[email protected]', changed: false, ref: 'ref_101', name: 'email', id: '' };agent.currentRunId.set(tabId, 'next-run');await submit('next-run');assert.equal(prompts, 8, `${AgentClass.name}: a write from another run still counted`);