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
observe submitter form association changes
Barack Sokulluee128e6198c4
diff --git a/src/chrome/src/content/page-monitor.js b/src/chrome/src/content/page-monitor.jsindex 1f14b73bd..d4a14139c 100644--- a/src/chrome/src/content/page-monitor.js+++ b/src/chrome/src/content/page-monitor.js@@ -379,7 +379,7 @@[size + length, (Math.imul(hash, power) + part) >>> 0], [0, 0]);const controlValue = controlValueFingerprint(el);return JSON.stringify([shown, content, el.children.length + (el.shadowRoot?.children.length || 0), el.getAttribute('role'), el.getAttribute('aria-label'),- el.getAttribute('id'), el.getAttribute('for'), el.getAttribute('name'), el.getAttribute('placeholder'), el.getAttribute('title'), el.getAttribute('alt'),+ el.getAttribute('id'), el.getAttribute('for'), el.getAttribute('form'), el.getAttribute('name'), el.getAttribute('placeholder'), el.getAttribute('title'), el.getAttribute('alt'),el.getAttribute('aria-labelledby'), el.getAttribute('aria-required'), el.getAttribute('aria-readonly'),el.getAttribute('contenteditable'), el.getAttribute('tabindex'), el.getAttribute('onclick'), el.getAttribute('required'),el.getAttribute('aria-expanded'), el.getAttribute('aria-selected'), el.getAttribute('aria-checked'),@@ -459,7 +459,7 @@if (!root || roots.has(root) || !observer) return;roots.add(root);observer.observe(root, { childList: true, subtree: true, characterData: true, attributes: true, attributeOldValue: true,- attributeFilter: ['role', 'aria-label', 'id', 'for', 'name', 'placeholder', 'title', 'alt', 'aria-labelledby',+ attributeFilter: ['role', 'aria-label', 'id', 'for', 'form', 'name', 'placeholder', 'title', 'alt', 'aria-labelledby','aria-required', 'aria-readonly', 'contenteditable', 'tabindex', 'onclick', 'required','aria-expanded', 'aria-selected', 'aria-checked', 'aria-pressed', 'aria-disabled','type', 'href', 'target', 'download', 'action', 'method', 'formaction', 'formmethod', 'formtarget',diff --git a/src/firefox/src/content/page-monitor.js b/src/firefox/src/content/page-monitor.jsindex 1f14b73bd..d4a14139c 100644--- a/src/firefox/src/content/page-monitor.js+++ b/src/firefox/src/content/page-monitor.js@@ -379,7 +379,7 @@[size + length, (Math.imul(hash, power) + part) >>> 0], [0, 0]);const controlValue = controlValueFingerprint(el);return JSON.stringify([shown, content, el.children.length + (el.shadowRoot?.children.length || 0), el.getAttribute('role'), el.getAttribute('aria-label'),- el.getAttribute('id'), el.getAttribute('for'), el.getAttribute('name'), el.getAttribute('placeholder'), el.getAttribute('title'), el.getAttribute('alt'),+ el.getAttribute('id'), el.getAttribute('for'), el.getAttribute('form'), el.getAttribute('name'), el.getAttribute('placeholder'), el.getAttribute('title'), el.getAttribute('alt'),el.getAttribute('aria-labelledby'), el.getAttribute('aria-required'), el.getAttribute('aria-readonly'),el.getAttribute('contenteditable'), el.getAttribute('tabindex'), el.getAttribute('onclick'), el.getAttribute('required'),el.getAttribute('aria-expanded'), el.getAttribute('aria-selected'), el.getAttribute('aria-checked'),@@ -459,7 +459,7 @@if (!root || roots.has(root) || !observer) return;roots.add(root);observer.observe(root, { childList: true, subtree: true, characterData: true, attributes: true, attributeOldValue: true,- attributeFilter: ['role', 'aria-label', 'id', 'for', 'name', 'placeholder', 'title', 'alt', 'aria-labelledby',+ attributeFilter: ['role', 'aria-label', 'id', 'for', 'form', 'name', 'placeholder', 'title', 'alt', 'aria-labelledby','aria-required', 'aria-readonly', 'contenteditable', 'tabindex', 'onclick', 'required','aria-expanded', 'aria-selected', 'aria-checked', 'aria-pressed', 'aria-disabled','type', 'href', 'target', 'download', 'action', 'method', 'formaction', 'formmethod', 'formtarget',diff --git a/test/page-monitor-ui.mjs b/test/page-monitor-ui.mjsindex 997f562c5..da1fa78da 100644--- a/test/page-monitor-ui.mjs+++ b/test/page-monitor-ui.mjs@@ -1964,6 +1964,33 @@ for (const [build, engine] of [['chrome', chromium], ['firefox', firefox]]) {} finally { await browser.close(); }});+ test(`${build}: submitter form association changes invalidate a prepared click`, async () => {+ const { browser, page } = await fixture(engine, build);+ try {+ await page.evaluate(() => {+ const first = document.createElement('form'); first.id = 'first-submit-form';+ const second = document.createElement('form'); second.id = 'second-submit-form';+ const button = document.createElement('button');+ button.id = 'associated-submit'; button.type = 'submit'; button.setAttribute('form', first.id); button.textContent = 'Save';+ document.body.append(first, second, button);+ });+ await page.waitForTimeout(120);++ const guard = await page.evaluate(() => {+ feedback = [];+ deliver('page_monitor_prepare', { operationId: 'submit-form-association', tool: 'click', selector: '#associated-submit' });+ deliver('page_monitor_dispatch', { operationId: 'submit-form-association', kind: 'click', selector: '#associated-submit' });+ return lastMonitorResponse.guard;+ });+ await page.locator('#associated-submit').evaluate(button => button.setAttribute('form', 'second-submit-form'));+ await page.waitForFunction(() => feedback.some(event => event.kind === 'dom' && event.target === 'button#associated-submit'));+ const accepted = await page.evaluate(value => window.dispatchEvent(new CustomEvent('webbrain-agent-dom-dispatch', {+ detail: JSON.stringify({ ...value, dispatchPhase: 'focus' }), cancelable: true,+ })), guard);+ assert.equal(accepted, false, 'Reassociating a submitter must invalidate the prepared click guard');+ } finally { await browser.close(); }+ });+test(`${build}: hidden native label changes invalidate visible control clicks`, async () => {const { browser, page } = await fixture(engine, build);try {