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
fix page feedback frame and state monitoring
Barack Sokullu852d3f3bf1ed
diff --git a/src/chrome/src/agent/page-feedback.js b/src/chrome/src/agent/page-feedback.jsindex 9ca01b5ec..e18502050 100644--- a/src/chrome/src/agent/page-feedback.js+++ b/src/chrome/src/agent/page-feedback.js@@ -6,7 +6,7 @@ const clean = (value, limit = 240) => String(value ?? '').replace(/[\u0000-\u001const token = () => globalThis.crypto.randomUUID();const apiFor = () => globalThis.browser || globalThis.chrome;-async function notifyPageMonitorFrames(api, tabId, message, knownFrames = []) {+async function notifyPageMonitorFrames(api, tabId, message, knownFrames = [], onFrame = null) {if (!api?.tabs?.sendMessage) return;const frameIds = new Set([0, ...knownFrames]);let enumerated = false;@@ -14,7 +14,10 @@ async function notifyPageMonitorFrames(api, tabId, message, knownFrames = []) {const frames = await api.webNavigation?.getAllFrames?.({ tabId });if (Array.isArray(frames)) {enumerated = true;- for (const frame of frames) if (Number.isSafeInteger(frame.frameId) && frame.frameId >= 0) frameIds.add(frame.frameId);+ for (const frame of frames) if (Number.isSafeInteger(frame.frameId) && frame.frameId >= 0) {+ frameIds.add(frame.frameId);+ onFrame?.(frame);+ }}} catch { /* Restricted documents may not expose their frame tree. */ }// A broadcast reaches every frame but resolves on the first response. Address@@ -136,7 +139,10 @@ export const pageFeedbackMethods = {} });const api = apiFor();try { run.url = (await api.tabs.get(tabId)).url || ''; } catch {}- await notifyPageMonitorFrames(api, tabId, { target: 'content', action: 'page_monitor_state', active: true }, run.frames.keys());+ await notifyPageMonitorFrames(api, tabId, { target: 'content', action: 'page_monitor_state', active: true }, run.frames.keys(), frame => {+ run.documents.set(frame.frameId, { id: frame.documentId || '', url: frame.url || '',+ parentFrameId: Number.isSafeInteger(frame.parentFrameId) ? frame.parentFrameId : undefined });+ });},_finishPageFeedbackRun(tabId) {@@ -153,7 +159,7 @@ export const pageFeedbackMethods = {active: false, runToken: run.token }, run.frames.keys()).catch(() => {});},- pageMonitorState(sender, documentToken) {+ pageMonitorState(sender, documentToken, frameName = '') {const tabId = sender?.tab?.id;const run = this._pageFeedbackRuns?.get(tabId);if (!run || !this.isRunning(tabId) || this._checkAbort(tabId) || typeof documentToken !== 'string'@@ -165,8 +171,9 @@ export const pageFeedbackMethods = {const previous = run.frames.get(frameId);if (previous && previous.token !== documentToken) run.gestures.delete(frameId);if (!previous || previous.token !== documentToken) {- run.frames.set(frameId, { token: documentToken, id: sender.documentId || '', seq: 0 });- }+ run.frames.set(frameId, { token: documentToken, id: sender.documentId || '', seq: 0,+ name: clean(frameName, 256) });+ } else previous.name = clean(frameName, 256);return { active: true, runToken: run.token, documentToken };},@@ -194,8 +201,23 @@ export const pageFeedbackMethods = {url = destination.href;}} catch { /* Clicks without a safe, concrete destination cannot correlate navigation. */ }- run.navigation = url ? { at: Date.now(), url, kind: 'click',- frameId: feedback.navigationTarget === '_top' ? 0 : frameId,+ const target = String(feedback.navigationTarget || '').toLowerCase();+ let destinationFrameId;+ if (target === '_blank') destinationFrameId = undefined;+ else if (target === '_top') destinationFrameId = 0;+ else if (target === '_parent') {+ const parentFrameId = run.documents.get(frameId)?.parentFrameId;+ destinationFrameId = frameId === 0 ? 0 : Number.isSafeInteger(parentFrameId) && parentFrameId >= 0 ? parentFrameId : undefined;+ } else if (target === '_self') destinationFrameId = frameId;+ else {+ const requestedName = clean(feedback.navigationTargetName, 256);+ if (requestedName) {+ const matches = [...run.frames].filter(([, entry]) => entry.name === requestedName);+ if (matches.length === 1) destinationFrameId = matches[0][0];+ } else if (!target) destinationFrameId = frameId;+ }+ run.navigation = url && Number.isSafeInteger(destinationFrameId) ? { at: Date.now(), url, kind: 'click',+ frameId: destinationFrameId,...(feedback.navigationFormGet === true ? { formGet: true } : {}),operationId: dispatchOwners.get(tabId)?.operationId || '' } : null;}@@ -227,10 +249,11 @@ export const pageFeedbackMethods = {if (type === 'committed') {run.frames.delete(frameId);run.gestures.delete(frameId);- run.documents.set(frameId, { id: details.documentId || '', url: details.url || '' });+ run.documents.set(frameId, { id: details.documentId || '', url: details.url || '',+ parentFrameId: Number.isSafeInteger(details.parentFrameId) ? details.parentFrameId : undefined });if (frameId === 0) {run.frames.clear(); run.gestures.clear(); run.documents.clear();- run.documents.set(0, { id: details.documentId || '', url: details.url || '' });+ run.documents.set(0, { id: details.documentId || '', url: details.url || '', parentFrameId: -1 });}}const before = frameId === 0 ? run.url : '';diff --git a/src/chrome/src/background.js b/src/chrome/src/background.jsindex b79a227d4..74d0271be 100644--- a/src/chrome/src/background.js+++ b/src/chrome/src/background.js@@ -2840,7 +2840,7 @@ chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {});async function handleMessage(msg, sender) {- if (msg.action === 'get_page_monitor_state') return agent.pageMonitorState(sender, msg.documentToken);+ if (msg.action === 'get_page_monitor_state') return agent.pageMonitorState(sender, msg.documentToken, msg.frameName);if (msg.action === 'page_feedback') return agent.observePageFeedback(sender, msg.feedback);if (msg.action === 'chat_steer') {diff --git a/src/chrome/src/content/page-monitor.js b/src/chrome/src/content/page-monitor.jsindex 78b700d84..067491118 100644--- a/src/chrome/src/content/page-monitor.js+++ b/src/chrome/src/content/page-monitor.js@@ -27,6 +27,7 @@let active = false, disposed = false, runToken = '', seq = 0, revision = 0;let observer = null, layoutObserver = null, domTimer = null, scrollTimer = null, controlTimer = null, lastUserAt = 0;let pointerHeld = false, composing = false, localOperation = null, controlIterator = null;+ let preparedOperationCursor = 0;let requestGeneration = 0, unreported = 0, pendingDOM = null;let lastViewport = '';let lastFeedbackDelivery = Promise.resolve();@@ -385,7 +386,7 @@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'),+ el.getAttribute('aria-expanded'), el.getAttribute('aria-selected'), el.getAttribute('aria-checked'), el.getAttribute('data-selected'),el.getAttribute('aria-valuenow'), el.getAttribute('aria-valuetext'),el.getAttribute('aria-pressed'),el.getAttribute('type'),@@ -434,10 +435,32 @@}if (records.length) onMutations(records);}- function flushPendingMutations() {+ function samplePreparedTargets(onlyOperation) {+ if (!active) return;+ const now = Date.now();+ const candidates = onlyOperation ? [onlyOperation] : [...operations.values()]+ .filter(op => !op.dispatched && op.target && op.preparedTargetSignature !== undefined && op.until >= now);+ if (!onlyOperation && candidates.length > 128) {+ const start = preparedOperationCursor % candidates.length;+ const batch = Array.from({ length: 128 }, (_, index) => candidates[(start + index) % candidates.length]);+ preparedOperationCursor = (start + batch.length) % candidates.length;+ candidates.splice(0, candidates.length, ...batch);+ }+ const changedTargets = new Set();+ for (const op of candidates) {+ if (!op || op.dispatched || !op.target || op.preparedTargetSignature === undefined) continue;+ const current = signature(op.target);+ if (current === op.preparedTargetSignature) continue;+ op.preparedTargetSignature = current;+ changedTargets.add(op.target);+ }+ if (changedTargets.size) onMutations([...changedTargets].map(target => ({ type: 'prepared-style', target })));+ }+ function flushPendingMutations(onlyOperation) {if (!active || !observer) return;const records = observer.takeRecords();if (records.length) onMutations(records);+ samplePreparedTargets(onlyOperation);}function sampleDescendants(root, limit = 100) {const nodes = [];@@ -465,7 +488,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', 'form', 'name', 'placeholder', 'title', 'alt', 'aria-labelledby', 'rel', 'media',+ attributeFilter: ['role', 'aria-label', 'id', 'for', 'form', 'name', 'placeholder', 'title', 'alt', 'aria-labelledby', 'rel', 'media', 'data-selected','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',@@ -625,7 +648,8 @@};const changes = [...records];for (const record of records) {- if (record.type !== 'popover' && (record.type !== 'attributes' || !['class', 'style', 'hidden', 'aria-hidden', 'open', 'inert', 'selected'].includes(record.attributeName))) continue;+ if (record.type !== 'popover' && record.type !== 'prepared-style'+ && (record.type !== 'attributes' || !['class', 'style', 'hidden', 'aria-hidden', 'open', 'inert', 'selected'].includes(record.attributeName))) continue;if (ignored(record.target)) continue;if (deferAnimationCheck(record, record.target)) continue;if (record.type === 'attributes' && record.attributeName === 'selected'@@ -660,6 +684,11 @@const editableTextMutation = editable(el) && (record.type === 'characterData'|| (record.type === 'childList' && [...record.addedNodes, ...record.removedNodes].some(node => node.nodeType === 3)));if (ignored(el)) continue;+ if (record.type === 'attributes' && record.attributeName === 'data-selected'+ && record.oldValue !== el.getAttribute('data-selected')) {+ const listbox = el.closest?.('[role="listbox"]');+ if (listbox && !ignored(listbox)) noteChange(listbox, record.agentUserAt);+ }// Native input already reports user edits, and agent input's synchronous// DOM writes are attributed to its dispatch. Keep those paths deduplicated// while observing independent page-script changes to editable text.@@ -691,6 +720,7 @@|| ((accessibleNameContentMutation || nativeLabelAssociationMutation)&& hasVisibleNativeLabelConsumer(el, nativeLabelAssociationMutation ? record.oldValue : '')));let identityChanged = (record.type === 'popover' && record.stateChanged)+ || record.type === 'prepared-style'|| (record.type === 'layout' && record.layoutChanged)|| editableTextMutation || hiddenAccessibleNameChanged|| (record.type === 'shadow' && (visible(el) || signatures.get(el)?.startsWith('[true')));@@ -713,6 +743,10 @@noteChange(el, record.agentUserAt);}if (!changed) return;+ // Keep prepared-target baselines aligned with changes already reported by+ // the DOM observer; the CSSOM sampler should only report unseen changes.+ for (const op of operations.values())+ if (!op.dispatched && op.target && op.until >= Date.now()) op.preparedTargetSignature = signature(op.target);revision++; publishRevision();clearTimeout(domTimer);pendingDOM = { kind: 'dom', source, target };@@ -754,7 +788,7 @@active = true; runToken = state.runToken; seq = 0; revision = 0; publishRevision();observer = new MutationObserver(onMutations);observeRoot(document);- controlTimer = setInterval(sampleFormControls, 250);+ controlTimer = setInterval(() => { sampleFormControls(); samplePreparedTargets(); }, 250);observeLayoutShifts();listen(document, 'webbrain-shadow-root-attached', event => {const path = event.composedPath();@@ -775,7 +809,7 @@? op?.domDispatchConsumed === true: op?.domDispatchConsumed === true || op?.domDispatchPhases?.has(phase) === true;event.stopImmediatePropagation();- flushPendingMutations();+ flushPendingMutations(op);sampleFormControls(op?.target);if (!active || guard.runToken !== runToken || guard.documentToken !== documentToken || guard.revision !== revision|| !op || phaseAlreadyConsumed || op.kind !== phaseKind@@ -819,8 +853,10 @@const form = submitter?.form;const formMethod = submitter?.hasAttribute('formmethod') ? submitter.formMethod : form?.method;const navigationFormGet = !link && !!form && String(formMethod || 'get').toLowerCase() === 'get';- const navigationTarget = (link?.getAttribute('target') || el?.form?.getAttribute('target')- || (link && document.querySelector('base[target]')?.getAttribute('target')) || '').toLowerCase();+ const formTarget = submitter?.getAttribute('formtarget') || form?.getAttribute('target');+ const baseTarget = document.querySelector('base[target]')?.getAttribute('target') || '';+ const navigationTarget = String((link ? link.getAttribute('target') : formTarget) || baseTarget || '');+ const normalizedTarget = navigationTarget.toLowerCase();let navigationUrl = '';try {const rawUrl = link?.href || (form ? (submitter.hasAttribute('formaction') ? submitter.formAction : form.action) : '');@@ -832,8 +868,9 @@send({ kind: 'activity', source: 'agent', operation: 'click',...(navigationUrl ? { navigationUrl } : {}),...(navigationUrl && navigationFormGet ? { navigationFormGet: true } : {}),- ...(navigationTarget === '_top' || (navigationTarget === '_parent' && window.parent === window.top)- ? { navigationTarget: '_top' } : {}) });+ ...(['_top', '_parent', '_self', '_blank'].includes(normalizedTarget)+ ? { navigationTarget: normalizedTarget }+ : navigationTarget ? { navigationTargetName: compact(navigationTarget, 256) } : {}) });}// Native listeners have microtask checkpoints between callbacks. Keep this// exact input's attribution through its page handlers, until the next task.@@ -958,7 +995,7 @@}function stop() {active = false; runToken = ''; activePointers.clear(); pointerHeld = false; composing = false;- lastUserAt = 0; lastViewport = ''; userTurn = null; lastUserTarget = null; matchedEvents = new WeakMap(); controlIterator = null;+ lastUserAt = 0; lastViewport = ''; userTurn = null; lastUserTarget = null; matchedEvents = new WeakMap(); controlIterator = null; preparedOperationCursor = 0;document.documentElement?.removeAttribute(fenceAttribute);for (const el of nativeTargets) {el.removeAttribute?.('data-webbrain-native-action');@@ -977,12 +1014,14 @@async function requestState() {const generation = ++requestGeneration;try {- const state = await api.runtime.sendMessage({ target: 'background', action: 'get_page_monitor_state', documentToken });+ const state = await api.runtime.sendMessage({ target: 'background', action: 'get_page_monitor_state', documentToken,+ frameName: compact(window.name.slice(0, 256), 256) });if (generation === requestGeneration && !disposed) start(state);} catch { stop(); }}function prepare(params) {if (!active || params.runToken !== runToken) return;+ flushPendingMutations();prune();const target = resolveTarget(params);const focusEligible = kindFor(params.tool) === 'input';@@ -994,7 +1033,8 @@const operationTarget = target || focusTarget;const controlStateAtPrepare = operationTarget && /^(INPUT|TEXTAREA|SELECT|OPTION)$/.test(operationTarget.tagName)? controlState(operationTarget) : undefined;- operations.set(params.operationId, { ...params, target: operationTarget, focusTarget, focusEligible, controlStateAtPrepare, kinds: new Set(),+ operations.set(params.operationId, { ...params, target: operationTarget, focusTarget, focusEligible, controlStateAtPrepare,+ preparedTargetSignature: operationTarget ? signature(operationTarget) : undefined, kinds: new Set(),coordinateSensitive, coordinateTarget, coordinateHit, coordinateTargetAtPoint,coordinatePoint: coordinateSensitive ? { x: params.x, y: params.y } : null,coordinateRect: rectFor(coordinateTarget),@@ -1031,7 +1071,7 @@}function activatePreparedDispatch(params = {}) {const op = operations.get(params.operationId);- flushPendingMutations();+ flushPendingMutations(op);sampleFormControls(op?.target);const layoutChanged = coordinatePreparationShifted(op);if (!active || !op || layoutChanged || domTimer || unreported@@ -1049,7 +1089,7 @@}function validateNativeDispatch(params = {}) {const op = operations.get(params.operationId);- flushPendingMutations();+ flushPendingMutations(op);sampleFormControls(op?.target);const shifted = coordinatePreparationShifted(op);if (!active || params.runToken !== runToken || params.documentToken !== documentToken || !op || shifted@@ -1098,8 +1138,9 @@}function beforeLocalDispatch({ preparation = false, kind, target } = {}) {if (!active || !localOperation) return;- flushPendingMutations();- sampleFormControls(operations.get(localOperation.operationId)?.target);+ const operation = operations.get(localOperation.operationId);+ flushPendingMutations(operation);+ sampleFormControls(operation?.target);const layoutChanged = coordinatePreparationShifted(operations.get(localOperation.operationId));if (layoutChanged || domTimer || unreported || lastUserAt > localOperation.userAt || revision !== localOperation.revision) {const error = new Error('Browser changed during action preparation. Re-observe before acting.');@@ -1138,7 +1179,7 @@else if (msg.action === 'page_monitor_dispatch') {const params = msg.params || {};const prepared = operations.get(params.operationId);- if (!params.release) { flushPendingMutations(); sampleFormControls(prepared?.target); }+ if (!params.release) { flushPendingMutations(prepared); sampleFormControls(prepared?.target); }const layoutChanged = !params.release && active && coordinatePreparationShifted(prepared);if (!params.release && active && (layoutChanged || domTimer || unreported || (prepared && prepared.preparedRevision !== revision)|| (params.documentToken && (params.documentToken !== documentToken || params.documentRevision !== revision)))) {diff --git a/src/firefox/src/agent/page-feedback.js b/src/firefox/src/agent/page-feedback.jsindex 9ca01b5ec..e18502050 100644--- a/src/firefox/src/agent/page-feedback.js+++ b/src/firefox/src/agent/page-feedback.js@@ -6,7 +6,7 @@ const clean = (value, limit = 240) => String(value ?? '').replace(/[\u0000-\u001const token = () => globalThis.crypto.randomUUID();const apiFor = () => globalThis.browser || globalThis.chrome;-async function notifyPageMonitorFrames(api, tabId, message, knownFrames = []) {+async function notifyPageMonitorFrames(api, tabId, message, knownFrames = [], onFrame = null) {if (!api?.tabs?.sendMessage) return;const frameIds = new Set([0, ...knownFrames]);let enumerated = false;@@ -14,7 +14,10 @@ async function notifyPageMonitorFrames(api, tabId, message, knownFrames = []) {const frames = await api.webNavigation?.getAllFrames?.({ tabId });if (Array.isArray(frames)) {enumerated = true;- for (const frame of frames) if (Number.isSafeInteger(frame.frameId) && frame.frameId >= 0) frameIds.add(frame.frameId);+ for (const frame of frames) if (Number.isSafeInteger(frame.frameId) && frame.frameId >= 0) {+ frameIds.add(frame.frameId);+ onFrame?.(frame);+ }}} catch { /* Restricted documents may not expose their frame tree. */ }// A broadcast reaches every frame but resolves on the first response. Address@@ -136,7 +139,10 @@ export const pageFeedbackMethods = {} });const api = apiFor();try { run.url = (await api.tabs.get(tabId)).url || ''; } catch {}- await notifyPageMonitorFrames(api, tabId, { target: 'content', action: 'page_monitor_state', active: true }, run.frames.keys());+ await notifyPageMonitorFrames(api, tabId, { target: 'content', action: 'page_monitor_state', active: true }, run.frames.keys(), frame => {+ run.documents.set(frame.frameId, { id: frame.documentId || '', url: frame.url || '',+ parentFrameId: Number.isSafeInteger(frame.parentFrameId) ? frame.parentFrameId : undefined });+ });},_finishPageFeedbackRun(tabId) {@@ -153,7 +159,7 @@ export const pageFeedbackMethods = {active: false, runToken: run.token }, run.frames.keys()).catch(() => {});},- pageMonitorState(sender, documentToken) {+ pageMonitorState(sender, documentToken, frameName = '') {const tabId = sender?.tab?.id;const run = this._pageFeedbackRuns?.get(tabId);if (!run || !this.isRunning(tabId) || this._checkAbort(tabId) || typeof documentToken !== 'string'@@ -165,8 +171,9 @@ export const pageFeedbackMethods = {const previous = run.frames.get(frameId);if (previous && previous.token !== documentToken) run.gestures.delete(frameId);if (!previous || previous.token !== documentToken) {- run.frames.set(frameId, { token: documentToken, id: sender.documentId || '', seq: 0 });- }+ run.frames.set(frameId, { token: documentToken, id: sender.documentId || '', seq: 0,+ name: clean(frameName, 256) });+ } else previous.name = clean(frameName, 256);return { active: true, runToken: run.token, documentToken };},@@ -194,8 +201,23 @@ export const pageFeedbackMethods = {url = destination.href;}} catch { /* Clicks without a safe, concrete destination cannot correlate navigation. */ }- run.navigation = url ? { at: Date.now(), url, kind: 'click',- frameId: feedback.navigationTarget === '_top' ? 0 : frameId,+ const target = String(feedback.navigationTarget || '').toLowerCase();+ let destinationFrameId;+ if (target === '_blank') destinationFrameId = undefined;+ else if (target === '_top') destinationFrameId = 0;+ else if (target === '_parent') {+ const parentFrameId = run.documents.get(frameId)?.parentFrameId;+ destinationFrameId = frameId === 0 ? 0 : Number.isSafeInteger(parentFrameId) && parentFrameId >= 0 ? parentFrameId : undefined;+ } else if (target === '_self') destinationFrameId = frameId;+ else {+ const requestedName = clean(feedback.navigationTargetName, 256);+ if (requestedName) {+ const matches = [...run.frames].filter(([, entry]) => entry.name === requestedName);+ if (matches.length === 1) destinationFrameId = matches[0][0];+ } else if (!target) destinationFrameId = frameId;+ }+ run.navigation = url && Number.isSafeInteger(destinationFrameId) ? { at: Date.now(), url, kind: 'click',+ frameId: destinationFrameId,...(feedback.navigationFormGet === true ? { formGet: true } : {}),operationId: dispatchOwners.get(tabId)?.operationId || '' } : null;}@@ -227,10 +249,11 @@ export const pageFeedbackMethods = {if (type === 'committed') {run.frames.delete(frameId);run.gestures.delete(frameId);- run.documents.set(frameId, { id: details.documentId || '', url: details.url || '' });+ run.documents.set(frameId, { id: details.documentId || '', url: details.url || '',+ parentFrameId: Number.isSafeInteger(details.parentFrameId) ? details.parentFrameId : undefined });if (frameId === 0) {run.frames.clear(); run.gestures.clear(); run.documents.clear();- run.documents.set(0, { id: details.documentId || '', url: details.url || '' });+ run.documents.set(0, { id: details.documentId || '', url: details.url || '', parentFrameId: -1 });}}const before = frameId === 0 ? run.url : '';diff --git a/src/firefox/src/background.js b/src/firefox/src/background.jsindex bc4d771cb..59ea536f1 100644--- a/src/firefox/src/background.js+++ b/src/firefox/src/background.js@@ -2483,7 +2483,7 @@ browser.runtime.onMessage.addListener((msg, sender) => {});async function handleMessage(msg, sender) {- if (msg.action === 'get_page_monitor_state') return agent.pageMonitorState(sender, msg.documentToken);+ if (msg.action === 'get_page_monitor_state') return agent.pageMonitorState(sender, msg.documentToken, msg.frameName);if (msg.action === 'page_feedback') return agent.observePageFeedback(sender, msg.feedback);if (msg.action === 'chat_steer') {diff --git a/src/firefox/src/content/page-monitor.js b/src/firefox/src/content/page-monitor.jsindex 78b700d84..067491118 100644--- a/src/firefox/src/content/page-monitor.js+++ b/src/firefox/src/content/page-monitor.js@@ -27,6 +27,7 @@let active = false, disposed = false, runToken = '', seq = 0, revision = 0;let observer = null, layoutObserver = null, domTimer = null, scrollTimer = null, controlTimer = null, lastUserAt = 0;let pointerHeld = false, composing = false, localOperation = null, controlIterator = null;+ let preparedOperationCursor = 0;let requestGeneration = 0, unreported = 0, pendingDOM = null;let lastViewport = '';let lastFeedbackDelivery = Promise.resolve();@@ -385,7 +386,7 @@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'),+ el.getAttribute('aria-expanded'), el.getAttribute('aria-selected'), el.getAttribute('aria-checked'), el.getAttribute('data-selected'),el.getAttribute('aria-valuenow'), el.getAttribute('aria-valuetext'),el.getAttribute('aria-pressed'),el.getAttribute('type'),@@ -434,10 +435,32 @@}if (records.length) onMutations(records);}- function flushPendingMutations() {+ function samplePreparedTargets(onlyOperation) {+ if (!active) return;+ const now = Date.now();+ const candidates = onlyOperation ? [onlyOperation] : [...operations.values()]+ .filter(op => !op.dispatched && op.target && op.preparedTargetSignature !== undefined && op.until >= now);+ if (!onlyOperation && candidates.length > 128) {+ const start = preparedOperationCursor % candidates.length;+ const batch = Array.from({ length: 128 }, (_, index) => candidates[(start + index) % candidates.length]);+ preparedOperationCursor = (start + batch.length) % candidates.length;+ candidates.splice(0, candidates.length, ...batch);+ }+ const changedTargets = new Set();+ for (const op of candidates) {+ if (!op || op.dispatched || !op.target || op.preparedTargetSignature === undefined) continue;+ const current = signature(op.target);+ if (current === op.preparedTargetSignature) continue;+ op.preparedTargetSignature = current;+ changedTargets.add(op.target);+ }+ if (changedTargets.size) onMutations([...changedTargets].map(target => ({ type: 'prepared-style', target })));+ }+ function flushPendingMutations(onlyOperation) {if (!active || !observer) return;const records = observer.takeRecords();if (records.length) onMutations(records);+ samplePreparedTargets(onlyOperation);}function sampleDescendants(root, limit = 100) {const nodes = [];@@ -465,7 +488,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', 'form', 'name', 'placeholder', 'title', 'alt', 'aria-labelledby', 'rel', 'media',+ attributeFilter: ['role', 'aria-label', 'id', 'for', 'form', 'name', 'placeholder', 'title', 'alt', 'aria-labelledby', 'rel', 'media', 'data-selected','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',@@ -625,7 +648,8 @@};const changes = [...records];for (const record of records) {- if (record.type !== 'popover' && (record.type !== 'attributes' || !['class', 'style', 'hidden', 'aria-hidden', 'open', 'inert', 'selected'].includes(record.attributeName))) continue;+ if (record.type !== 'popover' && record.type !== 'prepared-style'+ && (record.type !== 'attributes' || !['class', 'style', 'hidden', 'aria-hidden', 'open', 'inert', 'selected'].includes(record.attributeName))) continue;if (ignored(record.target)) continue;if (deferAnimationCheck(record, record.target)) continue;if (record.type === 'attributes' && record.attributeName === 'selected'@@ -660,6 +684,11 @@const editableTextMutation = editable(el) && (record.type === 'characterData'|| (record.type === 'childList' && [...record.addedNodes, ...record.removedNodes].some(node => node.nodeType === 3)));if (ignored(el)) continue;+ if (record.type === 'attributes' && record.attributeName === 'data-selected'+ && record.oldValue !== el.getAttribute('data-selected')) {+ const listbox = el.closest?.('[role="listbox"]');+ if (listbox && !ignored(listbox)) noteChange(listbox, record.agentUserAt);+ }// Native input already reports user edits, and agent input's synchronous// DOM writes are attributed to its dispatch. Keep those paths deduplicated// while observing independent page-script changes to editable text.@@ -691,6 +720,7 @@|| ((accessibleNameContentMutation || nativeLabelAssociationMutation)&& hasVisibleNativeLabelConsumer(el, nativeLabelAssociationMutation ? record.oldValue : '')));let identityChanged = (record.type === 'popover' && record.stateChanged)+ || record.type === 'prepared-style'|| (record.type === 'layout' && record.layoutChanged)|| editableTextMutation || hiddenAccessibleNameChanged|| (record.type === 'shadow' && (visible(el) || signatures.get(el)?.startsWith('[true')));@@ -713,6 +743,10 @@noteChange(el, record.agentUserAt);}if (!changed) return;+ // Keep prepared-target baselines aligned with changes already reported by+ // the DOM observer; the CSSOM sampler should only report unseen changes.+ for (const op of operations.values())+ if (!op.dispatched && op.target && op.until >= Date.now()) op.preparedTargetSignature = signature(op.target);revision++; publishRevision();clearTimeout(domTimer);pendingDOM = { kind: 'dom', source, target };@@ -754,7 +788,7 @@active = true; runToken = state.runToken; seq = 0; revision = 0; publishRevision();observer = new MutationObserver(onMutations);observeRoot(document);- controlTimer = setInterval(sampleFormControls, 250);+ controlTimer = setInterval(() => { sampleFormControls(); samplePreparedTargets(); }, 250);observeLayoutShifts();listen(document, 'webbrain-shadow-root-attached', event => {const path = event.composedPath();@@ -775,7 +809,7 @@? op?.domDispatchConsumed === true: op?.domDispatchConsumed === true || op?.domDispatchPhases?.has(phase) === true;event.stopImmediatePropagation();- flushPendingMutations();+ flushPendingMutations(op);sampleFormControls(op?.target);if (!active || guard.runToken !== runToken || guard.documentToken !== documentToken || guard.revision !== revision|| !op || phaseAlreadyConsumed || op.kind !== phaseKind@@ -819,8 +853,10 @@const form = submitter?.form;const formMethod = submitter?.hasAttribute('formmethod') ? submitter.formMethod : form?.method;const navigationFormGet = !link && !!form && String(formMethod || 'get').toLowerCase() === 'get';- const navigationTarget = (link?.getAttribute('target') || el?.form?.getAttribute('target')- || (link && document.querySelector('base[target]')?.getAttribute('target')) || '').toLowerCase();+ const formTarget = submitter?.getAttribute('formtarget') || form?.getAttribute('target');+ const baseTarget = document.querySelector('base[target]')?.getAttribute('target') || '';+ const navigationTarget = String((link ? link.getAttribute('target') : formTarget) || baseTarget || '');+ const normalizedTarget = navigationTarget.toLowerCase();let navigationUrl = '';try {const rawUrl = link?.href || (form ? (submitter.hasAttribute('formaction') ? submitter.formAction : form.action) : '');@@ -832,8 +868,9 @@send({ kind: 'activity', source: 'agent', operation: 'click',...(navigationUrl ? { navigationUrl } : {}),...(navigationUrl && navigationFormGet ? { navigationFormGet: true } : {}),- ...(navigationTarget === '_top' || (navigationTarget === '_parent' && window.parent === window.top)- ? { navigationTarget: '_top' } : {}) });+ ...(['_top', '_parent', '_self', '_blank'].includes(normalizedTarget)+ ? { navigationTarget: normalizedTarget }+ : navigationTarget ? { navigationTargetName: compact(navigationTarget, 256) } : {}) });}// Native listeners have microtask checkpoints between callbacks. Keep this// exact input's attribution through its page handlers, until the next task.@@ -958,7 +995,7 @@}function stop() {active = false; runToken = ''; activePointers.clear(); pointerHeld = false; composing = false;- lastUserAt = 0; lastViewport = ''; userTurn = null; lastUserTarget = null; matchedEvents = new WeakMap(); controlIterator = null;+ lastUserAt = 0; lastViewport = ''; userTurn = null; lastUserTarget = null; matchedEvents = new WeakMap(); controlIterator = null; preparedOperationCursor = 0;document.documentElement?.removeAttribute(fenceAttribute);for (const el of nativeTargets) {el.removeAttribute?.('data-webbrain-native-action');@@ -977,12 +1014,14 @@async function requestState() {const generation = ++requestGeneration;try {- const state = await api.runtime.sendMessage({ target: 'background', action: 'get_page_monitor_state', documentToken });+ const state = await api.runtime.sendMessage({ target: 'background', action: 'get_page_monitor_state', documentToken,+ frameName: compact(window.name.slice(0, 256), 256) });if (generation === requestGeneration && !disposed) start(state);} catch { stop(); }}function prepare(params) {if (!active || params.runToken !== runToken) return;+ flushPendingMutations();prune();const target = resolveTarget(params);const focusEligible = kindFor(params.tool) === 'input';@@ -994,7 +1033,8 @@const operationTarget = target || focusTarget;const controlStateAtPrepare = operationTarget && /^(INPUT|TEXTAREA|SELECT|OPTION)$/.test(operationTarget.tagName)? controlState(operationTarget) : undefined;- operations.set(params.operationId, { ...params, target: operationTarget, focusTarget, focusEligible, controlStateAtPrepare, kinds: new Set(),+ operations.set(params.operationId, { ...params, target: operationTarget, focusTarget, focusEligible, controlStateAtPrepare,+ preparedTargetSignature: operationTarget ? signature(operationTarget) : undefined, kinds: new Set(),coordinateSensitive, coordinateTarget, coordinateHit, coordinateTargetAtPoint,coordinatePoint: coordinateSensitive ? { x: params.x, y: params.y } : null,coordinateRect: rectFor(coordinateTarget),@@ -1031,7 +1071,7 @@}function activatePreparedDispatch(params = {}) {const op = operations.get(params.operationId);- flushPendingMutations();+ flushPendingMutations(op);sampleFormControls(op?.target);const layoutChanged = coordinatePreparationShifted(op);if (!active || !op || layoutChanged || domTimer || unreported@@ -1049,7 +1089,7 @@}function validateNativeDispatch(params = {}) {const op = operations.get(params.operationId);- flushPendingMutations();+ flushPendingMutations(op);sampleFormControls(op?.target);const shifted = coordinatePreparationShifted(op);if (!active || params.runToken !== runToken || params.documentToken !== documentToken || !op || shifted@@ -1098,8 +1138,9 @@}function beforeLocalDispatch({ preparation = false, kind, target } = {}) {if (!active || !localOperation) return;- flushPendingMutations();- sampleFormControls(operations.get(localOperation.operationId)?.target);+ const operation = operations.get(localOperation.operationId);+ flushPendingMutations(operation);+ sampleFormControls(operation?.target);const layoutChanged = coordinatePreparationShifted(operations.get(localOperation.operationId));if (layoutChanged || domTimer || unreported || lastUserAt > localOperation.userAt || revision !== localOperation.revision) {const error = new Error('Browser changed during action preparation. Re-observe before acting.');@@ -1138,7 +1179,7 @@else if (msg.action === 'page_monitor_dispatch') {const params = msg.params || {};const prepared = operations.get(params.operationId);- if (!params.release) { flushPendingMutations(); sampleFormControls(prepared?.target); }+ if (!params.release) { flushPendingMutations(prepared); sampleFormControls(prepared?.target); }const layoutChanged = !params.release && active && coordinatePreparationShifted(prepared);if (!params.release && active && (layoutChanged || domTimer || unreported || (prepared && prepared.preparedRevision !== revision)|| (params.documentToken && (params.documentToken !== documentToken || params.documentRevision !== revision)))) {diff --git a/test/page-feedback.mjs b/test/page-feedback.mjsindex 6319d5bf3..fb6af5353 100644--- a/test/page-feedback.mjs+++ b/test/page-feedback.mjs@@ -65,9 +65,9 @@ function setup(Agent, implementation = {}) {return agent;}-function bind(agent, tabId, frameId = 0, documentId = 'document-1', docToken = 'content-1') {+function bind(agent, tabId, frameId = 0, documentId = 'document-1', docToken = 'content-1', frameName = '') {const from = sender(tabId, frameId, documentId);- const state = agent.pageMonitorState(from, docToken);+ const state = agent.pageMonitorState(from, docToken, frameName);assert.equal(state.active, true);let seq = 0;return { state, from, send: value => agent.observePageFeedback(from, {@@ -228,7 +228,11 @@ for (const build of ['chrome', 'firefox']) {const agent = setup(Agent), tab = nextTab++, entered = deferred(), release = deferred();const states = new Map([[0, false], [2, false]]);const previousNavigation = api.webNavigation, previousMessage = api.tabs.sendMessage;- api.webNavigation = { getAllFrames: async () => [{ frameId: 0 }, { frameId: 2 }, { frameId: 9 }] };+ api.webNavigation = { getAllFrames: async () => [+ { frameId: 0, documentId: 'top-doc', parentFrameId: -1, url: 'https://example.com/' },+ { frameId: 2, documentId: 'child-doc', parentFrameId: 0, url: 'https://example.com/frame' },+ { frameId: 9, parentFrameId: 0 },+ ] };const sendFrame = async (frameId, message) => {if (frameId === 9) throw new Error('Restricted frame');if (message.action !== 'page_monitor_state') return {};@@ -245,6 +249,8 @@ for (const build of ['chrome', 'firefox']) {await entered.promise;await new Promise(resolve => setImmediate(resolve));assert.equal(complete, false, 'A top-frame response must not bypass a delayed child acknowledgement');+ assert.equal(agent._pageFeedbackRuns.get(tab).documents.get(2)?.parentFrameId, 0,+ 'Frame startup records parent IDs so later _parent navigation can be correlated');release.resolve(); await starting;assert.deepEqual([...states.values()], [true, true]);agent._releaseRunEntry(tab);@@ -406,7 +412,13 @@ for (const build of ['chrome', 'firefox']) {const agent = setup(Agent), tab = nextTab++;await agent._claimRunEntry(tab, 'interactive');try {- const child = bind(agent, tab, 2, 'child', 'child-token');+ const child = bind(agent, tab, 2, 'child', 'child-token', 'ChildFrame');+ const parent = bind(agent, tab, 1, 'parent', 'parent-token', 'ParentFrame');+ bind(agent, tab, 3, 'sibling', 'sibling-token', 'SiblingTarget');+ const run = agent._pageFeedbackRuns.get(tab);+ run.documents.set(2, { id: 'child', parentFrameId: 1 });+ run.documents.set(1, { id: 'parent', parentFrameId: 0 });+ run.documents.set(3, { id: 'sibling', parentFrameId: 1 });child.send({ kind: 'activity', source: 'agent', operation: 'click' });for (const frameId of [0, 3, 2]) agent.observePageNavigation({ tabId: tab, frameId,url: `https://example.com/frame-${frameId}`, transitionType: 'link' }, 'history');@@ -424,11 +436,25 @@ for (const build of ['chrome', 'firefox']) {agent.observePageNavigation({ tabId: tab, frameId: 2, url: 'https://example.com/unrelated', transitionType: 'link' }, 'history');assert.equal(agent._hasPendingPageFeedback(tab), true, 'A same-frame navigation to a different URL remains visible');agent._pageFeedbackRuns.get(tab).events.clear();+ child.send({ kind: 'activity', source: 'agent', operation: 'click', navigationTarget: '_parent',+ navigationUrl: 'https://example.com/parent' });+ agent.observePageNavigation({ tabId: tab, frameId: 1, url: 'https://example.com/parent', transitionType: 'link' }, 'history');+ assert.equal(agent._hasPendingPageFeedback(tab), false, 'A nested frame _parent click correlates to its actual parent');+ agent._pageFeedbackRuns.get(tab).events.clear();+ child.send({ kind: 'activity', source: 'agent', operation: 'click', navigationTargetName: 'SiblingTarget',+ navigationUrl: 'https://example.com/sibling' });+ agent.observePageNavigation({ tabId: tab, frameId: 3, url: 'https://example.com/sibling', transitionType: 'link' }, 'history');+ assert.equal(agent._hasPendingPageFeedback(tab), false, 'A named target click correlates to the uniquely named sibling frame');+ agent._pageFeedbackRuns.get(tab).events.clear();+ parent.send({ kind: 'activity', source: 'agent', operation: 'click', navigationTargetName: 'missing-frame',+ navigationUrl: 'https://example.com/ambiguous' });+ agent.observePageNavigation({ tabId: tab, frameId: 3, url: 'https://example.com/ambiguous', transitionType: 'link' }, 'history');+ assert.equal(agent._hasPendingPageFeedback(tab), true, 'An unresolved named target cannot suppress another frame navigation');+ agent._pageFeedbackRuns.get(tab).events.clear();child.send({ kind: 'activity', source: 'agent', operation: 'click', navigationUrl: 'https://example.com/expected' });- agent.observePageNavigation({ tabId: tab, frameId: 2, documentId: 'child-redirect',+ agent.observePageNavigation({ tabId: tab, frameId: 2, parentFrameId: 1, documentId: 'child-redirect',url: 'https://example.com/unrelated-redirect', transitionType: 'link', transitionQualifiers: ['server_redirect'] }, 'committed');assert.equal(agent._hasPendingPageFeedback(tab), false, 'The first same-frame redirect may commit at a URL different from the armed destination');- agent._pageFeedbackRuns.get(tab).events.clear();child.send({ kind: 'activity', source: 'agent', operation: 'click', navigationTarget: '_top', navigationUrl: 'javascript:alert(1)' });agent.observePageNavigation({ tabId: tab, frameId: 0, url: 'https://example.com/safe', transitionType: 'link' }, 'history');assert.equal(agent._hasPendingPageFeedback(tab), true, 'Non-web click targets cannot correlate browser navigation');diff --git a/test/page-monitor-ui.mjs b/test/page-monitor-ui.mjsindex e54444b4c..cd87f20a4 100644--- a/test/page-monitor-ui.mjs+++ b/test/page-monitor-ui.mjs@@ -42,12 +42,16 @@ async function fixture(engine, build, { runToken = 'test-run', siteIsolation = fawait context.addInitScript(() => {window.monitorEnabled = true;window.feedback = [];+ window.pageMonitorStateRequests = [];window.messageListeners = [];const runtime = { onMessage: {addListener: fn => messageListeners.push(fn),removeListener: fn => { messageListeners = messageListeners.filter(item => item !== fn); },}, async sendMessage(msg) {- if (msg.action === 'get_page_monitor_state') return { active: monitorEnabled, runToken: monitorRunToken, documentToken: msg.documentToken };+ if (msg.action === 'get_page_monitor_state') {+ pageMonitorStateRequests.push(msg.frameName);+ return { active: monitorEnabled, runToken: monitorRunToken, documentToken: msg.documentToken };+ }if (msg.action === 'page_feedback') { feedback.push(msg.feedback); return { accepted: true }; }return {};} };@@ -724,6 +728,57 @@ for (const [build, engine] of [['chrome', chromium], ['firefox', firefox]]) {} finally { await browser.close(); }});+ test(`${build}: CSSOM visibility changes fence prepared target clicks`, async () => {+ const { browser, page } = await fixture(engine, build);+ try {+ await page.evaluate(() => {+ feedback = [];+ deliver('page_monitor_prepare', { operationId: 'cssom-hidden-target', tool: 'click', selector: '#agent' });+ deliver('page_monitor_dispatch', { operationId: 'cssom-hidden-target', kind: 'click', selector: '#agent', fenceOnly: true });+ document.styleSheets[0].insertRule('#agent { opacity: 0 !important; }', document.styleSheets[0].cssRules.length);+ });+ await page.waitForFunction(() => feedback.some(event => event.kind === 'dom' && event.source === 'page'), null, { timeout: 1500 });+ const blocked = await page.evaluate(() => {+ try {+ __wbPageMonitor.activatePreparedDispatch({ operationId: 'cssom-hidden-target', kind: 'click',+ element: document.getElementById('agent') });+ return null;+ } catch (error) { return error.code; }+ });+ assert.equal(blocked, 'page_feedback_pending', 'A CSSOM-only visibility change must invalidate the prepared target');+ } finally { await browser.close(); }+ });++ test(`${build}: data-selected changes report the custom listbox value and fence prepared actions`, async () => {+ const { browser, page } = await fixture(engine, build);+ try {+ await page.evaluate(() => {+ const listbox = document.createElement('div');+ listbox.id = 'custom-listbox'; listbox.setAttribute('role', 'listbox');+ listbox.innerHTML = '<div id="option-first" role="option" data-selected="true">First</div>'+ + '<div id="option-second" role="option">Second</div>';+ document.body.append(listbox);+ });+ await page.waitForFunction(() => feedback.some(event => event.kind === 'dom'), null, { timeout: 1000 });+ await page.waitForTimeout(180);+ await page.evaluate(() => {+ feedback = [];+ deliver('page_monitor_prepare', { operationId: 'listbox-selected', tool: 'click', selector: '#custom-listbox' });+ deliver('page_monitor_dispatch', { operationId: 'listbox-selected', kind: 'click', selector: '#custom-listbox', fenceOnly: true });+ document.getElementById('option-first').removeAttribute('data-selected');+ document.getElementById('option-second').setAttribute('data-selected', 'true');+ });+ await page.waitForFunction(() => feedback.some(event => event.kind === 'dom' && event.source === 'page'), null, { timeout: 1000 });+ const observation = await page.evaluate(() => feedback.find(event => event.kind === 'dom'));+ assert.equal(observation.target, 'div#custom-listbox [listbox]', 'Feedback should identify the model-visible listbox value');+ const blocked = await page.evaluate(() => {+ try { __wbPageMonitor.activatePreparedDispatch({ operationId: 'listbox-selected', kind: 'click' }); return null; }+ catch (error) { return error.code; }+ });+ assert.equal(blocked, 'page_feedback_pending', 'Changing the selected option must stale a prepared action');+ } finally { await browser.close(); }+ });+test(`${build}: fenced iframe clicks reject transport-gap input and attribute the dispatched click`, async () => {const { browser, page } = await fixture(engine, build);try {@@ -1477,11 +1532,13 @@ for (const [build, engine] of [['chrome', chromium], ['firefox', firefox]]) {const host = document.createElement('div'); host.id = 'shadow-host';host.attachShadow({ mode: 'open' }).innerHTML = '<button id="shadow-button">Before</button>';document.body.prepend(host);- const frame = document.createElement('iframe'); frame.src = 'https://monitor.test/frame';+ const frame = document.createElement('iframe'); frame.name = 'NestedSource'; frame.src = 'https://monitor.test/frame';document.body.prepend(frame);});await page.waitForFunction(() => document.querySelector('iframe')?.contentWindow?.feedback);const child = page.frames().find(frame => frame.url() === 'https://monitor.test/frame');+ assert.equal(await child.evaluate(() => pageMonitorStateRequests.at(-1)), 'NestedSource',+ 'The monitor registers the frame name with background for later named-target resolution');await page.locator('#human').click();await child.locator('#human').click();const tokens = await Promise.all([page.evaluate(() => feedback[0]?.documentToken), child.evaluate(() => feedback[0]?.documentToken)]);@@ -1501,9 +1558,25 @@ for (const [build, engine] of [['chrome', chromium], ['firefox', firefox]]) {}, { target, id });await child.locator(`#${id}`).click();assert.ok((await child.evaluate(() => feedback)).some(event => event.source === 'agent'- && event.navigationTarget === '_top' && event.navigationUrl === 'https://monitor.test/destination'),- `${target} navigation must carry its safe destination and compatible top-frame target`);+ && event.navigationTarget === target && event.navigationUrl === 'https://monitor.test/destination'),+ `${target} navigation must carry its safe destination and original browsing-context target`);}+ await child.evaluate(() => {+ const link = document.createElement('a'); link.id = 'named-link'; link.href = 'https://monitor.test/destination';+ link.target = 'SiblingTarget'; link.textContent = 'named-link';+ link.addEventListener('click', event => event.preventDefault()); document.body.append(link);+ });+ await page.waitForTimeout(200);+ await child.evaluate(() => {+ deliver('page_monitor_prepare', { operationId: 'link-named', tool: 'click', selector: '#named-link' });+ deliver('page_monitor_dispatch', { operationId: 'link-named', kind: 'click', selector: '#named-link' });+ feedback = [];+ });+ await child.locator('#named-link').click();+ const namedFeedback = await child.evaluate(() => feedback);+ assert.ok(namedFeedback.some(event => event.source === 'agent'+ && event.navigationTargetName === 'SiblingTarget' && event.navigationUrl === 'https://monitor.test/destination'),+ `Named navigation targets must preserve their exact browsing-context name and safe destination: ${JSON.stringify(namedFeedback)}`);await page.waitForTimeout(200);await page.evaluate(() => {feedback = [];