Open-source AI browser agent for Chrome and Firefox (monorepo) ðŸ§
JavaScript ai-agentai-agentsai-toolsbrowser-aibrowser-automationbrowser-extensionchrome-aichrome-devtoolschrome-extensionchrome-extensionsfirefox-addonfirefox-addonsfirefox-extensionfirefox-extensionsgemmagemma4minimaxoffline-aioffline-llmqwen
Stop an action clicked just before More from reaching the model
Claudef5209773e145
diff --git a/docs/architecture.md b/docs/architecture.mdindex 285672cc7..44a725a38 100644--- a/docs/architecture.md+++ b/docs/architecture.md@@ -540,7 +540,7 @@ same cancel from `pagehide`, since it can no longer close the card itself; for tprovider also sends `webgpu-chat-cancel`, and the offscreen worker interrupts the runninggeneration or drops a queued one, and the offscreen host remembers a cancel that arrives while the request is still being routed to a worker, so the generation never starts; those workers report `outputTruncated` when an answer usedits token budget, since they have no finish reason); the card also claims its request id-before it waits for the language bundle, so a double click starts only one call. Selections+before it waits for the language bundle, so a double click starts only one call, and **More…** takes a newer id on the same wait, so an action clicked just before it never reaches the model. Selectionsover 4,000 characters skip the card and use the side-panel flow. The card draws the answer as DOMnodes (paragraphs, lists, bold, italic and code), never as HTML, and takes the sourcelanguage from the browser's own detector, with no network call. A follow-up typed in a carddiff --git a/src/chrome/src/content/selection-shortcut.js b/src/chrome/src/content/selection-shortcut.jsindex 3fbe4e8ed..a1acf5870 100644--- a/src/chrome/src/content/selection-shortcut.js+++ b/src/chrome/src/content/selection-shortcut.js@@ -769,7 +769,13 @@async function openPopup() {if (!snapshot || submitting) return;- if (!localization) await refreshLocalization(interfaceLanguage);+ if (!localization) {+ // A card asked for while the language bundle loads is replaced by this popup, so+ // take a newer request id now: its continuation then stops, instead of starting a+ // paid model call that closeCard would only cancel a moment later.+ cardRequestId += 1;+ await refreshLocalization(interfaceLanguage);+ }if (!snapshot || submitting) return;ensureSurface();applyLocalization();diff --git a/src/firefox/src/content/selection-shortcut.js b/src/firefox/src/content/selection-shortcut.jsindex 3fbe4e8ed..a1acf5870 100644--- a/src/firefox/src/content/selection-shortcut.js+++ b/src/firefox/src/content/selection-shortcut.js@@ -769,7 +769,13 @@async function openPopup() {if (!snapshot || submitting) return;- if (!localization) await refreshLocalization(interfaceLanguage);+ if (!localization) {+ // A card asked for while the language bundle loads is replaced by this popup, so+ // take a newer request id now: its continuation then stops, instead of starting a+ // paid model call that closeCard would only cancel a moment later.+ cardRequestId += 1;+ await refreshLocalization(interfaceLanguage);+ }if (!snapshot || submitting) return;ensureSurface();applyLocalization();diff --git a/test/fixtures/run.mjs b/test/fixtures/run.mjsindex 3888d0b5d..be5132c08 100644--- a/test/fixtures/run.mjs+++ b/test/fixtures/run.mjs@@ -2359,6 +2359,26 @@ for (const [label, sourcePath, manualOpen] of [}});+ test(`${label}: More clicked while an action's language bundle loads replaces that action without a model call`, async (page) => {+ await setupSelectionShortcut(page, sourcePath, { requiresManualOpen: manualOpen, holdLocalization: true });+ const selected = await selectFixtureText(page);+ await clickRectCenter(page, selected.inlineRects.explain);+ await clickRectCenter(page, selected.moreRect);+ // The start-up request plus one per click are now waiting on the held bundle.+ await page.waitForFunction(() => window.__selectionLocalizationRequests >= 3);+ await page.evaluate(() => window.__releaseLocalization());+ await page.waitForFunction(() => window.__webbrainSelectionShortcut.getState().popupVisible);+ await page.waitForTimeout(60);+ const result = await page.evaluate(() => ({+ inline: window.__selectionInlineMessages.length,+ cancels: window.__selectionCancelMessages.length,+ state: window.__webbrainSelectionShortcut.getState(),+ }));+ if (result.inline !== 0 || result.cancels !== 0 || result.state.cardVisible || !result.state.popupVisible) {+ throw new Error(`the abandoned action still reached the model or showed a card: ${JSON.stringify(result)}`);+ }+ });+test(`${label}: closing, retargeting or retrying a card cancels the call it abandons`, async (page) => {await setupSelectionShortcut(page, sourcePath, { requiresManualOpen: manualOpen });await page.evaluate(() => {diff --git a/test/run.js b/test/run.jsindex 76709928b..6be9d538e 100644--- a/test/run.js+++ b/test/run.js@@ -54500,7 +54500,7 @@ test('selection shortcut is shipped, enabled by default, and keeps browser-speciassert.match(content, /function containSurfaceKeyboardEvent\(event\)[\s\S]*?event\.stopImmediatePropagation\(\);/, `${label}: selection dialog keyboard events should stop page capture listeners`);assert.match(content, /window\.addEventListener\('keydown', containSurfaceKeyboardEvent, true\);\s*window\.addEventListener\('keypress', containSurfaceKeyboardEvent, true\);\s*window\.addEventListener\('keyup', containSurfaceKeyboardEvent, true\);/, `${label}: keyboard containment should run during window capture`);assert.match(content, /function dismissSurface\(\) \{\s*clearSelectionHighlight\(\);/, `${label}: dismissing the selection surface should clear the sticky highlight`);- assert.match(content, /async function openPopup\(\) \{\s*if \(!snapshot \|\| submitting\) return;\s*if \(!localization\) await refreshLocalization\(interfaceLanguage\);/, `${label}: opening the popup should wait for localized labels when they have not loaded yet`);+ assert.match(content, /async function openPopup\(\) \{\s*if \(!snapshot \|\| submitting\) return;\s*if \(!localization\) \{[\s\S]*?cardRequestId \+= 1;\s*await refreshLocalization\(interfaceLanguage\);\s*\}/, `${label}: opening the popup should wait for localized labels when they have not loaded yet, superseding a card requested meanwhile`);assert.match(content, /message\?\.type === 'WB_HIDE_FOR_TOOL_USE'[\s\S]*?suppressed = true;[\s\S]*?message\?\.type === 'WB_SHOW_AFTER_TOOL_USE'[\s\S]*?suppressed = false;/, `${label}: screenshot capture should suppress and restore future shortcut detection`);assert.match(content, /submitting = true;\s*dismissSurface\(\);\s*try \{\s*const response = await api\.runtime\.sendMessage\(request\);/, `${label}: submission should dismiss before sending to prevent duplicates`);