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
Iframe tools say how to name a frame host when urlFilter is only a path
Claude8732311ec311
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.jsindex fc380d861..a1ff4396c 100644--- a/src/chrome/src/agent/agent.js+++ b/src/chrome/src/agent/agent.js@@ -128,7 +128,7 @@ import {normalizeCloudflareManagedChallengeState,} from './cloudflare-managed-challenge.js';import { getRecordingStateFresh as recorderStateFresh } from '../recorder/host.js';-import { Capability, CAPABILITY_LABEL, SubmitRisk, capabilitiesFor, classifySearchNavigation, classifySubmitRisk, requiredHosts, frameHostMatches, isNetworkMutation, normalizeHost, registrableHost, PermissionManager, submitActionKey, UNTRUSTED_CONTENT_TOOLS } from './permission-gate.js';+import { Capability, CAPABILITY_LABEL, SubmitRisk, capabilitiesFor, classifySearchNavigation, classifySubmitRisk, requiredHosts, frameHostMatches, urlFilterHostHint, isNetworkMutation, normalizeHost, registrableHost, PermissionManager, submitActionKey, UNTRUSTED_CONTENT_TOOLS } from './permission-gate.js';import {buildPlannerMessages,buildPlannerAlignmentMessages,@@ -45357,11 +45357,12 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dreturn { success: false, dispatched: false, noDispatch: true, error: 'promote_iframe: matchIndex must be a non-negative integer' };}if (matches.length === 0) {+ const hint = urlFilterHostHint(urlFilter, frames.filter(frame => Number(frame?.frameId) !== 0).map(frame => frame?.url));return {success: false,dispatched: false,noDispatch: true,- error: `promote_iframe: no child frame matched urlFilter "${urlFilter}"`,+ error: `promote_iframe: no child frame matched urlFilter "${urlFilter}"${hint ? `. ${hint}` : ''}`,};}if (!hasMatchIndex && matches.length > 1) {@@ -48418,11 +48419,14 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dconst frames = results.map(r => r?.result ? { frameId: r.frameId, ...r.result } : null).filter(r => r && !r.isTop && (!urlFilter || frameHostMatches(r.url, urlFilter) && r.url.includes(urlFilter)));+ const hint = frames.length ? '' : urlFilterHostHint(urlFilter,+ results.map(r => (r?.result && !r.result.isTop ? r.result.url : '')));return {success: true,pageUrl: await this._currentUrl(tabId),frameCount: frames.length,frames,+ ...(hint ? { hint } : {}),};} catch (e) {return { success: false, error: `Iframe read failed: ${e.message}` };@@ -48540,7 +48544,8 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dframeUrls: candidates.map(candidate => candidate.url).slice(0, 10),error: targetCount > 1? 'iframe_click matched multiple elements. Call iframe_read and pass the intended matchIndex or narrow urlFilter before clicking.'- : 'Element not found in any matching iframe',+ : urlFilterHostHint(urlFilter, census.map(item => (item?.frameId !== 0 ? item?.result?.url : '')))+ || 'Element not found in any matching iframe',};}const selected = candidates[0];diff --git a/src/chrome/src/agent/permission-gate.js b/src/chrome/src/agent/permission-gate.jsindex f36ff180e..dcd962cb7 100644--- a/src/chrome/src/agent/permission-gate.js+++ b/src/chrome/src/agent/permission-gate.js@@ -586,6 +586,46 @@ export function frameHostMatches(frameUrl, urlFilter) {return host === want || host.endsWith('.' + want);}+// Whether a urlFilter starts with something that is a host ("stripe.com",+// "127.0.0.1:8080/x", "localhost") rather than a path or a file name+// ("iframe-inner.html", "/embed", "widget").+const FILE_NAME_SUFFIX = /\.(?:html?|xhtml|php|aspx?|jsp|cgi|js|mjs|css|json|xml|txt|svg|png|jpe?g|gif|webp|pdf)$/i;+function urlFilterNamesHost(filter) {+ const first = filter.replace(/^[a-z][a-z0-9+.-]*:\/\//i, '').split(/[/?#]/)[0];+ const host = first.replace(/:\d+$/, '');+ if (!host) return false;+ return /^\[[0-9a-f:.]+\]$/i.test(host) || /^\d{1,3}(?:\.\d{1,3}){3}$/.test(host) || host.toLowerCase() === 'localhost'+ || (/^[a-z0-9-]+(?:\.[a-z0-9-]+)+$/i.test(host) && !FILE_NAME_SUFFIX.test(host));+}++// urlFilter names an iframe's host, optionally followed by more of its URL+// ("stripe.com", "airtable.com/embed/"): target resolution and the permission+// scope both rely on that host. A filter that is only a path or file name+// ("iframe-inner.html") matches no frame; this names the host form that+// would, from the child frames whose address contains it, or returns ''. A+// filter that names a host never gets another host suggested: a page cannot+// turn "stripe.com" into its own frame that merely mentions stripe.com.+export function urlFilterHostHint(urlFilter, frameUrls = []) {+ const filter = String(urlFilter || '').trim();+ if (!filter || urlFilterNamesHost(filter)) return '';+ const examples = [];+ for (const raw of frameUrls || []) {+ const url = String(raw || '');+ if (!url.includes(filter) || frameHostMatches(url, filter)) continue;+ try {+ const parsed = new URL(url);+ if (!['http:', 'https:'].includes(parsed.protocol)) continue;+ const example = `${parsed.host}${parsed.pathname}`.slice(0, 200);+ if (!examples.includes(example)) examples.push(example);+ } catch { /* not an http(s) frame address */ }+ if (examples.length >= 3) break;+ }+ return examples.length+ ? `urlFilter ${JSON.stringify(filter.slice(0, 200))} does not name an iframe host, so no frame matched. `+ + `Start it with the frame's host, for example ${examples.map(example => JSON.stringify(example)).join(' or ')}.`+ : '';+}+/** Resolve a URL (relative / protocol-relative / absolute) to a host against a* base page URL β exactly what the browser handler does (new URL(raw, base)). */function resolveHostAgainst(url, base) {diff --git a/src/chrome/src/agent/rich-text-toolbar-probe.js b/src/chrome/src/agent/rich-text-toolbar-probe.jsindex da55a65b7..ffdd40d76 100644--- a/src/chrome/src/agent/rich-text-toolbar-probe.js+++ b/src/chrome/src/agent/rich-text-toolbar-probe.js@@ -1,5 +1,5 @@import { cdpClient } from '../cdp/cdp-client.js';-import { frameHostMatches } from './permission-gate.js';+import { frameHostMatches, urlFilterHostHint } from './permission-gate.js';import { richTextToolbarUsesFocusedTarget } from './rich-text-toolbar-guard.js';import { secureRandomBase36Token } from './random-token.js';@@ -229,7 +229,8 @@ export class RichTextToolbarProbe {candidates: candidates.map(frame => ({ frameId: frame.frameId, url: frame.url, elementCount: frame.matchCount })).slice(0, 10),error: targetCount > 1? `The iframe selector matched ${targetCount} elements, so nothing was typed. Call iframe_read with this selector and retry with the intended matchIndex.`- : 'Input not found in any matching iframe',+ : urlFilterHostHint(urlFilter, counted.map(entry => (entry?.result && !entry.result.isTop ? entry.result.url : '')))+ || 'Input not found in any matching iframe',};}const selected = candidates[0];diff --git a/src/chrome/src/agent/tools.js b/src/chrome/src/agent/tools.jsindex a63e31bc4..beb44b5ab 100644--- a/src/chrome/src/agent/tools.js+++ b/src/chrome/src/agent/tools.js@@ -885,7 +885,7 @@ export const AGENT_TOOLS = [parameters: {type: 'object',properties: {- urlFilter: { type: 'string', description: 'Required iframe host or URL substring, for example "airtable.com/embed/".' },+ urlFilter: { type: 'string', description: 'Required iframe host, optionally followed by more of its URL, for example "airtable.com/embed/". A file name without its host, such as "embed.html", matches no frame.' },matchIndex: { type: 'number', description: 'Zero-based matching-frame index. Omit unless promote_iframe reports several candidate frame URLs.' },force: { type: 'boolean', description: 'Discard unsaved state on the current page before promotion. Default false; use only when the user explicitly intends to discard it.' },},@@ -1026,7 +1026,7 @@ export const AGENT_TOOLS = [parameters: {type: 'object',properties: {- urlFilter: { type: 'string', description: 'Optional substring to filter frames by URL (e.g. "stripe.com" to only read Stripe iframes). Omit to read all frames.' },+ urlFilter: { type: 'string', description: 'Optional iframe host, optionally followed by more of its URL (e.g. "stripe.com" to only read Stripe iframes). A file name without its host matches no frame. Omit to read all frames.' },selector: { type: 'string', description: 'Optional CSS selector to extract specific elements within each frame. Omit to get the full body text.' },limit: { type: 'number', description: 'Maximum matching elements returned per frame. Default 25; maximum 50.' },offset: { type: 'number', description: 'Zero-based index of the first match returned per frame. Continue a truncated inventory by passing the returned nextOffset with the identical selector.' },@@ -1043,7 +1043,7 @@ export const AGENT_TOOLS = [parameters: {type: 'object',properties: {- urlFilter: { type: 'string', description: 'Required iframe host or URL substring (e.g. "stripe.com"). This scopes both target resolution and the permission gate.' },+ urlFilter: { type: 'string', description: 'Required iframe host, optionally followed by more of its URL (e.g. "stripe.com", "airtable.com/embed/"). This scopes both target resolution and the permission gate, so a file name without its host, such as "embed.html", matches no frame.' },selector: { type: 'string', description: 'CSS selector for the element to click inside the iframe.' },matchIndex: { type: 'number', description: 'Zero-based element index from iframe_read. Omit only when the selector uniquely matches one element across the selected frames.' },},@@ -1059,7 +1059,7 @@ export const AGENT_TOOLS = [parameters: {type: 'object',properties: {- urlFilter: { type: 'string', description: 'Required iframe host or URL substring. This scopes both target resolution and the permission gate.' },+ urlFilter: { type: 'string', description: 'Required iframe host, optionally followed by more of its URL. This scopes both target resolution and the permission gate, so a file name without its host, such as "embed.html", matches no frame.' },selector: { type: 'string', description: 'CSS selector for the input element inside the iframe.' },matchIndex: { type: 'number', description: 'Zero-based element index from iframe_read. Omit only when the selector uniquely matches one element across the selected frames.' },text: { type: 'string', description: 'Text to type into the field.' },@@ -2396,7 +2396,7 @@ IFRAMES β read this:- \`iframe_click({urlFilter, selector, matchIndex})\` clicks exactly one element and refuses ambiguous matches.- \`iframe_type({urlFilter, selector, matchIndex, text, clear})\` types into exactly one form field and refuses ambiguous matches.- If the embedded UI remains unreliable and no fields have been changed, call \`promote_iframe({urlFilter})\` to navigate the current run tab to that frame's standalone URL. After any iframe form edits, call \`verify_form({urlFilter})\` and compare labels/values before done, even when the user will submit later.-- The \`urlFilter\` parameter is a substring match against the iframe's URL. Use it to disambiguate when multiple iframes are present (e.g. \`urlFilter: "stripe.com"\` to target a Stripe widget specifically).+- The \`urlFilter\` parameter names the iframe's host, optionally followed by more of its URL (e.g. \`urlFilter: "stripe.com"\` to target a Stripe widget, or \`"airtable.com/embed/"\`); it also scopes the permission check. A file name without its host, such as \`"embed.html"\`, matches no frame. Use it to disambiguate when multiple iframes are present.- Coordinate clicks via \`click({x, y, coordinate_space:"screenshot", capture_id:"..."})\` ALSO work inside iframes β they dispatch at the OS level via CDP and don't care about origin boundaries β but selector-based iframe tools are more reliable.- DO NOT refuse a task by saying "I can't access cross-origin iframes" or "Stripe's security restrictions prevent this". Those refusals are wrong in this environment. Try the iframe tools instead.diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.jsindex d993e493a..3e05c7307 100644--- a/src/firefox/src/agent/agent.js+++ b/src/firefox/src/agent/agent.js@@ -120,7 +120,7 @@ import {cloudflareManagedChallengeStorageKey,normalizeCloudflareManagedChallengeState,} from './cloudflare-managed-challenge.js';-import { Capability, CAPABILITY_LABEL, SubmitRisk, capabilitiesFor, classifySearchNavigation, classifySubmitRisk, requiredHosts, frameHostMatches, isNetworkMutation, normalizeHost, registrableHost, PermissionManager, submitActionKey, UNTRUSTED_CONTENT_TOOLS } from './permission-gate.js';+import { Capability, CAPABILITY_LABEL, SubmitRisk, capabilitiesFor, classifySearchNavigation, classifySubmitRisk, requiredHosts, frameHostMatches, urlFilterHostHint, isNetworkMutation, normalizeHost, registrableHost, PermissionManager, submitActionKey, UNTRUSTED_CONTENT_TOOLS } from './permission-gate.js';import {buildPlannerMessages,buildPlannerAlignmentMessages,@@ -41097,11 +41097,12 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dreturn { success: false, dispatched: false, noDispatch: true, error: 'promote_iframe: matchIndex must be a non-negative integer' };}if (matches.length === 0) {+ const hint = urlFilterHostHint(urlFilter, frames.filter(frame => Number(frame?.frameId) !== 0).map(frame => frame?.url));return {success: false,dispatched: false,noDispatch: true,- error: `promote_iframe: no child frame matched urlFilter "${urlFilter}"`,+ error: `promote_iframe: no child frame matched urlFilter "${urlFilter}"${hint ? `. ${hint}` : ''}`,};}if (!hasMatchIndex && matches.length > 1) {@@ -44513,11 +44514,14 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d}));const frames = inspected.filter(r => r && !r.isTop&& (!urlFilter || (frameHostMatches(r.url, urlFilter) && r.url.includes(urlFilter))));+ const hint = frames.length ? '' : urlFilterHostHint(urlFilter,+ frameInfos.filter(frame => frame.frameId !== 0).map(frame => frame.url));return {success: true,pageUrl: await this._currentUrl(tabId),frameCount: frames.length,frames,+ ...(hint ? { hint } : {}),};} catch (e) {return { success: false, error: `Iframe read failed: ${e.message}` };@@ -44630,7 +44634,8 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout dframeUrls: candidates.map(candidate => candidate.url).slice(0, 10),error: targetCount > 1? 'iframe_click matched multiple elements. Call iframe_read and pass the intended matchIndex or narrow urlFilter before clicking.'- : 'Element not found in any matching iframe',+ : urlFilterHostHint(urlFilter, frames.filter(frame => frame.frameId !== 0).map(frame => frame.url))+ || 'Element not found in any matching iframe',};}const selected = candidates[0];diff --git a/src/firefox/src/agent/permission-gate.js b/src/firefox/src/agent/permission-gate.jsindex f795ac312..a03fe4caf 100644--- a/src/firefox/src/agent/permission-gate.js+++ b/src/firefox/src/agent/permission-gate.js@@ -571,6 +571,46 @@ export function frameHostMatches(frameUrl, urlFilter) {return host === want || host.endsWith('.' + want);}+// Whether a urlFilter starts with something that is a host ("stripe.com",+// "127.0.0.1:8080/x", "localhost") rather than a path or a file name+// ("iframe-inner.html", "/embed", "widget").+const FILE_NAME_SUFFIX = /\.(?:html?|xhtml|php|aspx?|jsp|cgi|js|mjs|css|json|xml|txt|svg|png|jpe?g|gif|webp|pdf)$/i;+function urlFilterNamesHost(filter) {+ const first = filter.replace(/^[a-z][a-z0-9+.-]*:\/\//i, '').split(/[/?#]/)[0];+ const host = first.replace(/:\d+$/, '');+ if (!host) return false;+ return /^\[[0-9a-f:.]+\]$/i.test(host) || /^\d{1,3}(?:\.\d{1,3}){3}$/.test(host) || host.toLowerCase() === 'localhost'+ || (/^[a-z0-9-]+(?:\.[a-z0-9-]+)+$/i.test(host) && !FILE_NAME_SUFFIX.test(host));+}++// urlFilter names an iframe's host, optionally followed by more of its URL+// ("stripe.com", "airtable.com/embed/"): target resolution and the permission+// scope both rely on that host. A filter that is only a path or file name+// ("iframe-inner.html") matches no frame; this names the host form that+// would, from the child frames whose address contains it, or returns ''. A+// filter that names a host never gets another host suggested: a page cannot+// turn "stripe.com" into its own frame that merely mentions stripe.com.+export function urlFilterHostHint(urlFilter, frameUrls = []) {+ const filter = String(urlFilter || '').trim();+ if (!filter || urlFilterNamesHost(filter)) return '';+ const examples = [];+ for (const raw of frameUrls || []) {+ const url = String(raw || '');+ if (!url.includes(filter) || frameHostMatches(url, filter)) continue;+ try {+ const parsed = new URL(url);+ if (!['http:', 'https:'].includes(parsed.protocol)) continue;+ const example = `${parsed.host}${parsed.pathname}`.slice(0, 200);+ if (!examples.includes(example)) examples.push(example);+ } catch { /* not an http(s) frame address */ }+ if (examples.length >= 3) break;+ }+ return examples.length+ ? `urlFilter ${JSON.stringify(filter.slice(0, 200))} does not name an iframe host, so no frame matched. `+ + `Start it with the frame's host, for example ${examples.map(example => JSON.stringify(example)).join(' or ')}.`+ : '';+}+/** Resolve a URL (relative / protocol-relative / absolute) to a host against a* base page URL β exactly what the browser handler does (new URL(raw, base)). */function resolveHostAgainst(url, base) {diff --git a/src/firefox/src/agent/rich-text-toolbar-probe.js b/src/firefox/src/agent/rich-text-toolbar-probe.jsindex 5fd560361..1a0b93778 100644--- a/src/firefox/src/agent/rich-text-toolbar-probe.js+++ b/src/firefox/src/agent/rich-text-toolbar-probe.js@@ -1,4 +1,4 @@-import { frameHostMatches } from './permission-gate.js';+import { frameHostMatches, urlFilterHostHint } from './permission-gate.js';import { richTextToolbarUsesFocusedTarget } from './rich-text-toolbar-guard.js';import { secureRandomBase36Token } from './random-token.js';@@ -233,7 +233,8 @@ export class RichTextToolbarProbe {candidates: candidates.map(frame => ({ frameId: frame.frameId, url: frame.url, elementCount: frame.matchCount })).slice(0, 10),error: targetCount > 1? `The iframe selector matched ${targetCount} elements, so nothing was typed. Call iframe_read with this selector and retry with the intended matchIndex.`- : 'Input not found in any matching iframe',+ : urlFilterHostHint(urlFilter, (navigationFrames || []).filter(frame => frame?.frameId !== 0).map(frame => frame?.url))+ || 'Input not found in any matching iframe',};}const selected = candidates[0];diff --git a/src/firefox/src/agent/tools.js b/src/firefox/src/agent/tools.jsindex f11f45f79..cad46b3d0 100644--- a/src/firefox/src/agent/tools.js+++ b/src/firefox/src/agent/tools.js@@ -747,7 +747,7 @@ export const AGENT_TOOLS = [parameters: {type: 'object',properties: {- urlFilter: { type: 'string', description: 'Required iframe host or URL substring, for example "airtable.com/embed/".' },+ urlFilter: { type: 'string', description: 'Required iframe host, optionally followed by more of its URL, for example "airtable.com/embed/". A file name without its host, such as "embed.html", matches no frame.' },matchIndex: { type: 'number', description: 'Zero-based matching-frame index. Omit unless promote_iframe reports several candidate frame URLs.' },force: { type: 'boolean', description: 'Discard unsaved state on the current page before promotion. Default false; use only when the user explicitly intends to discard it.' },},@@ -873,7 +873,7 @@ export const AGENT_TOOLS = [parameters: {type: 'object',properties: {- urlFilter: { type: 'string', description: 'Optional substring to filter frames by URL (e.g. "stripe.com").' },+ urlFilter: { type: 'string', description: 'Optional iframe host, optionally followed by more of its URL (e.g. "stripe.com"). A file name without its host matches no frame.' },selector: { type: 'string', description: 'Optional CSS selector to extract specific elements within each frame.' },limit: { type: 'number', description: 'Maximum matching elements returned per frame. Default 25; maximum 50.' },offset: { type: 'number', description: 'Zero-based index of the first match returned per frame. Continue a truncated inventory by passing the returned nextOffset with the identical selector.' },@@ -890,7 +890,7 @@ export const AGENT_TOOLS = [parameters: {type: 'object',properties: {- urlFilter: { type: 'string', description: 'Required iframe host or URL substring. This scopes both target resolution and the permission gate.' },+ urlFilter: { type: 'string', description: 'Required iframe host, optionally followed by more of its URL. This scopes both target resolution and the permission gate, so a file name without its host, such as "embed.html", matches no frame.' },selector: { type: 'string', description: 'CSS selector for the element to click inside the iframe.' },matchIndex: { type: 'number', description: 'Zero-based element index from iframe_read. Omit only when the selector uniquely matches one element across the selected frames.' },},@@ -906,7 +906,7 @@ export const AGENT_TOOLS = [parameters: {type: 'object',properties: {- urlFilter: { type: 'string', description: 'Required iframe host or URL substring. This scopes both target resolution and the permission gate.' },+ urlFilter: { type: 'string', description: 'Required iframe host, optionally followed by more of its URL. This scopes both target resolution and the permission gate, so a file name without its host, such as "embed.html", matches no frame.' },selector: { type: 'string', description: 'CSS selector for the input element inside the iframe.' },matchIndex: { type: 'number', description: 'Zero-based element index from iframe_read. Omit only when the selector uniquely matches one element across the selected frames.' },text: { type: 'string', description: 'Text to type into the field.' },@@ -2251,7 +2251,7 @@ IFRAMES β read this:- \`iframe_click({urlFilter, selector, matchIndex})\` clicks exactly one element and refuses ambiguous matches.- \`iframe_type({urlFilter, selector, matchIndex, text, clear})\` types into exactly one form field and refuses ambiguous matches.- If the embedded UI remains unreliable and no fields have been changed, call \`promote_iframe({urlFilter})\` to navigate the current run tab to that frame's standalone URL. After any iframe form edits, call \`verify_form({urlFilter})\` and compare labels/values before done, even when the user will submit later.-- The \`urlFilter\` parameter is a substring match against the iframe's URL. Use it to disambiguate when multiple iframes are present (e.g. \`urlFilter: "stripe.com"\` to target a Stripe widget specifically).+- The \`urlFilter\` parameter names the iframe's host, optionally followed by more of its URL (e.g. \`urlFilter: "stripe.com"\` to target a Stripe widget, or \`"airtable.com/embed/"\`); it also scopes the permission check. A file name without its host, such as \`"embed.html"\`, matches no frame. Use it to disambiguate when multiple iframes are present.- DO NOT refuse a task by saying "I can't access cross-origin iframes" or "Stripe's security restrictions prevent this". Those refusals are wrong in this environment. Try the iframe tools instead.TYPING β read this:diff --git a/test/run.js b/test/run.jsindex e46604a6c..467216987 100644--- a/test/run.js+++ b/test/run.js@@ -2553,6 +2553,61 @@ test('rich-text frame geometry uses wildcard delivery only for known opaque sand}});+test('iframe tools say how to name a frame host when urlFilter is only a path', async () => {+ const originalChrome = globalThis.chrome;+ const originalBrowser = globalThis.browser;+ const frameUrl = 'http://127.0.0.1:47615/iframe-inner.html';+ try {+ for (const build of ['chrome', 'firefox']) {+ const gate = await import(pathToFileURL(path.join(ROOT, `src/${build}/src/agent/permission-gate.js`)).href);+ const hint = gate.urlFilterHostHint('iframe-inner.html', ['http://127.0.0.1:47615/', frameUrl, 'about:blank', frameUrl]);+ assert.equal(hint, 'urlFilter "iframe-inner.html" does not name an iframe host, so no frame matched. '+ + 'Start it with the frame\'s host, for example "127.0.0.1:47615/iframe-inner.html".', `${build}: path-only filter hint`);+ // The suggested filter matches, so the hint is never a dead end.+ assert.equal(gate.frameHostMatches(frameUrl, '127.0.0.1:47615/iframe-inner.html') && frameUrl.includes('127.0.0.1:47615/iframe-inner.html'), true);+ assert.match(gate.urlFilterHostHint('embed', ['https://forms.example/embed/v2']), /for example "forms\.example\/embed\/v2"/);+ // No hint when the filter names a host (even one no frame has: a page+ // cannot steer "stripe.com" to its own frame that mentions it), when+ // nothing contains the filter, or without a filter.+ for (const [filter, urls] of [['127.0.0.1:47615', [frameUrl]], ['missing.html', [frameUrl]], ['', [frameUrl]],+ ['stripe.com', ['https://evil.example/?next=stripe.com', 'https://evil.example/stripe.com/pay']],+ ['localhost:3000', ['https://evil.example/localhost:3000']], ['[::1]', ['https://evil.example/[::1]']]]) {+ assert.equal(gate.urlFilterHostHint(filter, urls), '', `${build}: ${filter || '(empty)'}`);+ }+ // iframe_type answers a path-only filter with the same hint, before anything is typed.+ const execute = async () => (build === 'chrome'+ ? [{ frameId: 0, result: { ok: true, url: 'http://127.0.0.1:47615/', isTop: true, matchCount: 0 } },+ { frameId: 9, result: { ok: true, url: frameUrl, isTop: false, matchCount: 1 } }]+ : [{ ok: true, url: frameUrl, matchCount: 1 }]);+ globalThis.chrome = build === 'chrome' ? { scripting: { executeScript: execute } } : originalChrome;+ globalThis.browser = build === 'firefox'+ ? { webNavigation: { getAllFrames: async () => [{ frameId: 0, parentFrameId: -1, url: 'http://127.0.0.1:47615/' },+ { frameId: 9, parentFrameId: 0, url: frameUrl }] }, tabs: { executeScript: execute } }+ : originalBrowser;+ const { RichTextToolbarProbe } = await import(`${pathToFileURL(path.join(ROOT, `src/${build}/src/agent/rich-text-toolbar-probe.js`)).href}?url-filter-hint=${build}`);+ const typed = await new RichTextToolbarProbe({}).legacyIframeTypeAllFrames(77, {+ selector: '#ref', text: 'WB-QA-B2', clear: true, urlFilter: 'iframe-inner.html',+ }, { beforeDispatch: async () => assert.fail(`${build}: nothing may be typed`) });+ assert.equal(typed.success, false);+ assert.equal(typed.noDispatch, true);+ assert.match(typed.error, /does not name an iframe host[\s\S]*"127\.0\.0\.1:47615\/iframe-inner\.html"/, `${build}: iframe_type hint`);+ }+ for (const build of ['chrome', 'firefox']) {+ const agent = fs.readFileSync(path.join(ROOT, `src/${build}/src/agent/agent.js`), 'utf8');+ assert.match(agent, /: urlFilterHostHint\(urlFilter, [^\n]+\)\n\s*\|\| 'Element not found in any matching iframe',/, `${build}: iframe_click hint`);+ assert.match(agent, /const hint = urlFilterHostHint\(urlFilter, frames\.filter\(frame => Number\(frame\?\.frameId\) !== 0\)\.map\(frame => frame\?\.url\)\);[\s\S]{0,240}promote_iframe: no child frame matched urlFilter "\$\{urlFilter\}"\$\{hint \? `\. \$\{hint\}` : ''\}`/, `${build}: promote_iframe hint`);+ assert.match(agent, /const hint = frames\.length \? '' : urlFilterHostHint\(urlFilter,[\s\S]{0,400}\.\.\.\(hint \? \{ hint \} : \{\}\),/, `${build}: iframe_read hint`);+ const tools = fs.readFileSync(path.join(ROOT, `src/${build}/src/agent/tools.js`), 'utf8');+ assert.doesNotMatch(tools, /urlFilter[^\n]*(?:host or URL substring|substring to filter frames|substring match against the iframe)/, `${build}: no tool still calls urlFilter a plain substring`);+ }+ } finally {+ if (originalChrome === undefined) delete globalThis.chrome;+ else globalThis.chrome = originalChrome;+ if (originalBrowser === undefined) delete globalThis.browser;+ else globalThis.browser = originalBrowser;+ }+});+test('legacy iframe typing marks background dispatch only for its mutation phase', async () => {const originalChrome = globalThis.chrome;const originalBrowser = globalThis.browser;