Skip to content

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

perf(chrome): wake click_ax observation from browser events

alectimison-makerac51849c3ff4
diff --git a/docs/privacy-and-data-flow.md b/docs/privacy-and-data-flow.md
index 354f69bc8..2542fa100 100644
--- a/docs/privacy-and-data-flow.md
+++ b/docs/privacy-and-data-flow.md
@@ -236,6 +236,11 @@ to the local `webbrain_traces` IndexedDB database in one of two privacy tiers:
storage bounds; old completed lossless runs may be evicted to remain within
the aggregate limit. These runs are visibly marked in the Traces UI.
+`click_ax_timing` trace notes retain only bounded stage durations, input-event
+counts, outcome categories, and safety-status booleans. URL, target labels,
+accessibility references, and other page content are excluded in both tiers,
+including lossless traces.
+
Default trace redaction does not disable `/workflow --save`. While a traced run
is active, the recorder keeps bounded raw tool payloads in memory only. On
successful completion, the agent immediately compiles them into the existing
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index 3f2f217e6..b4600557e 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -12469,6 +12469,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
onUpdate,
{
completionBatchStartState,
+ traceStep: step,
promptTier,
dispatchBinding: pipelineToolbarPreflight.probe?.dispatchBinding || null,
...messageRecipientExecutionContext,
@@ -15459,33 +15460,103 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
}
}
- async _dispatchClickAx(tabId, args, axScope = null, dispatchBinding = null, messageRecipientContext = {}, upstreamAbortSignal = null, upstreamDispatchState = null) {
+ _recordClickAxTiming(tabId, step, timing, result) {
+ const runId = this.currentRunId?.get(tabId);
+ if (!runId) return;
+ let outcome = 'inconclusive';
+ if (timing.outcomeUnknown === true) outcome = 'unknown';
+ else if (!timing.syntheticDispatched) outcome = 'pre_dispatch';
+ else if (result?.noProgress === true) outcome = 'no_progress';
+ else if (result?.success !== true) outcome = 'failed';
+ else if (result?.verified === true) outcome = 'verified';
+ const extra = {
+ preflightMs: timing.preflightMs,
+ syntheticDispatchMs: timing.syntheticDispatchMs,
+ syntheticResponseMs: timing.syntheticResponseMs,
+ postClickObservationMs: timing.postClickObservationMs,
+ fallbackPreparationMs: timing.fallbackPreparationMs,
+ fallbackDispatchMs: timing.fallbackDispatchMs,
+ trustedObservationMs: timing.trustedObservationMs,
+ clickPathMs: timing.clickPathMs,
+ trustedInputEvents: timing.trustedInputEvents,
+ syntheticDispatched: timing.syntheticDispatched,
+ trustedFallbackAttempted: result?.fallbackAttempted === true || timing.trustedInputEvents > 0,
+ outcomeUnknown: timing.outcomeUnknown === true,
+ safetyVeto: timing.safetyVeto === true,
+ duplicateFallbackBlocked: timing.duplicateFallbackBlocked === true,
+ outcome,
+ };
+ try {
+ const pending = trace.recordNote(runId, Number.isInteger(step) ? step : null, 'click_ax_timing', extra);
+ if (pending?.catch) pending.catch(() => {});
+ } catch {}
+ }
+
+ async _dispatchClickAx(
+ tabId,
+ args,
+ axScope = null,
+ dispatchBinding = null,
+ messageRecipientContext = {},
+ upstreamAbortSignal = null,
+ upstreamDispatchState = null,
+ traceStep = null,
+ ) {
const dispatchState = upstreamDispatchState || { started: false };
+ const timing = {
+ startedAt: this._clickAxClockNow(),
+ startedAtEpoch: Date.now(),
+ postClickObservationMs: 0,
+ fallbackPreparationMs: 0,
+ fallbackDispatchMs: 0,
+ trustedObservationMs: 0,
+ trustedInputEvents: 0,
+ syntheticDispatched: false,
+ safetyVeto: false,
+ duplicateFallbackBlocked: false,
+ };
+ let result = null;
try {
return await this._withContentActionDeadline(
- deadlineAbortSignal => this._dispatchClickAxImpl(
- tabId,
- args,
- axScope,
- dispatchBinding,
- messageRecipientContext,
- deadlineAbortSignal,
- upstreamAbortSignal,
- dispatchState,
- ),
+ async deadlineAbortSignal => {
+ result = await this._dispatchClickAxImpl(
+ tabId,
+ args,
+ axScope,
+ dispatchBinding,
+ messageRecipientContext,
+ deadlineAbortSignal,
+ upstreamAbortSignal,
+ dispatchState,
+ timing,
+ );
+ return result;
+ },
'click_ax',
);
} catch (error) {
if (error?.code !== 'content_action_timeout') throw error;
- if (dispatchState.started) return this._contentActionTimeoutResult('click_ax', error);
- return {
- success: false,
- dispatched: false,
- noDispatch: true,
- outcomeUnknown: false,
- retryable: true,
- error: `${error.message} No click was sent because the pre-dispatch page observation did not finish. Re-observe the page before retrying.`,
- };
+ if (dispatchState.started) {
+ result = this._contentActionTimeoutResult('click_ax', error);
+ } else {
+ result = {
+ success: false,
+ dispatched: false,
+ noDispatch: true,
+ outcomeUnknown: false,
+ retryable: true,
+ error: `${error.message} No click was sent because the pre-dispatch page observation did not finish. Re-observe the page before retrying.`,
+ };
+ }
+ return result;
+ } finally {
+ timing.clickPathMs = Math.max(0, this._clickAxClockNow() - timing.startedAt);
+ timing.outcomeUnknown = result?.outcomeUnknown === true
+ || (!timing.syntheticDispatched
+ && dispatchState.started
+ && result?.dispatched !== false
+ && result?.noDispatch !== true);
+ this._recordClickAxTiming(tabId, traceStep, timing, result);
}
}
@@ -15498,6 +15569,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
deadlineAbortSignal = null,
upstreamAbortSignal = null,
dispatchState = { started: false },
+ timing = null,
) {
const throwIfAborted = () => {
this._throwIfAborted(upstreamAbortSignal);
@@ -15600,6 +15672,22 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
return { error: `Failed to communicate with page: ${retryError.message}` };
}
}
+ const syntheticClickStartedAt = Number(response?._syntheticClickStartedAt);
+ const syntheticClickDispatchMs = Number(response?._syntheticClickDispatchMs);
+ if (timing && Number.isFinite(syntheticClickStartedAt) && syntheticClickStartedAt > 0) {
+ timing.preflightMs = Math.max(0, syntheticClickStartedAt - timing.startedAtEpoch);
+ timing.syntheticDispatchMs = Number.isFinite(syntheticClickDispatchMs)
+ ? Math.max(0, syntheticClickDispatchMs)
+ : undefined;
+ timing.syntheticResponseMs = Math.max(
+ 0,
+ Date.now() - syntheticClickStartedAt - (timing.syntheticDispatchMs || 0),
+ );
+ timing.syntheticDispatched = true;
+ }
+ if (response && Object.prototype.hasOwnProperty.call(response, '_syntheticClickDispatchMs')) {
+ delete response._syntheticClickDispatchMs;
+ }
response = await this._settleContentFilePickerGuard(tabId, response);
throwIfAborted();
if (response?.documentToken && (
@@ -15620,6 +15708,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
response,
baseline,
deadlineAbortSignal,
+ timing,
);
throwIfAborted();
}
@@ -38924,6 +39013,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
{ messageRecipientGuardRequired, messageRecipientDispatchBinding },
earlyCdpAbortSignal,
earlyCdpDispatchState,
+ dispatchContext.traceStep,
);
}
@@ -39198,21 +39288,38 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
_beginClickAxSideEffectWatch(tabId) {
const created = [];
const requests = [];
+ let signalVersion = 0;
+ const signalWaiters = new Set();
+ const signal = () => {
+ signalVersion++;
+ for (const waiter of [...signalWaiters]) waiter.resolve();
+ };
const downloadListener = (item) => {
created.push({ id: item?.id, filename: item?.filename || '', ts: Date.now() });
+ signal();
};
const requestListener = (details) => {
if (details?.tabId !== tabId) return;
- requests.push({
+ const request = {
url: details.url || '',
method: details.method || '',
type: details.type || '',
requestId: details.requestId,
ts: Date.now(),
- });
+ };
+ requests.push(request);
+ if (this._clickAxRequestIsSafetyRelevant(request, request.ts)) signal();
+ };
+ const tabCreatedListener = () => signal();
+ const tabRemovedListener = () => signal();
+ const tabUpdatedListener = (updatedTabId, changeInfo) => {
+ if (updatedTabId === tabId && typeof changeInfo?.url === 'string') signal();
};
let listeningDownloads = false;
let listeningRequests = false;
+ let listeningTabCreated = false;
+ let listeningTabRemoved = false;
+ let listeningTabUpdated = false;
try {
if (chrome.downloads?.onCreated?.addListener) {
chrome.downloads.onCreated.addListener(downloadListener);
@@ -39228,9 +39335,45 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
listeningRequests = true;
}
} catch {}
+ try {
+ if (chrome.tabs?.onCreated?.addListener) {
+ chrome.tabs.onCreated.addListener(tabCreatedListener);
+ listeningTabCreated = true;
+ }
+ } catch {}
+ try {
+ if (chrome.tabs?.onRemoved?.addListener) {
+ chrome.tabs.onRemoved.addListener(tabRemovedListener);
+ listeningTabRemoved = true;
+ }
+ } catch {}
+ try {
+ if (chrome.tabs?.onUpdated?.addListener) {
+ chrome.tabs.onUpdated.addListener(tabUpdatedListener);
+ listeningTabUpdated = true;
+ }
+ } catch {}
return {
created,
requests,
+ get signalVersion() {
+ return signalVersion;
+ },
+ waitForSignal: (ms, afterVersion = signalVersion) => {
+ if (signalVersion !== afterVersion) return Promise.resolve(signalVersion);
+ return new Promise(resolve => {
+ const waiter = {
+ timer: null,
+ resolve: () => {
+ clearTimeout(waiter.timer);
+ signalWaiters.delete(waiter);
+ resolve(signalVersion);
+ },
+ };
+ waiter.timer = setTimeout(waiter.resolve, Math.max(0, Number(ms) || 0));
+ signalWaiters.add(waiter);
+ });
+ },
get listeningRequests() {
return listeningRequests;
},
@@ -39243,6 +39386,19 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
try { chrome.webRequest.onBeforeRequest.removeListener(requestListener); } catch {}
listeningRequests = false;
}
+ if (listeningTabCreated) {
+ try { chrome.tabs.onCreated.removeListener(tabCreatedListener); } catch {}
+ listeningTabCreated = false;
+ }
+ if (listeningTabRemoved) {
+ try { chrome.tabs.onRemoved.removeListener(tabRemovedListener); } catch {}
+ listeningTabRemoved = false;
+ }
+ if (listeningTabUpdated) {
+ try { chrome.tabs.onUpdated.removeListener(tabUpdatedListener); } catch {}
+ listeningTabUpdated = false;
+ }
+ for (const waiter of [...signalWaiters]) waiter.resolve();
},
};
}
@@ -39303,6 +39459,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
snapshot: snapshot || await this._clickProgressSnapshot(tabId),
tabIds: await this._clickAxTabSnapshot(),
sideEffectWatch,
+ signalVersion: Number(sideEffectWatch?.signalVersion) || 0,
// Carry preparatory / pre-round focus identity so blur-only changes
// (e.g. CDP mousedown clearing an unrelated focused input) never count
// as proof that this click activated the page.
@@ -39401,6 +39558,34 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
return new Promise(resolve => setTimeout(resolve, ms));
}
+ _clickAxClockNow() {
+ try {
+ const now = globalThis.performance?.now;
+ if (typeof now === 'function') return now.call(globalThis.performance);
+ } catch {}
+ return Date.now();
+ }
+
+ async _measureClickAxStage(timing, field, operation) {
+ const startedAt = this._clickAxClockNow();
+ try {
+ return await operation();
+ } finally {
+ if (timing) {
+ const elapsedMs = Math.max(0, this._clickAxClockNow() - startedAt);
+ timing[field] = (Number(timing[field]) || 0) + elapsedMs;
+ }
+ }
+ }
+
+ async _observeClickAxTimed(tabId, baseline, options, timing, field = 'postClickObservationMs') {
+ return this._measureClickAxStage(
+ timing,
+ field,
+ () => this._observeClickAxSideEffect(tabId, baseline, options),
+ );
+ }
+
/**
* Observe post-click side effects. Fixed sleeps alone misclassify slow SPA
* handlers; progressive polling keeps the upper bound but resolves early on
@@ -39418,11 +39603,19 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
return this._clickAxObservedSideEffect(tabId, baseline);
}
const started = Date.now();
- await this._clickAxDelay(allowDelayed ? firstDelayMs : Math.min(firstDelayMs, 250));
+ let signalVersion = Number(baseline.signalVersion) || 0;
+ const waitForNextObservation = async ms => {
+ if (typeof baseline.sideEffectWatch?.waitForSignal === 'function') {
+ signalVersion = await baseline.sideEffectWatch.waitForSignal(ms, signalVersion);
+ } else {
+ await this._clickAxDelay(ms);
+ }
+ };
+ await waitForNextObservation(allowDelayed ? firstDelayMs : Math.min(firstDelayMs, 250));
let observed = await this._clickAxObservedSideEffect(tabId, baseline);
if (!allowDelayed || observed.proved || observed.safetyVeto || !observed.observable) return observed;
while (Date.now() - started < maxMs) {
- await this._clickAxDelay(pollMs);
+ await waitForNextObservation(pollMs);
observed = await this._clickAxObservedSideEffect(tabId, baseline);
if (observed.proved || observed.safetyVeto || !observed.observable) return observed;
}
@@ -39825,7 +40018,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
} catch { /* best-effort pointer cleanup */ }
}
- async _maybeFallbackClickAxWithCdp(tabId, args, response, baseline, upstreamAbortSignal = null) {
+ async _maybeFallbackClickAxWithCdp(tabId, args, response, baseline, upstreamAbortSignal = null, timing = null) {
if (CONTENT_ACTION_SIGNAL_DEADLINES.has(upstreamAbortSignal)) {
return this._maybeFallbackClickAxWithCdpImpl(
tabId,
@@ -39833,6 +40026,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
response,
baseline,
upstreamAbortSignal,
+ timing,
);
}
try {
@@ -39843,6 +40037,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
response,
baseline,
abortSignal,
+ timing,
),
'click_ax',
this._contentActionDeadlineMs('click_ax', args),
@@ -39856,7 +40051,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
}
}
- async _maybeFallbackClickAxWithCdpImpl(tabId, args, response, baseline, abortSignal = null) {
+ async _maybeFallbackClickAxWithCdpImpl(tabId, args, response, baseline, abortSignal = null, timing = null) {
if (!response || response.success !== true || !baseline) return response;
const withSnapshot = (value, observation) => {
@@ -39920,13 +40115,15 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
// Ineligible targets only pay a short first sample; eligible candidates
// use progressive polling so slow SPA handlers can still prove progress
// before a second trusted click is considered.
- const syntheticObservation = await this._observeClickAxSideEffect(
+ const syntheticObservation = await this._observeClickAxTimed(
tabId,
baseline,
fallbackStaticBlockedReason
? { allowDelayed: false, firstDelayMs: 250 }
: { allowDelayed: true, firstDelayMs: 250, pollMs: 150, maxMs: 1250 },
+ timing,
);
+ if (timing) timing.safetyVeto ||= syntheticObservation?.safetyVeto === true;
this._throwIfAborted(abortSignal);
{
const assessed = this._assessClickAxObservationRound(
@@ -39937,7 +40134,11 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
if (assessed.done) return withSnapshot(assessed.value, syntheticObservation);
}
- let target = await this._resolveClickAxFallbackTarget(tabId, args?.ref_id, abortSignal);
+ let target = await this._measureClickAxStage(
+ timing,
+ 'fallbackPreparationMs',
+ () => this._resolveClickAxFallbackTarget(tabId, args?.ref_id, abortSignal),
+ );
this._throwIfAborted(abortSignal);
let targetStrongState = strongStateOf(target);
let targetWeakState = weakStateOf(target);
@@ -39963,11 +40164,13 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
// Final settle for eligible candidates only: progressive samples up to
// ~finalSettleMs so late DOM/URL/focus still suppress the second click.
const settleBudget = this._clickAxFinalSettleMs();
- const settledObservation = await this._observeClickAxSideEffect(
+ const settledObservation = await this._observeClickAxTimed(
tabId,
baseline,
{ allowDelayed: true, firstDelayMs: Math.min(200, settleBudget), pollMs: 150, maxMs: settleBudget },
+ timing,
);
+ if (timing) timing.safetyVeto ||= settledObservation?.safetyVeto === true;
this._throwIfAborted(abortSignal);
{
const assessed = this._assessClickAxObservationRound(
@@ -39978,7 +40181,11 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
if (assessed.done) return withSnapshot(assessed.value, settledObservation);
}
- const settledTarget = await this._resolveClickAxFallbackTarget(tabId, args?.ref_id, abortSignal);
+ const settledTarget = await this._measureClickAxStage(
+ timing,
+ 'fallbackPreparationMs',
+ () => this._resolveClickAxFallbackTarget(tabId, args?.ref_id, abortSignal),
+ );
this._throwIfAborted(abortSignal);
const settledTargetStrongState = strongStateOf(settledTarget);
const settledTargetWeakState = weakStateOf(settledTarget);
@@ -40018,6 +40225,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
const fallbackKey = `${target.documentToken || 'document'}|${args?.ref_id || ''}`;
const attempted = this._clickAxCdpFallbacks.get(tabId) || new Set();
if (attempted.has(fallbackKey)) {
+ if (timing) timing.duplicateFallbackBlocked = true;
return withSnapshot({
...response,
success: false,
@@ -40037,12 +40245,16 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
} catch {
preCdpActive = '';
}
- const fallbackBaseline = await this._captureClickAxObservation(
- tabId,
- settledObservation.snapshot,
- baseline.sideEffectWatch,
- Date.now(),
- baseline.preparedActive || preCdpActive,
+ const fallbackBaseline = await this._measureClickAxStage(
+ timing,
+ 'fallbackPreparationMs',
+ () => this._captureClickAxObservation(
+ tabId,
+ settledObservation.snapshot,
+ baseline.sideEffectWatch,
+ Date.now(),
+ baseline.preparedActive || preCdpActive,
+ ),
);
this._throwIfAborted(abortSignal);
// Prefer the live pre-CDP active as the "preparatory" identity for the
@@ -40054,22 +40266,32 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
let pressedDelivered = false;
try {
this._throwIfAborted(abortSignal);
- await cdpClient.attach(tabId);
+ await this._measureClickAxStage(timing, 'fallbackPreparationMs', () => cdpClient.attach(tabId));
this._throwIfAborted(abortSignal);
dispatchStage = 'filePickerGuardArm';
- await cdpClient.armFileInputClickGuard(tabId);
+ await this._measureClickAxStage(timing, 'fallbackPreparationMs', () => cdpClient.armFileInputClickGuard(tabId));
this._throwIfAborted(abortSignal);
dispatchStage = 'mouseMoved';
- await cdpClient.dispatchMouseEvent(tabId, 'mouseMoved', target.x, target.y);
+ await this._measureClickAxStage(
+ timing,
+ 'fallbackDispatchMs',
+ () => cdpClient.dispatchMouseEvent(tabId, 'mouseMoved', target.x, target.y),
+ );
dispatchedEvents++;
+ if (timing) timing.trustedInputEvents = dispatchedEvents;
this._throwIfAborted(abortSignal);
dispatchStage = 'mousePressed';
// Snapshot/tab baselines must exist before pointer input, but the
// mutation window starts at the first click-producing event rather than
// CDP attach or mouse movement.
fallbackBaseline.startedAt = Date.now();
- await cdpClient.dispatchMouseEvent(tabId, 'mousePressed', target.x, target.y);
+ await this._measureClickAxStage(
+ timing,
+ 'fallbackDispatchMs',
+ () => cdpClient.dispatchMouseEvent(tabId, 'mousePressed', target.x, target.y),
+ );
dispatchedEvents++;
+ if (timing) timing.trustedInputEvents = dispatchedEvents;
pressedDelivered = true;
// A confirmed press is partial user input; from this point onward a
// retry could double-activate or leave mismatched pointer state.
@@ -40082,11 +40304,20 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
throw error;
}
dispatchStage = 'mouseReleased';
- await cdpClient.dispatchMouseEvent(tabId, 'mouseReleased', target.x, target.y);
+ await this._measureClickAxStage(
+ timing,
+ 'fallbackDispatchMs',
+ () => cdpClient.dispatchMouseEvent(tabId, 'mouseReleased', target.x, target.y),
+ );
dispatchedEvents++;
+ if (timing) timing.trustedInputEvents = dispatchedEvents;
this._throwIfAborted(abortSignal);
dispatchStage = 'filePickerGuardConsume';
- const blockedFileInput = await cdpClient.consumeFileInputClickGuard(tabId);
+ const blockedFileInput = await this._measureClickAxStage(
+ timing,
+ 'fallbackDispatchMs',
+ () => cdpClient.consumeFileInputClickGuard(tabId),
+ );
if (blockedFileInput?.blocked) {
return withSnapshot({
...cdpClient.fileInputClickBlockedResult(
@@ -40120,17 +40351,24 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
}, settledObservation);
}
- const trustedObservation = await this._observeClickAxSideEffect(
+ const trustedObservation = await this._observeClickAxTimed(
tabId,
fallbackBaseline,
{ allowDelayed: true, firstDelayMs: 250, pollMs: 150, maxMs: 1000 },
+ timing,
+ 'trustedObservationMs',
);
+ if (timing) timing.safetyVeto ||= trustedObservation?.safetyVeto === true;
this._throwIfAborted(abortSignal);
this._clickAxAddObservedHints(response, trustedObservation);
let trustedTargetStateChanged = false;
let trustedTargetWeakStateChanged = false;
if (!trustedObservation.proved) {
- const trustedTarget = await this._resolveClickAxFallbackTarget(tabId, args?.ref_id, abortSignal);
+ const trustedTarget = await this._measureClickAxStage(
+ timing,
+ 'fallbackPreparationMs',
+ () => this._resolveClickAxFallbackTarget(tabId, args?.ref_id, abortSignal),
+ );
this._throwIfAborted(abortSignal);
const trustedTargetStrongState = strongStateOf(trustedTarget);
const trustedTargetWeakState = weakStateOf(trustedTarget);
diff --git a/src/chrome/src/content/content.js b/src/chrome/src/content/content.js
index 8387e4be1..7ba5259e9 100644
--- a/src/chrome/src/content/content.js
+++ b/src/chrome/src/content/content.js
@@ -6095,7 +6095,9 @@
);
}
dispatched = true;
+ const syntheticClickDispatchStartedAt = performance.now();
const filePickerGuard = clickWithoutNativeFilePicker(() => el.click());
+ const syntheticClickDispatchMs = Math.max(0, performance.now() - syntheticClickDispatchStartedAt);
const fallbackStateAfterImmediate = _axFallbackState(el);
if (filePickerGuard.blocked) {
return failure(
@@ -6127,6 +6129,7 @@
tag,
_preparedActive: preparedActive,
_syntheticClickStartedAt: syntheticClickStartedAt,
+ _syntheticClickDispatchMs: syntheticClickDispatchMs,
_fallbackStateBefore: fallbackStateBefore.full,
_fallbackStateAfterImmediate: fallbackStateAfterImmediate.full,
_fallbackStrongStateBefore: fallbackStateBefore.strong,
diff --git a/src/chrome/src/trace/privacy.js b/src/chrome/src/trace/privacy.js
index afa827238..67dda4269 100644
--- a/src/chrome/src/trace/privacy.js
+++ b/src/chrome/src/trace/privacy.js
@@ -39,6 +39,38 @@ const NOTE_METADATA_FIELDS = [
'adapter', 'revision', 'notesInjected', 'workflowSchema', 'job', 'template',
];
+const CLICK_AX_TIMING_MS_FIELDS = [
+ 'preflightMs', 'syntheticDispatchMs', 'syntheticResponseMs',
+ 'postClickObservationMs', 'fallbackPreparationMs', 'fallbackDispatchMs',
+ 'trustedObservationMs', 'clickPathMs',
+];
+
+function projectClickAxTiming(data) {
+ const extra = {};
+ for (const key of CLICK_AX_TIMING_MS_FIELDS) {
+ const value = data?.extra?.[key];
+ if (typeof value === 'number' && Number.isFinite(value) && value >= 0) {
+ extra[key] = Math.min(value, 120_000);
+ }
+ }
+ const trustedInputEvents = data?.extra?.trustedInputEvents;
+ if (Number.isSafeInteger(trustedInputEvents) && trustedInputEvents >= 0) {
+ extra.trustedInputEvents = Math.min(trustedInputEvents, 16);
+ }
+ for (const key of ['syntheticDispatched', 'trustedFallbackAttempted', 'outcomeUnknown', 'safetyVeto', 'duplicateFallbackBlocked']) {
+ if (typeof data?.extra?.[key] === 'boolean') extra[key] = data.extra[key];
+ }
+ const outcome = data?.extra?.outcome;
+ if (['verified', 'inconclusive', 'no_progress', 'failed', 'pre_dispatch', 'unknown'].includes(outcome)) {
+ extra.outcome = outcome;
+ }
+ return {
+ step: Number.isFinite(data?.step) ? data.step : 0,
+ note: 'click_ax_timing',
+ extra,
+ };
+}
+
function pick(source, fields) {
if (!source || typeof source !== 'object' || Array.isArray(source)) return {};
const output = {};
@@ -113,6 +145,9 @@ export function projectTraceEventData(kind, data, { includeContent = false } = {
if (Object.keys(usage).length) extra.usage = usage;
return { step: Number.isFinite(data.step) ? data.step : 0, note: 'system_one', extra };
}
+ if (kind === 'note' && data?.note === 'click_ax_timing') {
+ return projectClickAxTiming(data);
+ }
if (includeContent || data == null) return data;
const source = data && typeof data === 'object' && !Array.isArray(data) ? data : {};
diff --git a/src/firefox/src/trace/privacy.js b/src/firefox/src/trace/privacy.js
index afa827238..67dda4269 100644
--- a/src/firefox/src/trace/privacy.js
+++ b/src/firefox/src/trace/privacy.js
@@ -39,6 +39,38 @@ const NOTE_METADATA_FIELDS = [
'adapter', 'revision', 'notesInjected', 'workflowSchema', 'job', 'template',
];
+const CLICK_AX_TIMING_MS_FIELDS = [
+ 'preflightMs', 'syntheticDispatchMs', 'syntheticResponseMs',
+ 'postClickObservationMs', 'fallbackPreparationMs', 'fallbackDispatchMs',
+ 'trustedObservationMs', 'clickPathMs',
+];
+
+function projectClickAxTiming(data) {
+ const extra = {};
+ for (const key of CLICK_AX_TIMING_MS_FIELDS) {
+ const value = data?.extra?.[key];
+ if (typeof value === 'number' && Number.isFinite(value) && value >= 0) {
+ extra[key] = Math.min(value, 120_000);
+ }
+ }
+ const trustedInputEvents = data?.extra?.trustedInputEvents;
+ if (Number.isSafeInteger(trustedInputEvents) && trustedInputEvents >= 0) {
+ extra.trustedInputEvents = Math.min(trustedInputEvents, 16);
+ }
+ for (const key of ['syntheticDispatched', 'trustedFallbackAttempted', 'outcomeUnknown', 'safetyVeto', 'duplicateFallbackBlocked']) {
+ if (typeof data?.extra?.[key] === 'boolean') extra[key] = data.extra[key];
+ }
+ const outcome = data?.extra?.outcome;
+ if (['verified', 'inconclusive', 'no_progress', 'failed', 'pre_dispatch', 'unknown'].includes(outcome)) {
+ extra.outcome = outcome;
+ }
+ return {
+ step: Number.isFinite(data?.step) ? data.step : 0,
+ note: 'click_ax_timing',
+ extra,
+ };
+}
+
function pick(source, fields) {
if (!source || typeof source !== 'object' || Array.isArray(source)) return {};
const output = {};
@@ -113,6 +145,9 @@ export function projectTraceEventData(kind, data, { includeContent = false } = {
if (Object.keys(usage).length) extra.usage = usage;
return { step: Number.isFinite(data.step) ? data.step : 0, note: 'system_one', extra };
}
+ if (kind === 'note' && data?.note === 'click_ax_timing') {
+ return projectClickAxTiming(data);
+ }
if (includeContent || data == null) return data;
const source = data && typeof data === 'object' && !Array.isArray(data) ? data : {};
diff --git a/test/run.js b/test/run.js
index 67d605f57..1e76b4f90 100644
--- a/test/run.js
+++ b/test/run.js
@@ -12441,6 +12441,77 @@ test('trace privacy: default persistence keeps metadata and content mode is expl
const safeNote = TRACE_PRIVACY_CH.projectTraceEventData('note', note);
assert.deepEqual(safeNote.extra, { attempt: 2, delayMs: 50, code: 'RATE_LIMIT' });
+ const clickAxTimingExtra = {
+ preflightMs: 12.25,
+ syntheticDispatchMs: 1.5,
+ syntheticResponseMs: 3.25,
+ postClickObservationMs: 250,
+ fallbackPreparationMs: 0,
+ fallbackDispatchMs: 0,
+ trustedObservationMs: 0,
+ clickPathMs: 270,
+ trustedInputEvents: 0,
+ syntheticDispatched: true,
+ trustedFallbackAttempted: false,
+ safetyVeto: true,
+ duplicateFallbackBlocked: false,
+ outcome: 'inconclusive',
+ tabUrl: 'https://private.example.test/path',
+ targetName: 'Private button label',
+ ref_id: 'private-ref',
+ };
+ const projectedClickAxTiming = {
+ step: 4,
+ note: 'click_ax_timing',
+ extra: {
+ preflightMs: 12.25,
+ syntheticDispatchMs: 1.5,
+ syntheticResponseMs: 3.25,
+ postClickObservationMs: 250,
+ fallbackPreparationMs: 0,
+ fallbackDispatchMs: 0,
+ trustedObservationMs: 0,
+ clickPathMs: 270,
+ trustedInputEvents: 0,
+ syntheticDispatched: true,
+ trustedFallbackAttempted: false,
+ safetyVeto: true,
+ duplicateFallbackBlocked: false,
+ outcome: 'inconclusive',
+ },
+ };
+ for (const [label, privacy] of [['chrome', TRACE_PRIVACY_CH], ['firefox', TRACE_PRIVACY_FX]]) {
+ for (const includeContent of [false, true]) {
+ assert.deepEqual(
+ privacy.projectTraceEventData('note', {
+ step: 4,
+ note: 'click_ax_timing',
+ extra: clickAxTimingExtra,
+ }, { includeContent }),
+ projectedClickAxTiming,
+ `${label}: click timing must retain only its numeric and categorical metadata even in the content tier`,
+ );
+ }
+ for (const includeContent of [false, true]) {
+ assert.deepEqual(
+ privacy.projectTraceEventData('note', {
+ step: 5,
+ note: 'click_ax_timing',
+ extra: {
+ outcome: 'unknown',
+ outcomeUnknown: true,
+ tabUrl: 'https://private.example.test/path',
+ },
+ }, { includeContent }),
+ {
+ step: 5,
+ note: 'click_ax_timing',
+ extra: { outcomeUnknown: true, outcome: 'unknown' },
+ },
+ `${label}: unknown click outcomes must remain diagnosable without retaining page content`,
+ );
+ }
+ }
const safeAdapterContext = TRACE_PRIVACY_CH.projectTraceEventData('note', {
step: 0,
note: 'adapter_context',
@@ -59631,6 +59702,114 @@ test('Chrome click_ax skips observation delay and keeps clean success when snaps
assert.match(result.fallbackSkipped, /could not be observed safely/);
});
+test('Chrome click_ax observation wakes on route and safety events without trusting the event alone', async () => {
+ const previousChrome = globalThis.chrome;
+ const createEvent = () => {
+ const listeners = new Set();
+ return {
+ addListener(listener) { listeners.add(listener); },
+ removeListener(listener) { listeners.delete(listener); },
+ fire(...args) { for (const listener of [...listeners]) listener(...args); },
+ get listenerCount() { return listeners.size; },
+ };
+ };
+ const events = {
+ download: createEvent(),
+ request: createEvent(),
+ tabCreated: createEvent(),
+ tabRemoved: createEvent(),
+ tabUpdated: createEvent(),
+ };
+ globalThis.chrome = {
+ downloads: { onCreated: events.download },
+ webRequest: { onBeforeRequest: events.request },
+ tabs: {
+ onCreated: events.tabCreated,
+ onRemoved: events.tabRemoved,
+ onUpdated: events.tabUpdated,
+ },
+ };
+ const agent = new AgentCh({});
+ const before = JSON.stringify({ url: 'https://example.test/', text: 'same', media: '', controls: '', active: '' });
+ let snapshot = before;
+ let tabs = '1,42';
+ const results = [];
+ agent._clickProgressSnapshot = async () => snapshot;
+ agent._clickAxTabSnapshot = async () => tabs;
+
+ const observeAfterSignal = async (fire, { proved = false, safetyVeto = false } = {}) => {
+ const watch = agent._beginClickAxSideEffectWatch(42);
+ const baseline = {
+ startedAt: Date.now(),
+ snapshot: before,
+ tabIds: '1,42',
+ sideEffectWatch: watch,
+ signalVersion: watch.signalVersion,
+ };
+ const timer = setTimeout(fire, 20);
+ const started = performance.now();
+ try {
+ const observation = await agent._observeClickAxSideEffect(42, baseline, {
+ firstDelayMs: 250,
+ pollMs: 150,
+ maxMs: 1250,
+ });
+ const elapsedMs = performance.now() - started;
+ assert.ok(elapsedMs < 230, `expected an event-driven sample, got ${Math.round(elapsedMs)} ms`);
+ assert.equal(observation.proved, proved);
+ assert.equal(observation.safetyVeto, safetyVeto);
+ if (safetyVeto) assert.equal(observation.proved, false, 'a safety event must not become click success proof');
+ results.push(observation);
+ } finally {
+ clearTimeout(timer);
+ watch.stop();
+ }
+ };
+
+ try {
+ snapshot = before;
+ await observeAfterSignal(() => {
+ snapshot = before.replace('example.test/', 'example.test/next');
+ events.tabUpdated.fire(42, { url: 'https://example.test/next' });
+ }, { proved: true });
+
+ snapshot = before;
+ await observeAfterSignal(() => {
+ events.request.fire({
+ tabId: 42,
+ url: 'https://example.test/api/mutate',
+ method: 'POST',
+ type: 'xmlhttprequest',
+ requestId: 'request-1',
+ });
+ }, { safetyVeto: true });
+
+ snapshot = before;
+ await observeAfterSignal(() => {
+ events.download.fire({ id: 7, filename: 'download.zip' });
+ }, { safetyVeto: true });
+
+ snapshot = before;
+ tabs = '1,42';
+ await observeAfterSignal(() => {
+ tabs = '1,42,43';
+ events.tabCreated.fire({ id: 43 });
+ }, { safetyVeto: true });
+
+ tabs = '1,42';
+ await observeAfterSignal(() => {
+ tabs = '1';
+ events.tabRemoved.fire(42, { windowId: 1, isWindowClosing: false });
+ }, { safetyVeto: true });
+
+ assert.equal(results.length, 5);
+ assert.ok(Object.values(events).every(event => event.listenerCount === 0), 'all watcher listeners must be removed');
+ } finally {
+ if (previousChrome === undefined) delete globalThis.chrome;
+ else globalThis.chrome = previousChrome;
+ }
+});
+
test('Chrome click_ax trusted phase carries preparedActive so blur-only is not proof', async () => {
const originals = {
attach: cdpClientCh.attach,