Skip to content

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

fix: address recipient guard review findings

release-verificationadfb622f22d7
diff --git a/src/chrome/src/agent/adapters.js b/src/chrome/src/agent/adapters.js
index d254b0c25..d2c9c6a68 100644
--- a/src/chrome/src/agent/adapters.js
+++ b/src/chrome/src/agent/adapters.js
@@ -18187,29 +18187,20 @@ export function getFullPageCapturePolicy(url) {
}
}
-/**
- * Messaging / webmail surfaces that have no first-party adapter but still get
- * the same recipient verification and confirm-then-send flow. Matched against
- * `hostname + pathname`, so it covers both known providers and generic
- * messaging routes on any site (/messages, /chat, /dm, /compose, /inbox, ...).
- */
+// Generic mail routes may legitimately show a To/Cc/Bcc set. Generic chat
+// routes must resolve to one visible conversation identity before dispatch.
const GENERIC_MESSAGING_SURFACE_RE = new RegExp(
'(?:^|\\.)(?:mail|webmail|outlook|hotmail|yahoo|proton|zoho|fastmail|icloud|gmx|tutanota|roundcube|horde|zimbra)\\b'
+ '|(?:^|\\.)(?:whatsapp|telegram|discord|slack|messenger|wechat|signal|skype|teams|element|mattermost)\\.'
- + '|/(?:mail|messages?|chats?|dm|direct|inbox|compose|conversations?)(?:/|$)',
+ + '|/(?:mail|messag(?:e|es|ing)|chats?|dm|direct|compose|conversations?)(?:/|$)',
'i',
);
-// Mail-like surfaces carry a To/Cc/Bcc set; chat-like surfaces address one
-// conversation. Only the verification shape differs — both get the same
-// confirm-then-send flow.
const GENERIC_MESSAGING_MAIL_LIKE_RE = new RegExp(
'(?:^|\\.)(?:mail|webmail|outlook|hotmail|yahoo|proton|zoho|fastmail|icloud|gmx|tutanota|roundcube|horde|zimbra)\\b'
- + '|/(?:mail|compose|inbox)(?:/|$)',
+ + '|/(?:mail|compose)(?:/|$)',
'i',
);
-
-
/**
* Return the machine-readable recipient-safety policy for a messaging page.
* Unlike adapter notes, this is enforced by the runtime before dispatch.
@@ -18224,14 +18215,6 @@ export function getMessageRecipientGuardPolicy(url) {
enabled = false;
}
if (!enabled) {
- // Any page on the web may host a messaging or mail surface. The recipient
- // guard is therefore generic-first: arm it everywhere and let the
- // content-side recipient extraction decide whether this page is actually
- // sending something. If it finds no address and no conversation header,
- // nothing is a send and no action is blocked; when it does find one, the
- // same verify → ask → authorize flow used by Gmail applies. These entries
- // only pick the verification shape (single conversation identity vs a
- // To/Cc/Bcc set).
let mailLike = false;
let chatLike = false;
try {
@@ -18239,14 +18222,12 @@ export function getMessageRecipientGuardPolicy(url) {
const hostPath = `${parsed.hostname}${parsed.pathname}`;
mailLike = GENERIC_MESSAGING_MAIL_LIKE_RE.test(hostPath);
chatLike = !mailLike && GENERIC_MESSAGING_SURFACE_RE.test(hostPath);
- } catch {
- mailLike = false;
- chatLike = false;
- }
+ } catch {}
+ if (!mailLike && !chatLike) return null;
return {
- adapterName: adapter?.name || 'generic-messaging',
+ adapterName: 'generic-messaging',
verifyActiveRecipient: true,
- ...(mailLike || chatLike ? { supportsRecipientSets: true } : {}),
+ ...(mailLike ? { supportsRecipientSets: true } : {}),
};
}
return {
diff --git a/src/chrome/src/agent/agent.js b/src/chrome/src/agent/agent.js
index 064149735..03864d006 100644
--- a/src/chrome/src/agent/agent.js
+++ b/src/chrome/src/agent/agent.js
@@ -1080,6 +1080,9 @@ export class Agent extends LoopDetector {
this.deliveryObservationStreaks = new Map(); // tabId -> count
this.deliveryActionableDiscoveryResets = new Set(); // tabIds that used their one discovery reset since meaningful progress
this.lastAutoScreenshotTs = new Map(); // tabId -> ms — defensive debounce
+ // tabId -> { toolName, streak }. Burst state must not leak across tabs or
+ // be consumed by read-only preflight checks.
+ this.autoScreenshotBursts = new Map();
this.lastSeenAdapter = new Map(); // tabId -> adapter name from last enrichment
this.pendingAdapterMatchTraces = new Map(); // tabId -> Map(adapter@revision -> content-free match metadata)
this.adapterMatchTraceKeys = new Map(); // runId -> Map(adapter@revision -> OR-merged match metadata)
@@ -9131,24 +9134,19 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
&& opts.turnCaptures >= this.maxScreenshotsPerTurn) {
return false;
}
- // Repetition-aware budget. A burst of the SAME action (invite N people,
- // like N posts, click through a list) barely moves the page between steps,
- // yet the default `state_change` mode paid an image plus a full vision LLM
- // call for every one of them — the largest avoidable token and latency cost
- // in a run. Capture the first action of a burst, then only every 4th, so a
- // long burst still gets periodic visual evidence. A different action resets
- // the burst, because that usually does change what is on screen.
- //
- // Deliberately not time-based: consecutive agent steps are seconds apart
- // because each contains an LLM round trip, so an idle-gap throttle would
- // never engage.
- if (this._autoScreenshotLastTool !== toolName) {
- this._autoScreenshotLastTool = toolName;
- this._autoScreenshotSameToolStreak = 1;
- return true;
- }
- this._autoScreenshotSameToolStreak = (Number(this._autoScreenshotSameToolStreak) || 1) + 1;
- return this._autoScreenshotSameToolStreak % 4 === 1;
+ return true;
+ }
+
+ // Advance the burst only after a successful post-dispatch capture request.
+ // _shouldAutoScreenshot is used by preflight, so it must remain pure.
+ _advanceAutoScreenshotBurst(tabId, toolName) {
+ if (this.autoScreenshot === 'navigation') return true;
+ const normalizedTool = String(toolName || '');
+ if (!normalizedTool) return true;
+ const prior = this.autoScreenshotBursts.get(tabId);
+ const streak = prior?.toolName === normalizedTool ? prior.streak + 1 : 1;
+ this.autoScreenshotBursts.set(tabId, { toolName: normalizedTool, streak });
+ return streak === 1 || streak % 4 === 1;
}
/**
@@ -11598,6 +11596,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
async _executeToolBatchInner(tabId, toolCalls, messages, onUpdate, provider, partialAssistantText, allowedToolNames, step, runOptions, toolSchemas, cancellationState) {
let didStateChange = false;
+ let autoScreenshotToolName = '';
const apiMutationsDeniedForRun = runOptions.apiMutationsDenied === true;
const apiMutationsAllowedForRun = () =>
!apiMutationsDeniedForRun && this.isApiMutationsAllowed(tabId);
@@ -13572,7 +13571,10 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
// The interruption helper already emitted the queued synthetic results
// and navigation notice. Continue through the shared post-batch path so
// state_change/every_step auto-screenshots still reach the fresh turn.
- if (this._shouldAutoScreenshot(fnName) && !toolResult?.error) didStateChange = true;
+ if (this._shouldAutoScreenshot(fnName) && !toolResult?.error) {
+ didStateChange = true;
+ autoScreenshotToolName = fnName;
+ }
navNotices.length = 0;
break;
}
@@ -13622,6 +13624,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
if (this._shouldAutoScreenshot(fnName) && !toolResult?.error) {
didStateChange = true;
+ autoScreenshotToolName = fnName;
}
}
@@ -13632,12 +13635,14 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
// Auto-screenshot once per batch, debounced 500ms. Capture if either
// the main provider supports images, or a dedicated vision model is
// configured to describe them.
+ const captureAfterBatch = didStateChange
+ && this._advanceAutoScreenshotBurst(tabId, autoScreenshotToolName);
const visionRoute = await this._resolveVisionRoute(tabId, provider);
- if (didStateChange && !visionRoute.provider && visionRoute.visionStatus) {
+ if (captureAfterBatch && !visionRoute.provider && visionRoute.visionStatus) {
this._recordVisionRouteTrace(tabId, visionRoute, null, 'auto_screenshot');
this._emitVisionUnavailableNotice(tabId, visionRoute, onUpdate, 'Automatic screenshot');
}
- if (didStateChange && visionRoute.provider) {
+ if (captureAfterBatch && visionRoute.provider) {
const lastTs = this.lastAutoScreenshotTs.get(tabId) || 0;
if (Date.now() - lastTs >= 500) {
await new Promise(r => setTimeout(r, 250));
@@ -23372,35 +23377,6 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
return null;
}
- // A send-labelled control on a page that exposes NO recipient identity at
- // all is a contact/feedback form, not a message with an addressee to
- // protect — the recipient guard has nothing to verify there, and blocking
- // it would loop the agent on a page that cannot ever answer. Known
- // adapters keep their stricter behaviour; on generic surfaces we fail open
- // and let the separate submit-confirmation gate govern the submission.
- if (probe?.success === true
- && probe?.conclusive === true
- && probe?.messageSend === true
- && observedIdentities.length === 0
- && policy?.adapterName === 'generic-messaging') {
- return null;
- }
-
- // Unclassifiable actions pass through.
- //
- // A recipient guard exists to stop a mis-addressed MESSAGE — it must never
- // veto an action the classifier could not place. Blocking these produced
- // "could not conclusively resolve the target control and active composer"
- // on pages that were perfectly usable, made the agent give up and report a
- // blocker, and forced the user to re-confirm forever. Only a CONFIDENT send
- // classification reaches the recipient verification below; everything the
- // probe could not resolve is left to the normal dispatch path, which
- // enforces its own target resolution, permission gate, and submit
- // confirmation.
- if (probe?.success !== true || probe?.conclusive !== true || probe?.messageSend !== true) {
- return null;
- }
-
// Retain what the page actually showed only when the plan already permits
// messaging and has pre-existing messaging authorization. The block below
// tells the model to ask the user who the message is for, and that answer
@@ -25958,6 +25934,7 @@ If the user has already named or confirmed this exact recipient, do NOT ask agai
this._continuationResponseLanguagePolicies.delete(tabId);
this.mastodonStates.delete(tabId);
this.lastAutoScreenshotTs.delete(tabId);
+ this.autoScreenshotBursts.delete(tabId);
this.autoScreenshotCount.delete(tabId);
this.toolbarAuditScreenshotCount.delete(tabId);
this.toolbarAuditBudgetNotified.delete(tabId);
@@ -41725,6 +41702,7 @@ If the user has already named or confirmed this exact recipient, do NOT ask agai
this.pendingVisionSubCallTraces.delete(tabId);
this.visionStatusNotices.delete(tabId);
// Reset the per-turn auto-screenshot budget (issue #311) for a fresh turn.
+ this.autoScreenshotBursts.delete(tabId);
this.autoScreenshotCount.delete(tabId);
this.toolbarAuditScreenshotCount.delete(tabId);
this.toolbarAuditBudgetNotified.delete(tabId);
@@ -43132,6 +43110,7 @@ If the user has already named or confirmed this exact recipient, do NOT ask agai
this.pendingVisionSubCallTraces.delete(tabId);
this.visionStatusNotices.delete(tabId);
// Reset the per-turn auto-screenshot budget (issue #311) for a fresh turn.
+ this.autoScreenshotBursts.delete(tabId);
this.autoScreenshotCount.delete(tabId);
this.toolbarAuditScreenshotCount.delete(tabId);
this.toolbarAuditBudgetNotified.delete(tabId);
diff --git a/src/chrome/src/content/content.js b/src/chrome/src/content/content.js
index 2f71e4248..82d28f8ff 100644
--- a/src/chrome/src/content/content.js
+++ b/src/chrome/src/content/content.js
@@ -1390,12 +1390,14 @@
// (including every shadow host) and reads innerText per match. clickElement,
// the recipient preflight, and every retry all call it. Cache the result and
// reuse it until the DOM actually changes.
- const _domRevision = { value: 0, observer: null };
- function _ensureDomRevisionObserver() {
- if (_domRevision.observer || typeof MutationObserver === 'undefined') return;
+ const _domRevision = { value: 0, observer: null, observedRoots: new WeakSet() };
+ function _observeDomRevisionRoot(root) {
+ if (!root || _domRevision.observedRoots.has(root) || typeof MutationObserver === 'undefined') return;
try {
- _domRevision.observer = new MutationObserver(() => { _domRevision.value += 1; });
- _domRevision.observer.observe(document, {
+ if (!_domRevision.observer) {
+ _domRevision.observer = new MutationObserver(() => { _domRevision.value += 1; });
+ }
+ _domRevision.observer.observe(root, {
childList: true,
subtree: true,
attributes: true,
@@ -1407,11 +1409,17 @@
'class', 'style', 'role', 'tabindex',
],
});
+ _domRevision.observedRoots.add(root);
} catch {
- _domRevision.observer = null;
+ // Some roots cannot be observed. The uncached caller still retains the
+ // original click behaviour; do not prevent other roots from registering.
}
}
+ function _ensureDomRevisionObserver() {
+ _observeDomRevisionRoot(document);
+ }
+
const _textCandidateCache = new WeakMap();
function _clickTextCandidates(scope) {
_ensureDomRevisionObserver();
@@ -1432,6 +1440,7 @@
// labels across roots, without searching outside the selected modal.
const candidates = [];
const visit = (root) => {
+ _observeDomRevisionRoot(root);
candidates.push(...root.querySelectorAll(selectors));
if (root.shadowRoot) visit(root.shadowRoot);
for (const host of root.querySelectorAll('*')) {
@@ -1440,11 +1449,10 @@
};
visit(cacheScope);
const out = [];
- const seen = new Set();
for (const e of candidates) {
if (!_hasVisibleBox(e)) continue;
const text = _siteInteractionText(e).toLowerCase();
- if (text && !seen.has(`${text}\u0000${out.length}`)) out.push({ e, txt: text });
+ if (text) out.push({ e, txt: text });
// A control's aria-label / title / placeholder often names it far better
// than its visible glyphs — icon-only buttons and combobox-style fields
// ("Search for contacts") are unreachable by visible text alone. Offer
@@ -5165,7 +5173,8 @@
).replace(/\s+/g, ' ').trim();
if (label && _COMPOSER_UTILITY_LABEL_RE.test(label)) return true;
// Formatting toolbars and pressed toggles are structural non-sends.
- if (el.closest?.('[role="toolbar"],[aria-label*="formatting" i],[aria-label*="format" i]')) return true;
+ const formattingScope = el.closest?.('[role="toolbar"],[aria-label*="formatting" i],[aria-label*="format" i]');
+ if (formattingScope && formattingScope !== el) return true;
if (el.hasAttribute?.('aria-pressed')) return true;
return false;
} catch {
@@ -5855,32 +5864,6 @@
const verticalGap = Math.max(0, composerRect.top - controlRect.bottom, controlRect.top - composerRect.bottom);
messageSend = sameForm || (horizontalGap <= 240 && verticalGap <= 120);
if (!messageSend) {
- // The control is geometrically far from the composer and not in the
- // same form, so clicking it cannot commit the message. Geometry alone
- // is enough evidence — but only after also ruling out a send-labelled
- // control and anything inside the app's messaging surface, both of
- // which can commit without sitting near the composer. That second
- // check is what makes far-away controls self-healing instead of
- // being blocked as "inconclusive" and retried in a loop.
- const farLabel = compact(
- control.getAttribute?.('aria-label')
- || control.getAttribute?.('title')
- || control.getAttribute?.('data-tooltip')
- || control.value
- || control.innerText
- || control.textContent,
- 120,
- );
- if (!_hasMessageCommitName(farLabel) && !_inMessagingSurface(control)) {
- return {
- success: true,
- messageSend: false,
- conclusive: true,
- nonMessagingTarget: true,
- reasonCode: 'non_messaging_target',
- identityCandidates: [],
- };
- }
return { success: true, messageSend: null, conclusive: false, identityCandidates: [] };
}
}
@@ -6220,6 +6203,8 @@
// depending on one vendor's markup. This is what makes confirm-then-send
// work globally rather than only on Gmail.
if (observedRecipientCandidates.length === 0) {
+ const genericMailRecipientMode = params.adapterName === 'generic-messaging'
+ && params.supportsRecipientSets === true;
const RECIPIENT_FIELD_RE = new RegExp(
'(?:^|[^\\p{L}])(?:to|to\\s+recipients?|recipients?|send\\s+to|email|e-?mail(?:\\s+address)?'
+ '|destinatario|destinataria|destinataire|para|aan|kime|do|til|komu|\\u0644\\u0625\\u0649'
@@ -6228,8 +6213,8 @@
);
const fieldLooksLikeRecipient = (el) => {
try {
- if (/^email$/i.test(String(el.getAttribute?.('type') || ''))) return true;
- if (/^email$/i.test(String(el.getAttribute?.('autocomplete') || ''))) return true;
+ if (/^email$/i.test(String(el.getAttribute?.('type') || ''))) return genericMailRecipientMode;
+ if (/^email$/i.test(String(el.getAttribute?.('autocomplete') || ''))) return genericMailRecipientMode;
const haystack = [
el.getAttribute?.('name'),
el.getAttribute?.('aria-label'),
@@ -6290,6 +6275,8 @@
'[email],[data-email],[data-hovercard-id],a[href^="mailto:" i],input[type="email"]',
)).slice(0, 40)) {
if (!visible(el) || el === composer || composer?.contains?.(el)) continue;
+ if (!genericMailRecipientMode
+ && /^email$/i.test(String(el.getAttribute?.('type') || ''))) continue;
const mailto = String(el.getAttribute?.('href') || '')
.replace(/^mailto:/i, '').split('?')[0];
const address = [
diff --git a/src/firefox/src/agent/adapters.js b/src/firefox/src/agent/adapters.js
index ecf214489..650ed7ecd 100644
--- a/src/firefox/src/agent/adapters.js
+++ b/src/firefox/src/agent/adapters.js
@@ -18185,6 +18185,20 @@ export function getFullPageCapturePolicy(url) {
}
}
+// Generic mail routes may legitimately show a To/Cc/Bcc set. Generic chat
+// routes must resolve to one visible conversation identity before dispatch.
+const GENERIC_MESSAGING_SURFACE_RE = new RegExp(
+ '(?:^|\\.)(?:mail|webmail|outlook|hotmail|yahoo|proton|zoho|fastmail|icloud|gmx|tutanota|roundcube|horde|zimbra)\\b'
+ + '|(?:^|\\.)(?:whatsapp|telegram|discord|slack|messenger|wechat|signal|skype|teams|element|mattermost)\\.'
+ + '|/(?:mail|messag(?:e|es|ing)|chats?|dm|direct|compose|conversations?)(?:/|$)',
+ 'i',
+);
+const GENERIC_MESSAGING_MAIL_LIKE_RE = new RegExp(
+ '(?:^|\\.)(?:mail|webmail|outlook|hotmail|yahoo|proton|zoho|fastmail|icloud|gmx|tutanota|roundcube|horde|zimbra)\\b'
+ + '|/(?:mail|compose)(?:/|$)',
+ 'i',
+);
+
/**
* Return the machine-readable recipient-safety policy for a messaging page.
* Unlike adapter notes, this is enforced by the runtime before dispatch.
@@ -18198,7 +18212,22 @@ export function getMessageRecipientGuardPolicy(url) {
} catch {
enabled = false;
}
- if (!enabled) return null;
+ if (!enabled) {
+ let mailLike = false;
+ let chatLike = false;
+ try {
+ const parsed = new URL(url);
+ const hostPath = `${parsed.hostname}${parsed.pathname}`;
+ mailLike = GENERIC_MESSAGING_MAIL_LIKE_RE.test(hostPath);
+ chatLike = !mailLike && GENERIC_MESSAGING_SURFACE_RE.test(hostPath);
+ } catch {}
+ if (!mailLike && !chatLike) return null;
+ return {
+ adapterName: 'generic-messaging',
+ verifyActiveRecipient: true,
+ ...(mailLike ? { supportsRecipientSets: true } : {}),
+ };
+ }
return {
adapterName: adapter.name,
verifyActiveRecipient: true,
diff --git a/src/firefox/src/agent/agent.js b/src/firefox/src/agent/agent.js
index 01678fad6..1da212720 100644
--- a/src/firefox/src/agent/agent.js
+++ b/src/firefox/src/agent/agent.js
@@ -902,6 +902,9 @@ export class Agent extends LoopDetector {
// default — loaded from browser.storage.local in background.js.
this.screenshotRedaction = false;
this.lastAutoScreenshotTs = new Map();
+ // tabId -> { toolName, streak } for post-dispatch screenshot throttling.
+ // It is deliberately independent per tab and reset for every run.
+ this.autoScreenshotBursts = new Map();
this.lastSeenAdapter = new Map();
this.pendingAdapterMatchTraces = new Map(); // tabId -> Map(adapter@revision -> content-free match metadata)
this.adapterMatchTraceKeys = new Map(); // runId -> Map(adapter@revision -> OR-merged match metadata)
@@ -8672,13 +8675,35 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
return { imageBlockCount, documentBlockCount };
}
- _shouldAutoScreenshot(toolName) {
+ _shouldAutoScreenshot(toolName, opts = {}) {
const mode = this.autoScreenshot;
if (mode === 'off' || !mode) return false;
- if (mode === 'every_step') return true;
- if (mode === 'state_change') return Agent.STATE_CHANGE_TOOLS.has(toolName);
- if (mode === 'navigation') return Agent.NAV_TOOLS.has(toolName);
- return false;
+ if (opts.domEvidenceProven === true) return false;
+ const isStateChange = Agent.STATE_CHANGE_TOOLS.has(toolName);
+ const eligible = mode === 'every_step'
+ || (mode === 'state_change' && isStateChange)
+ || (mode === 'navigation' && Agent.NAV_TOOLS.has(toolName));
+ if (!eligible) return false;
+ if (mode === 'navigation') return true;
+ if (Number.isFinite(opts.turnCaptures) && Number.isFinite(this.maxScreenshotsPerTurn)
+ && this.maxScreenshotsPerTurn > 0
+ && opts.turnCaptures >= this.maxScreenshotsPerTurn) {
+ return false;
+ }
+ return true;
+ }
+
+ // Advance only after a successful action batch has requested a screenshot.
+ // _shouldAutoScreenshot is also used by preflight, so it must remain a pure
+ // predicate and cannot consume a capture slot or burst position.
+ _advanceAutoScreenshotBurst(tabId, toolName) {
+ if (this.autoScreenshot === 'navigation') return true;
+ const normalizedTool = String(toolName || '');
+ if (!normalizedTool) return true;
+ const prior = this.autoScreenshotBursts.get(tabId);
+ const streak = prior?.toolName === normalizedTool ? prior.streak + 1 : 1;
+ this.autoScreenshotBursts.set(tabId, { toolName: normalizedTool, streak });
+ return streak === 1 || streak % 4 === 1;
}
async _currentUrl(tabId) {
@@ -10180,6 +10205,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
async _executeToolBatchInner(tabId, toolCalls, messages, onUpdate, provider, partialAssistantText, allowedToolNames, step, runOptions, toolSchemas, cancellationState) {
let didStateChange = false;
+ let autoScreenshotToolName = '';
const apiMutationsDeniedForRun = runOptions.apiMutationsDenied === true;
const apiMutationsAllowedForRun = () =>
!apiMutationsDeniedForRun && this.isApiMutationsAllowed(tabId);
@@ -11984,7 +12010,10 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
// The interruption helper already emitted the queued synthetic results
// and navigation notice. Continue through the shared post-batch path so
// state_change/every_step auto-screenshots still reach the fresh turn.
- if (this._shouldAutoScreenshot(fnName) && !toolResult?.error) didStateChange = true;
+ if (this._shouldAutoScreenshot(fnName) && !toolResult?.error) {
+ didStateChange = true;
+ autoScreenshotToolName = fnName;
+ }
navNotices.length = 0;
break;
}
@@ -12032,6 +12061,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
}
if (this._shouldAutoScreenshot(fnName) && !toolResult?.error) {
didStateChange = true;
+ autoScreenshotToolName = fnName;
}
}
@@ -12040,8 +12070,10 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
// Auto-screenshot after state change. Capture if either the main
// provider supports images, or a dedicated vision model is configured
// to describe them.
+ const captureAfterBatch = didStateChange
+ && this._advanceAutoScreenshotBurst(tabId, autoScreenshotToolName);
const visionRoute = await this._resolveVisionRoute(tabId, provider);
- if (didStateChange && visionRoute.provider) {
+ if (captureAfterBatch && visionRoute.provider) {
const lastTs = this.lastAutoScreenshotTs.get(tabId) || 0;
if (Date.now() - lastTs >= 500) {
await new Promise(r => setTimeout(r, 250));
@@ -21019,12 +21051,23 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
? this._resolveTwitterNamedMessagingTarget(target, probe) : null;
if (resolvedTwitterTarget) target = resolvedTwitterTarget;
const messageBodyBaselineCount = Number(probe?.messageBodyBaselineCount);
+ const targetMatchesObserved = messageTargetMatchesObservedIdentities(
+ target,
+ this._messageRecipientCandidates(probe),
+ );
+ const observedIdentities = this._messageRecipientCandidates(probe)
+ .map(item => normalizeRecipientIdentity(item?.identity || item))
+ .filter(Boolean);
+ const approvedRecipients = Array.isArray(guard?.approvedRecipients) ? guard.approvedRecipients : [];
+ const approvedByUser = guard?.messageRecipientApprovedAll === true
+ || (observedIdentities.length > 0
+ && observedIdentities.every(identity => approvedRecipients.includes(identity)));
const verified = probe?.success === true
&& probe.messageSend === true
&& !!this._workflowMessageBody(probe?.messageBody)
&& Number.isInteger(messageBodyBaselineCount)
&& messageBodyBaselineCount >= 0
- && messageTargetMatchesObservedIdentities(target, this._messageRecipientCandidates(probe));
+ && (targetMatchesObserved || approvedByUser);
if (verified) {
const binding = probe?.messageRecipientDispatchBinding;
if (!binding?.token) {
@@ -21050,6 +21093,16 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
executionContext.messageRecipientTwitterEmptyConversationBaseline = true;
}
}
+ if (!targetMatchesObserved && approvedByUser && observedIdentities.length > 0) {
+ const approvedTarget = normalizeMessageTarget({
+ target_kind: 'named',
+ recipients: this._messageRecipientCandidates(probe).map(item => ({
+ identity: item?.identity || item,
+ role: item?.role || 'to',
+ })),
+ });
+ if (approvedTarget && guard) guard.messaging = approvedTarget;
+ }
if (probe.composerSubjectAvailable === true) {
executionContext.messageRecipientSubject = this._workflowMetadataValue(probe.composerSubject);
executionContext.messageRecipientSubjectAvailable = true;
@@ -21206,11 +21259,24 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
}
const normalizedAnswer = normalizeRecipientAnswer(answer);
if (!normalizedAnswer) return false;
- if (!answerNamesAllObservedRecipients(normalizedAnswer, observed)) return false;
- const resolvedRecipients = resolveClarifiedRecipients(observed, guard.messaging, clarifyContext, answer);
+ const allowAllSends = /(?:^|[^\p{L}])(?:all|everything|any|every|allow\s+all|send\s+all)(?:[^\p{L}]|$)/iu
+ .test(normalizedAnswer);
+ if (!allowAllSends && !answerNamesAllObservedRecipients(normalizedAnswer, observed)) return false;
+ const resolvedRecipients = allowAllSends
+ ? observed
+ .map(item => ({ identity: item?.identity || item, role: item?.role || 'to' }))
+ .filter(recipient => recipient.identity)
+ : resolveClarifiedRecipients(observed, guard.messaging, clarifyContext, answer);
const target = normalizeMessageTarget({ target_kind: 'named', recipients: resolvedRecipients });
if (!target) return false;
guard.messaging = target;
+ const approved = Array.isArray(guard.approvedRecipients) ? guard.approvedRecipients.slice() : [];
+ for (const recipient of target.recipients || []) {
+ const identity = normalizeRecipientIdentity(recipient?.identity || recipient);
+ if (identity && !approved.includes(identity)) approved.push(identity);
+ }
+ guard.approvedRecipients = approved;
+ if (allowAllSends) guard.messageRecipientApprovedAll = true;
return true;
}
@@ -24394,6 +24460,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
this._standaloneChatRunTabs.delete(tabId);
this.mastodonStates.delete(tabId);
this.lastAutoScreenshotTs.delete(tabId);
+ this.autoScreenshotBursts.delete(tabId);
this.autoScreenshotCount.delete(tabId);
this.toolbarAuditScreenshotCount.delete(tabId);
this.toolbarAuditBudgetNotified.delete(tabId);
@@ -34019,6 +34086,29 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
};
try {
let response = await dispatchContentAction();
+ if (response === undefined || response === null) {
+ // An orphaned content script can still receive the message but be
+ // unable to reply after an extension reload or update. Reinject the
+ // current bundle once so its generation-aware startup can replace the
+ // stale copy, then require a definite response before continuing.
+ try {
+ await runContentActionStage(() => this._injectCoreContentScripts(tabId));
+ response = await dispatchContentAction();
+ } catch (eInj) {
+ if (eInj?.code === 'content_action_timeout') throw eInj;
+ response = undefined;
+ }
+ if (response === undefined || response === null) {
+ return this._withCoordinateReconciliation({
+ success: false,
+ dispatched: false,
+ noDispatch: true,
+ retryable: true,
+ staleContentScript: true,
+ error: `${name} received no answer from the page. The content script may be stale for this tab (reload the tab, or toggle the extension off/on) or the page blocked script injection. Re-observe the page before retrying.`,
+ }, coordinateDiagnostic);
+ }
+ }
const deadlineResult = provenNoDispatchDeadline(response);
if (deadlineResult) return this._withCoordinateReconciliation(deadlineResult, coordinateDiagnostic);
if (name === 'click') {
@@ -34546,6 +34636,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
this.pendingVisionRouteTraces.delete(tabId);
this.pendingVisionSubCallTraces.delete(tabId);
// Reset the per-turn auto-screenshot budget (issue #311) for a fresh turn.
+ this.autoScreenshotBursts.delete(tabId);
this.autoScreenshotCount.delete(tabId);
this.toolbarAuditScreenshotCount.delete(tabId);
this.toolbarAuditBudgetNotified.delete(tabId);
@@ -35782,6 +35873,7 @@ Rules: no prose intro, no conclusion, no "this screenshot shows...", no layout d
this.pendingVisionRouteTraces.delete(tabId);
this.pendingVisionSubCallTraces.delete(tabId);
// Reset the per-turn auto-screenshot budget (issue #311) for a fresh turn.
+ this.autoScreenshotBursts.delete(tabId);
this.autoScreenshotCount.delete(tabId);
this.toolbarAuditScreenshotCount.delete(tabId);
this.toolbarAuditBudgetNotified.delete(tabId);
diff --git a/src/firefox/src/content/content.js b/src/firefox/src/content/content.js
index 1ef8a9633..06bf530be 100644
--- a/src/firefox/src/content/content.js
+++ b/src/firefox/src/content/content.js
@@ -4,8 +4,11 @@
*/
(() => {
- // Prevent double-injection
- if (window.__webbrain_injected) return;
+ // Take over from an orphaned installation. A reload or update leaves the
+ // old content script in the page with a dead runtime context; the newest
+ // copy must be the only listener that answers subsequent tool calls.
+ window.__webbrain_generation = (Number(window.__webbrain_generation) || 0) + 1;
+ const WEBBRAIN_GENERATION = window.__webbrain_generation;
window.__webbrain_injected = true;
const PAGE_GATE_SELECTORS = [
@@ -470,7 +473,8 @@
const descriptor = window.__wbSiteInteractions?.describe?.(el);
if (descriptor?.name) return descriptor.name;
} catch {}
- return (el?.innerText || el?.value || el?.placeholder || el?.title || el?.ariaLabel || '').trim();
+ const aria = el?.getAttribute?.('aria-label') || el?.ariaLabel || '';
+ return (el?.innerText || el?.value || el?.placeholder || el?.title || aria || '').trim();
}
function _isSiteInteractive(el) {
@@ -1307,12 +1311,43 @@
// Shared by click dispatch and its recipient-safety preflight. Keep the
// Firefox option visibility and input-label rules identical in both paths.
+ // Text candidate discovery walks every open shadow root, so each discovered
+ // root must invalidate the cache when its own subtree changes.
+ const _domRevision = { value: 0, observer: null, observedRoots: new WeakSet() };
+ function _observeDomRevisionRoot(root) {
+ if (!root || _domRevision.observedRoots.has(root) || typeof MutationObserver === 'undefined') return;
+ try {
+ if (!_domRevision.observer) {
+ _domRevision.observer = new MutationObserver(() => { _domRevision.value += 1; });
+ }
+ _domRevision.observer.observe(root, {
+ childList: true,
+ subtree: true,
+ attributes: true,
+ attributeFilter: [
+ 'aria-label', 'aria-labelledby', 'title', 'placeholder', 'value', 'disabled',
+ 'aria-expanded', 'aria-selected', 'aria-checked', 'aria-hidden', 'hidden',
+ 'class', 'style', 'role', 'tabindex',
+ ],
+ });
+ _domRevision.observedRoots.add(root);
+ } catch { /* leave other observable roots cacheable */ }
+ }
+
+ const _textCandidateCache = new WeakMap();
function _clickTextCandidates(scope) {
+ _observeDomRevisionRoot(document);
+ const revision = _domRevision.value;
+ const cacheScope = scope && typeof scope === 'object' ? scope : document;
+ const cached = _textCandidateCache.get(cacheScope);
+ if (cached && cached.revision === revision) return cached.list.slice();
const sels = [
'a', 'button', '[role="button"]', '[role="link"]', '[role="tab"]', '[role="menuitem"]',
'[role="option"]', '[role="menuitemradio"]', '[role="menuitemcheckbox"]', '[role="treeitem"]',
+ '[role="combobox"]', '[role="searchbox"]', '[role="textbox"]',
'input:not([type="hidden"])', 'textarea', 'select', 'input[type="button"]',
'input[type="submit"]', 'summary', 'label', '[onclick]', '[data-action]',
+ '[aria-label]', '[tabindex]', '[data-tooltip]',
..._siteInteractiveSelectors(),
].join(', ');
// Candidate filter: listbox/menu option roles are often kept mounted but
@@ -1347,22 +1382,34 @@
};
const _normTxt = (el) => {
const siteText = _isSiteInteractive(el) ? _siteInteractionText(el) : '';
- return (siteText || el.innerText || (_valIsLabel(el) ? el.value : '') || el.placeholder || el.ariaLabel || '').trim().toLowerCase();
+ return (siteText || el.innerText || (_valIsLabel(el) ? el.value : '') || el.placeholder
+ || el.getAttribute?.('aria-label') || el.ariaLabel || el.title || '').trim().toLowerCase();
};
// LinkedIn can render the feed itself inside an open shadow root. Keep
// preflight and dispatch on the same candidate set, including duplicate
// labels across roots, without searching outside the selected modal.
const candidates = [];
const visit = (root) => {
+ _observeDomRevisionRoot(root);
candidates.push(...root.querySelectorAll(sels));
if (root.shadowRoot) visit(root.shadowRoot);
for (const host of root.querySelectorAll('*')) {
if (host.shadowRoot) visit(host.shadowRoot);
}
};
- visit(scope);
+ visit(cacheScope);
const all = candidates.filter(e => _hasVisibleBox(e) && _keepCandidate(e));
- return all.map(e => ({ e, txt: _normTxt(e) })).filter(x => !!x.txt);
+ const list = [];
+ for (const e of all) {
+ const text = _normTxt(e);
+ if (text) list.push({ e, txt: text });
+ for (const attr of ['aria-label', 'title', 'placeholder', 'data-tooltip']) {
+ const value = String(e.getAttribute?.(attr) || '').trim().toLowerCase();
+ if (value && value !== text) list.push({ e, txt: value });
+ }
+ }
+ _textCandidateCache.set(cacheScope, { revision, list });
+ return list.slice();
}
let _lastClickIdent = null;
@@ -1711,7 +1758,14 @@
function tryMode(mode) {
if (mode === 'exact') return normalized.filter(x => x.txt === needle);
if (mode === 'prefix') return normalized.filter(x => x.txt.startsWith(needle));
- if (mode === 'contains') return normalized.filter(x => x.txt.includes(needle));
+ if (mode === 'contains') {
+ if (needle.length >= 3) return normalized.filter(x => x.txt.includes(needle));
+ const padded = ` ${needle} `;
+ return normalized.filter(x => x.txt === needle
+ || x.txt.startsWith(`${needle} `)
+ || x.txt.endsWith(` ${needle}`)
+ || x.txt.includes(padded));
+ }
return [];
}
@@ -1844,12 +1898,49 @@
}
}
}
+ // Labels nested inside their actionable control are not independent
+ // targets. Collapse them before reporting an ambiguity so a single
+ // visible Send/Post control remains directly clickable.
+ if (!el && matches.length > 1) {
+ const collapsedByAncestor = new Map();
+ for (const match of matches) {
+ const actionable = _resolveInteractiveAncestor(match.e) || match.e;
+ if (!collapsedByAncestor.has(actionable)) collapsedByAncestor.set(actionable, match);
+ }
+ if (collapsedByAncestor.size < matches.length) matches = [...collapsedByAncestor.values()];
+ if (matches.length === 1) {
+ el = _resolveInteractiveAncestor(matches[0].e) || matches[0].e;
+ textResolvedExact = (usedMode === 'exact');
+ }
+ }
if (!el && matches.length > 1) {
// Prefer interactive elements over passive children (label, span, etc.)
const interactiveMatches = matches.filter(m => _isInteractive(m.e));
if (interactiveMatches.length === 1) {
matches = interactiveMatches;
} else {
+ const hitTargetPool = (interactiveMatches.length > 1 ? interactiveMatches : matches).filter(m => {
+ try {
+ const r = m.e.getBoundingClientRect();
+ if (r.width < 1 || r.height < 1) return false;
+ if (m.e.disabled === true || m.e.getAttribute?.('aria-disabled') === 'true') return false;
+ const hit = _shadowAwareElementFromPoint(
+ Math.round(r.left + r.width / 2),
+ Math.round(r.top + r.height / 2),
+ );
+ return !!hit && (hit === m.e || m.e.contains?.(hit) || hit.contains?.(m.e));
+ } catch {
+ return false;
+ }
+ });
+ if (hitTargetPool.length === 1) {
+ el = _resolveInteractiveAncestor(hitTargetPool[0].e) || hitTargetPool[0].e;
+ textResolvedExact = (usedMode === 'exact');
+ matches = hitTargetPool;
+ } else if (hitTargetPool.length > 1 && hitTargetPool.length < matches.length) {
+ matches = hitTargetPool;
+ }
+ if (matches.length > 1) {
// Build rich candidates: position (rect), tag, role, surrounding
// context (closest landmark/dialog/button text), and precomputed
// click centers. When the same text appears twice, the model needs
@@ -1899,6 +1990,7 @@
error: `Ambiguous text match for "${params.text}" (mode=${usedMode}, matches=${matches.length})${_scopeNote}. ${candidates.length} candidates returned with cx/cy (precomputed click center, in CSS pixels) and ancestor context. Pick one and call click({x: candidate.cx, y: candidate.cy, coordinate_space: "css"}) — no arithmetic needed. Use the ancestor field to disambiguate (e.g. an alertdialog's Cancel vs a form's Cancel sit in different containers). Do NOT retry click({text: "${params.text}"}) — it will fail the same way.`,
candidates,
};
+ }
}
}
if (!el) {
@@ -4146,6 +4238,38 @@
fieldMeta: _fieldMeta(el), rect: { x: rect.x, y: rect.y, w: rect.width, h: rect.height } };
}
+ const _COMPOSER_UTILITY_LABEL_RE = new RegExp(
+ '^(?:save\\s*(?:&|and)?\\s*(?:close|draft|draft\\s*&\\s*close)|save\\s*&\\s*close'
+ + '|minimi[sz]e|exit\\s+full\\s+screen|full\\s+screen|pop-?out|expand|collapse'
+ + '|discard(?:\\s+draft)?|delete\\s+draft|print|check\\s+spelling|plain\\s+text(?:\\s+mode)?'
+ + '|attach(?:\\s+(?:files?|photos?|images?|documents?))?|insert\\s+(?:link|photo|image|file|drive|emoji|signature|contact|table|drawing|note)'
+ + '|emoji|emoticon|bold|italic|underline|strikethrough|align|numbered\\s+list|bulleted\\s+list'
+ + '|indent|outdent|undo|redo|more\\s+options|formatting(?:\\s+options)?|text\\s+formatting'
+ + '|remove\\s+formatting|font|text\\s+color|highlight|edit\\s+subject|confidential\\s+mode)',
+ 'i',
+ );
+
+ function _isComposerUtilityControl(el) {
+ if (!el) return false;
+ try {
+ const label = String(
+ el.getAttribute?.('aria-label')
+ || el.getAttribute?.('title')
+ || el.getAttribute?.('data-tooltip')
+ || el.value
+ || el.innerText
+ || el.textContent
+ || '',
+ ).replace(/\s+/g, ' ').trim();
+ if (label && _COMPOSER_UTILITY_LABEL_RE.test(label)) return true;
+ const formattingScope = el.closest?.('[role="toolbar"],[aria-label*="formatting" i],[aria-label*="format" i]');
+ if (formattingScope && formattingScope !== el) return true;
+ return !!el.hasAttribute?.('aria-pressed');
+ } catch {
+ return false;
+ }
+ }
+
function _probeMessageRecipientGuard(params = {}) {
try {
const tool = String(params.tool || '');
@@ -4342,7 +4466,11 @@
} else if (tool === 'click') {
// Match dispatch precedence, modal scope, candidate text and match
// mode. A supplied selector must not approve a different text click.
- if (typeof args.text === 'string' && args.text) {
+ if (typeof args.ref_id === 'string' && args.ref_id
+ && typeof window.__wb_ax_lookup === 'function') {
+ target = window.__wb_ax_lookup(args.ref_id);
+ }
+ if (!target && typeof args.text === 'string' && args.text) {
const needle = args.text.toLowerCase();
const scope = _findTopmostModal() || document;
const candidates = _clickTextCandidates(scope);
@@ -4360,11 +4488,11 @@
if (matches.length === 1) target = _resolveInteractiveAncestor(matches[0].e);
if (matches.length) break;
}
- } else if (typeof args.selector === 'string' && args.selector) {
+ } else if (!target && typeof args.selector === 'string' && args.selector) {
target = safeIndexedQuerySelector(args.selector, args.matchIndex).element;
- } else if (Number.isInteger(args.index) && args.index >= 0) {
+ } else if (!target && Number.isInteger(args.index) && args.index >= 0) {
target = queryInteractiveForToolIndex()[args.index] || null;
- } else if (Number.isFinite(args.x) && Number.isFinite(args.y)) {
+ } else if (!target && Number.isFinite(args.x) && Number.isFinite(args.y)) {
target = _shadowAwareElementFromPoint(args.x, args.y);
}
targetResolved = !!target;
@@ -4651,9 +4779,19 @@
return { success: true, messageSend: null, conclusive: false, identityCandidates: [] };
}
if (active !== layoutComposer) {
- return verifiedNavigationEditable(active)
- ? { success: true, messageSend: false, conclusive: true, identityCandidates: [] }
- : { success: true, messageSend: null, conclusive: false, identityCandidates: [] };
+ if (verifiedNavigationEditable(active)) {
+ return { success: true, messageSend: false, conclusive: true, identityCandidates: [] };
+ }
+ try {
+ const composeScopeOf = (el) => el?.closest?.(
+ 'form, [role="dialog"], [role="form"], [aria-label*="compose" i], [class*="compose" i]',
+ );
+ const activeScope = composeScopeOf(active);
+ if (activeScope && activeScope === composeScopeOf(layoutComposer)) {
+ return { success: true, messageSend: false, conclusive: true, identityCandidates: [] };
+ }
+ } catch { /* fall through to the conservative result */ }
+ return { success: true, messageSend: null, conclusive: false, identityCandidates: [] };
}
composer = layoutComposer;
dispatchTarget = active;
@@ -4706,6 +4844,16 @@
identityCandidates: [],
};
}
+ if (_isComposerUtilityControl(control)) {
+ return {
+ success: true,
+ messageSend: false,
+ conclusive: true,
+ composerUtility: true,
+ reasonCode: 'non_messaging_target',
+ identityCandidates: [],
+ };
+ }
composer = layoutComposer;
if (!composer) {
const actionLabel = compact(
@@ -4719,11 +4867,30 @@
);
const composerSetup = params.adapterName === 'gmail'
&& /^(?:reply|reply all|forward)$/i.test(actionLabel);
+ const messageCommit = /(?:^|[^\p{L}])(?:send|enviar|envoyer|invia|senden|verzenden|gönder|отправить|送信|发送|發送|보내|إرسال|ارسال)(?:[^\p{L}]|$)/iu
+ .test(actionLabel);
+ const messagingSurface = (() => {
+ try {
+ return !!control.closest?.('[class*="msg-"],[class*="messaging"],[id*="messaging"],[data-messaging],[data-test-messaging],[role="log"]');
+ } catch { return false; }
+ })();
+ if (!composerSetup && !messageCommit && !messagingSurface) {
+ return {
+ success: true,
+ messageSend: false,
+ conclusive: true,
+ composerAvailable: false,
+ nonMessagingTarget: true,
+ reasonCode: 'non_messaging_target',
+ identityCandidates: [],
+ };
+ }
return {
success: true,
messageSend: null,
conclusive: false,
composerAvailable: false,
+ reasonCode: messageCommit ? 'message_commit_without_composer' : 'no_composer_surface',
...(composerSetup ? { composerSetup: true } : {}),
identityCandidates: [],
};
@@ -4916,6 +5083,47 @@
})();
gmailComposeRoot = composeRoot;
const recipients = collectGmailRecipients(composeRoot);
+ // A typed, uncommitted Gmail address only exists in the visible
+ // recipient input. Include it so confirmation remains bound to what
+ // is actually on screen before the UI turns it into a chip.
+ const collectRecipientInputValues = (root) => {
+ if (!root?.querySelectorAll) return;
+ let inputs = [];
+ try {
+ inputs = Array.from(root.querySelectorAll(
+ 'input, textarea, [contenteditable="true"], [contenteditable=""]',
+ )).slice(0, 40);
+ } catch {
+ return;
+ }
+ for (const input of inputs) {
+ if (!visible(input) || input === composer || composer?.contains?.(input)) continue;
+ const role = recipientRole(input, root);
+ if (!role) continue;
+ const raw = String('value' in input ? (input.value || '') : (input.innerText || input.textContent || ''));
+ if (!raw || raw.length > 2000) continue;
+ for (const piece of raw.split(/[,;\n]+/)) {
+ const candidate = compact(piece, 240);
+ const match = candidate.match(/[^\s<>@,;]+@[^\s<>@,;.]+\.[^\s<>@,;]+/);
+ if (!match) continue;
+ const email = match[0];
+ const key = normalizedIdentity(email);
+ if (!key) continue;
+ const recipientKey = `${role}:${key}`;
+ const prior = recipients.get(recipientKey) || { identity: email, role, aliases: new Map() };
+ prior.aliases.set(key, email);
+ const display = compact(candidate.replace(/<[^>]*>/g, ''), 240);
+ if (display && display !== email) {
+ const normalizedDisplay = normalizedIdentity(display);
+ if (normalizedDisplay && !prior.aliases.has(normalizedDisplay)) {
+ prior.aliases.set(normalizedDisplay, display);
+ }
+ }
+ recipients.set(recipientKey, prior);
+ }
+ }
+ };
+ collectRecipientInputValues(composeRoot);
for (const [recipientKey, recipient] of recipients) {
const emailKey = recipientKey.slice(recipientKey.indexOf(':') + 1);
const identity = recipient.aliases.get(emailKey) || [...recipient.aliases.values()][0] || recipient.identity || '';
@@ -5033,6 +5241,94 @@
}
}
+ // Generic mail surfaces expose recipient fields and chips without a
+ // provider-specific adapter. Read only explicit recipient semantics;
+ // an ordinary contact form's email field must not become a message
+ // recipient, and a generic chat still requires one header identity.
+ if (observedRecipientCandidates.length === 0) {
+ const genericMailRecipientMode = params.adapterName === 'generic-messaging'
+ && params.supportsRecipientSets === true;
+ const RECIPIENT_FIELD_RE = new RegExp(
+ '(?:^|[^\\p{L}])(?:to|to\\s+recipients?|recipients?|send\\s+to|email|e-?mail(?:\\s+address)?'
+ + '|destinatario|destinataria|destinataire|para|aan|kime|do|til|komu|\\u0644\\u0625\\u0649'
+ + '|\\u6536\\u4ef6\\u4eba|\\u5b9b\\u5148|\\ubc1b\\ub294\\s*\\uc0ac\\ub78c)(?:[^\\p{L}]|$)',
+ 'iu',
+ );
+ const fieldLooksLikeRecipient = (el) => {
+ try {
+ if (/^email$/i.test(String(el.getAttribute?.('type') || ''))) return genericMailRecipientMode;
+ if (/^email$/i.test(String(el.getAttribute?.('autocomplete') || ''))) return genericMailRecipientMode;
+ const haystack = [
+ el.getAttribute?.('name'),
+ el.getAttribute?.('aria-label'),
+ el.getAttribute?.('placeholder'),
+ el.getAttribute?.('id'),
+ el.getAttribute?.('data-testid'),
+ el.getAttribute?.('autocomplete'),
+ el.labels ? Array.from(el.labels).map(label => label.innerText).join(' ') : '',
+ ].filter(Boolean).join(' ');
+ return !!haystack && RECIPIENT_FIELD_RE.test(haystack);
+ } catch { return false; }
+ };
+ const pushRecipient = (identity, extraAliases = []) => {
+ const raw = compact(identity, 240);
+ const normalized = raw ? normalizedIdentity(raw) : '';
+ if (!normalized) return;
+ const existing = observedRecipientCandidates.find(
+ item => normalizedIdentity(item.identity) === normalized,
+ );
+ const aliases = Array.from(new Set([
+ raw, ...extraAliases, ...(existing?.aliases || []),
+ ].filter(Boolean)));
+ const entry = { identity: raw, role: 'to', aliases };
+ if (existing) Object.assign(existing, entry);
+ else observedRecipientCandidates.push(entry);
+ if (!strongRecipients.some(item => normalizedIdentity(item.identity) === normalized)) {
+ strongRecipients.push({ identity: raw, role: 'to' });
+ }
+ };
+ const extractAddresses = (rawValue) => {
+ const raw = String(rawValue || '');
+ if (!raw || raw.length > 2000) return;
+ for (const piece of raw.split(/[,;\n]+/)) {
+ const candidate = compact(piece, 240);
+ const match = candidate.match(/[^\s<>@,;]+@[^\s<>@,;.]+\.[^\s<>@,;]+/);
+ if (!match) continue;
+ const display = compact(candidate.replace(/<[^>]*>/g, ''), 240);
+ pushRecipient(match[0], display && display !== match[0] ? [display] : []);
+ }
+ };
+ try {
+ for (const el of Array.from(document.querySelectorAll(
+ 'input, textarea, [contenteditable="true"], [contenteditable=""]',
+ )).slice(0, 60)) {
+ if (!visible(el) || el === composer || composer?.contains?.(el)) continue;
+ if (!fieldLooksLikeRecipient(el)) continue;
+ extractAddresses('value' in el ? el.value : (el.innerText || el.textContent || ''));
+ }
+ } catch { /* structural read is best-effort */ }
+ try {
+ const chipScope = composer.closest?.('[role="dialog"],form,[role="main"]') || document;
+ for (const el of Array.from(chipScope.querySelectorAll(
+ '[email],[data-email],[data-hovercard-id],a[href^="mailto:" i],input[type="email"]',
+ )).slice(0, 40)) {
+ if (!visible(el) || el === composer || composer?.contains?.(el)) continue;
+ if (!genericMailRecipientMode
+ && /^email$/i.test(String(el.getAttribute?.('type') || ''))) continue;
+ const mailto = String(el.getAttribute?.('href') || '')
+ .replace(/^mailto:/i, '').split('?')[0];
+ const address = [
+ el.getAttribute?.('email'), el.getAttribute?.('data-email'),
+ el.getAttribute?.('data-hovercard-id'), mailto,
+ 'value' in el ? el.value : '',
+ ].map(value => compact(value, 240)).find(value => String(value || '').includes('@')) || '';
+ if (!address) continue;
+ const display = compact(el.innerText || el.textContent, 240);
+ pushRecipient(address, display && display !== address ? [display] : []);
+ }
+ } catch { /* structural read is best-effort */ }
+ }
+
const composerText = (() => {
try {
if ('value' in composer) return String(composer.value || '');
@@ -5142,6 +5438,7 @@
// --- Message handler ---
browser.runtime.onMessage.addListener((msg, sender, sendResponse) => {
if (msg.target !== 'content') return;
+ if (WEBBRAIN_GENERATION !== (Number(window.__webbrain_generation) || 0)) return;
const actionDeadlineAt = Number(msg.actionDeadlineAt) || 0;
const actionDeadlineExpired = () => actionDeadlineAt > 0 && Date.now() >= actionDeadlineAt;
if (actionDeadlineExpired()) {
@@ -6760,7 +7057,16 @@
return value;
};
- const result = handler();
+ let result;
+ try {
+ result = handler();
+ } catch (err) {
+ sendResponse(withLiveDocumentScope({
+ success: false,
+ error: `${msg.action} failed: ${err?.message || String(err)}`,
+ }));
+ return;
+ }
if (result instanceof Promise) {
// Always settle sendResponse — a rejecting handler (e.g. a throwing
// DOM API) must not leave the caller's await hanging forever.
@@ -6773,6 +7079,14 @@
);
return true; // async
}
+ if (result === undefined || result === null) {
+ sendResponse(withLiveDocumentScope({
+ success: false,
+ noResult: true,
+ error: `${msg.action} returned no result (handler produced no payload).`,
+ }));
+ return;
+ }
sendResponse(withLiveDocumentScope(result));
});
diff --git a/src/firefox/src/ui/sidepanel.js b/src/firefox/src/ui/sidepanel.js
index 9c062636a..12c8ec3e6 100644
--- a/src/firefox/src/ui/sidepanel.js
+++ b/src/firefox/src/ui/sidepanel.js
@@ -1402,6 +1402,12 @@ function playCompletionSound() {
} catch { /* ignore */ }
}
+// A clarification or permission card needs the same attention cue as a
+// completed run. It shares the user's existing notification-sound preference.
+function playClarifySound() {
+ playCompletionSound();
+}
+
function triggerCompletionConfetti() {
if (!completionConfettiEnabled) return;
if (globalThis.matchMedia?.('(prefers-reduced-motion: reduce)')?.matches) return;
@@ -9590,6 +9596,7 @@ function workflowHealingTargetLabel(target) {
function renderClarifyCard(data) {
hideActivity();
+ playClarifySound();
const tabId = data?.scheduledTabId ?? data?.tabId ?? currentTabId;
if (tabId == null) return;
const scheduledJobId = data?.scheduledJobId ? String(data.scheduledJobId) : '';
diff --git a/test/run.js b/test/run.js
index 6ac77d07c..4faa4ce7b 100644
--- a/test/run.js
+++ b/test/run.js
@@ -4972,7 +4972,22 @@ test('matches Douyin video and live surfaces with verification and publication g
assert.equal(getMessageRecipientGuardPolicy('https://www.douyin.com/chat/123')?.adapterName, 'douyin');
assert.equal(getMessageRecipientGuardPolicy('https://www.douyin.com/video/123'), null);
assert.equal(getMessageRecipientGuardPolicy('https://creator.douyin.com/creator-micro/content/upload'), null);
- assert.equal(getMessageRecipientGuardPolicy('https://example.com/chat'), null);
+ assert.deepEqual(getMessageRecipientGuardPolicy('https://example.com/chat'), {
+ adapterName: 'generic-messaging', verifyActiveRecipient: true,
+ });
+ assert.deepEqual(getMessageRecipientGuardPolicyFx('https://example.com/chat'), {
+ adapterName: 'generic-messaging', verifyActiveRecipient: true,
+ });
+ assert.deepEqual(getMessageRecipientGuardPolicy('https://mail.example.com/compose'), {
+ adapterName: 'generic-messaging', verifyActiveRecipient: true, supportsRecipientSets: true,
+ });
+ assert.deepEqual(getMessageRecipientGuardPolicyFx('https://mail.example.com/compose'), {
+ adapterName: 'generic-messaging', verifyActiveRecipient: true, supportsRecipientSets: true,
+ });
+ assert.equal(getMessageRecipientGuardPolicy('https://example.com/contact'), null);
+ assert.equal(getMessageRecipientGuardPolicyFx('https://example.com/contact'), null);
+ assert.equal(getMessageRecipientGuardPolicy('https://example.com/inbox'), null);
+ assert.equal(getMessageRecipientGuardPolicyFx('https://example.com/inbox'), null);
});
test('direct-message recipient guard uses structured intent and exact active identity evidence', async () => {
@@ -5478,12 +5493,36 @@ test('direct-message recipient guard uses structured intent and exact active ide
assert.deepEqual(getPolicy('https://www.linkedin.com/messaging/thread/2-abc/'), {
adapterName: 'linkedin', verifyActiveRecipient: true,
});
- assert.equal(getPolicy('https://linkedin.example.com/messaging/'), null);
+ assert.deepEqual(getPolicy('https://linkedin.example.com/messaging/'), {
+ adapterName: 'generic-messaging', verifyActiveRecipient: true,
+ });
+ assert.deepEqual(getPolicy('https://example.com/chat/rooms/42'), {
+ adapterName: 'generic-messaging', verifyActiveRecipient: true,
+ });
+ assert.deepEqual(getPolicy('https://mail.example.com/compose'), {
+ adapterName: 'generic-messaging', verifyActiveRecipient: true, supportsRecipientSets: true,
+ });
+ assert.equal(getPolicy('https://example.com/contact'), null);
+ assert.equal(getPolicy('https://example.com/inbox'), null);
}
for (const [label, AgentClass] of [['chrome', AgentCh], ['firefox', AgentFx]]) {
const agent = new AgentClass({ getVisionProvider: async () => null });
const tabId = label === 'chrome' ? 27101 : 27102;
+ agent.autoScreenshot = 'state_change';
+ assert.equal(agent.autoScreenshotBursts.size, 0, `${label}: screenshot predicate inherited stale burst state`);
+ assert.deepEqual(
+ [1, 2, 3, 4, 5].map(() => agent._advanceAutoScreenshotBurst(tabId, 'click')),
+ [true, false, false, false, true],
+ `${label}: repeated action screenshots were not throttled at the batch boundary`,
+ );
+ assert.equal(agent._advanceAutoScreenshotBurst(tabId + 1, 'click'), true,
+ `${label}: screenshot throttle leaked across tabs`);
+ assert.equal(agent._shouldAutoScreenshot('click'), true,
+ `${label}: screenshot eligibility unexpectedly changed`);
+ assert.equal(agent.autoScreenshotBursts.get(tabId)?.streak, 5,
+ `${label}: screenshot predicate consumed a burst position`);
+ agent.autoScreenshotBursts.clear();
agent._currentUrl = async () => 'https://www.douyin.com/chat';
let probe = {
success: true,
@@ -5527,6 +5566,13 @@ test('direct-message recipient guard uses structured intent and exact active ide
'https://www.douyin.com/chat',
);
assert.equal(ambiguousPin.ok, false, `${label}: ambiguous active conversation was authorized`);
+ const genericGroupPin = await agent._pinActiveConversationMessagingTarget(
+ tabId,
+ { target_kind: 'active_conversation', recipients: [] },
+ 'https://example.com/chat/rooms/42',
+ );
+ assert.equal(genericGroupPin.ok, false,
+ `${label}: generic group chat was accepted as a single authorized recipient`);
probe = {
success: false,
@@ -7049,7 +7095,7 @@ test('direct-message recipient probe accepts only a unique active-thread header
const distantControl = element('Forward', {
left: 20, right: 140, top: 300, bottom: 350, width: 120, height: 50,
}, { tagName: 'BUTTON', role: 'button' });
- distantControl.closest = () => distantControl;
+ distantControl.closest = (selector) => selector.includes('button') ? distantControl : null;
const conversationRail = element('', {
left: 0, right: 340, top: 80, bottom: 900, width: 340, height: 820,
}, { role: 'list', clientHeight: 820, scrollHeight: 820 });
@@ -7128,7 +7174,10 @@ test('direct-message recipient probe accepts only a unique active-thread header
const composedParentEnd = source.indexOf('\n\n function ', composedParentStart + 1);
assert.ok(composedParentStart >= 0 && composedParentEnd > composedParentStart,
`${prefix}: composed-parent helper must be available to visibility checks`);
- const candidatesStart = source.indexOf(' function _clickTextCandidates(');
+ const clickCandidatesStart = source.indexOf(' function _clickTextCandidates(');
+ const candidatesStart = source.lastIndexOf(' const _domRevision', clickCandidatesStart) >= 0
+ ? source.lastIndexOf(' const _domRevision', clickCandidatesStart)
+ : clickCandidatesStart;
const candidatesEnd = source.indexOf('\n\n let _lastClickIdent', candidatesStart);
Object.assign(context, {
_siteInteractiveSelectors: () => [],
@@ -7141,8 +7190,15 @@ test('direct-message recipient probe accepts only a unique active-thread header
});
const visibilityStart = source.indexOf(' function _hasVisibleBox(');
const visibilityEnd = source.indexOf('\n\n function ', visibilityStart + 1);
+ const recipientHelpersStart = [
+ source.indexOf(' const _MESSAGE_COMMIT_LABEL_RE'),
+ source.indexOf(' const _COMPOSER_UTILITY_LABEL_RE'),
+ ].filter(index => index >= 0).sort((a, b) => a - b)[0] ?? -1;
+ const recipientHelpers = recipientHelpersStart >= 0
+ ? source.slice(recipientHelpersStart, start)
+ : '';
const probe = vm.runInNewContext(
- `${source.slice(composedParentStart, composedParentEnd)}; ${source.slice(visibilityStart, visibilityEnd)}; ${source.slice(candidatesStart, candidatesEnd)}; (${source.slice(start, end)})`, context,
+ `${source.slice(composedParentStart, composedParentEnd)}; ${source.slice(visibilityStart, visibilityEnd)}; ${source.slice(candidatesStart, candidatesEnd)}; ${recipientHelpers}; (${source.slice(start, end)})`, context,
);
const observationResult = probe({ tool: 'observe_active_conversation', args: {} });
const enterResult = probe({ tool: 'press_keys', args: { key: 'Enter' } });
@@ -41868,7 +41924,7 @@ test('web hero social proof uses recognizable brand and users icons', () => {
);
assert.match(
fs.readFileSync(path.join(ROOT, 'web/assets/marktechpost.svg'), 'utf8'),
- /<svg[^>]+width="32" height="32" viewBox="0 0 32 32"/,
+ /<svg(?=[^>]*\bwidth="32")(?=[^>]*\bheight="32")(?=[^>]*\bviewBox="0 0 32 32")/,
'web assets: MarkTechPost favicon should preserve its square aspect ratio',
);
});
@@ -86730,7 +86786,9 @@ test('browser batches keep leading reads, then require fresh evidence after unsa
const messages = [];
agent._ensureGateSetting = async () => {};
agent._skipPermissionGate = true;
- agent._currentUrl = async () => 'https://mail.example.test/inbox';
+ // This batching check is deliberately not a messaging surface: generic
+ // recipient guards correctly stop send-like controls on mail routes.
+ agent._currentUrl = async () => 'https://www.example.test/docs';
agent._rememberMastodonObservation = async () => null;
agent._recordProgressObservation = async () => null;
agent._autoRecordProgressAction = () => null;