Skip to content

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

Keep the side panel open on a follow-up, and drop the bar's actions from More…

Claudeb54430ce6508
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 53639e5e2..2057de8a1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,9 +7,10 @@ This changelog was generated from the repository Git history and release tags. V
## [Unreleased]
### Changed
-- Selecting text on a page now shows a small bar, **Translate | Explain | Proofread | More…**, instead of the single `?` button. Translate, Explain and Proofread answer in a card next to the selection: Translate shows the detected source language, the original text and a target-language picker, and every card has an "Ask a follow-up" box that continues in the side panel with the card's answer as context. **More…** opens the same popup the `?` button opened (Summarize, Explain, Quiz me, Proofread, Humanize, Translate, a question box and Hide this). A card sends the selected text to your configured model provider, like any other selection action; selections over 4,000 characters go to the side panel instead of a card. A card answer that reaches the model's output limit says it was cut off and offers to continue in the side panel, and closing or redoing a card cancels the request it no longer needs. Chrome and Firefox.
+- Selecting text on a page now shows a small bar, **Translate | Explain | Proofread | More…**, instead of the single `?` button. Translate, Explain and Proofread answer in a card next to the selection: Translate shows the detected source language, the original text and a target-language picker, and every card has an "Ask a follow-up" box that continues in the side panel with the card's answer as context. **More…** opens the same popup the `?` button opened (Summarize, Quiz me, Humanize, a question box and Hide this; Translate, Explain and Proofread are on the bar, so they are not repeated there). A card sends the selected text to your configured model provider, like any other selection action; selections over 4,000 characters go to the side panel instead of a card. A card answer that reaches the model's output limit says it was cut off and offers to continue in the side panel, and closing or redoing a card cancels the request it no longer needs. Chrome and Firefox.
### Fixed
+- Chrome: sending a follow-up or a selection action to WebBrain while the side panel is already open no longer closes it. Each side panel now tells the background whether it is on screen, and the background skips re-opening a panel that is already showing and hands it the prompt directly.
- Stopping a task while WebBrain was waiting for page navigation to settle now stops it immediately. The pending settle step previously kept waiting and could let the run continue after you chose Stop.
- Mastodon: replying to toots in a narrow window no longer posts the same reply several times and stops before the next toot. There, a toot's Reply button opens the composer at /publish, and after posting Mastodon goes back to the previous column by itself. WebBrain took both page changes for something you did, so it reported each click's outcome as unknown; the agent then concluded its reply had not been posted, wrote it again, and never reached the next toot. In Chrome, a page's own Back is now told apart from your browser's Back button: the page a click opens counts as that click's verified effect, and a click after which the page goes back by itself counts as delivered, to be checked on the page. The Mastodon notes now cover replies (start with the prefilled @mentions once, check the reply under the toot before any retry) and stay active on Favourites, Bookmarks and the other columns. Firefox still treats a page's own Back as yours until its Back button reporting is verified.
- Finishing a form you asked WebBrain not to submit no longer takes most of a minute. The completion check removed every line that mentioned a password, so "fill out this form with a random password … don't submit" reached its judge as "[credential omitted]", and so did the approved plan and the agent's summary. Seeing only an unsubmitted signup form, the judge answered "pending" again and again; in the trace it took four attempts and about 50 seconds, ending only when a slow screenshot check ran out of time. The active model's check, which already holds these texts in the conversation, now receives every line of them, with only addresses shortened and bearer tokens and entered passwords hidden, as in all judge evidence. A decision model on this device, or WebBrain Cloud's own while WebBrain Cloud is also your provider, receives that same copy; any other decision model keeps whole-line redaction, and when that leaves it without the task, it is no longer asked while the active model can judge. A password WebBrain typed into a password field during the run is now hidden in the text judges receive, such as the agent's summary or a field a "show password" control revealed, unless the typing tool could not tell what kind of field it was; other entered values stay visible, so a judge can still catch a mistyped one. The judges are told that a task asking not to submit is complete once the staged values match, that a hidden value neither proves nor disproves an entry, and, for each recorded entry, whether its field read back what was entered, whether it is a credential field and which field it targeted; a credential field's line in the page evidence keeps its role and reference. Staged field edits are judged from the accessibility tree first: a screenshot shows passwords only as dots, and the focused field's blinking caret made each one stale before its verdict returned.
diff --git a/docs/architecture.md b/docs/architecture.md
index 85cfec3a6..bd92d6917 100644
--- a/docs/architecture.md
+++ b/docs/architecture.md
@@ -512,7 +512,8 @@ trace and diagnostic exports as privacy-sensitive data.
Selecting text on a page shows a bar (Translate, Explain, Proofread, More…) drawn by a
content script in a closed Shadow DOM, in the top frame and in the PDF viewer page.
-**More…** opens the full popup; its actions and question box queue a side-panel prompt as
+**More…** opens the full popup; its actions (Summarize, Quiz me, Humanize, with the three
+the bar already offers left out) and question box queue a side-panel prompt as
described above. Translate, Explain and Proofread answer in place instead: the script sends
one `WB_SELECTION_SHORTCUT_INLINE` message and the background builds the same allowlisted
selection prompt (the selection inside its untrusted boundary, `selection_only` grounding)
@@ -535,8 +536,13 @@ before it waits for the language bundle, so a double click starts only one call.
over 4,000 characters skip the card and use the side-panel flow. The card draws the answer as DOM
nodes (paragraphs, lists, bold, italic and code), never as HTML, and takes the source
language from the browser's own detector, with no network call. A follow-up typed in a card
-continues in the side panel as a custom question. The card's answer travels inside the
-selection's untrusted boundary, labelled as an earlier answer that may contain mistakes and
+continues in the side panel as a custom question. In Chrome the background opens the panel
+only when none is showing in that window: re-running `sidePanel.setOptions()` + `open()` on an
+open panel closes it, so each panel reports its visibility over a long-lived port
+(`sidepanel-presence.js`) and the background reads that synchronously, before the user
+gesture can lapse, then hands an already-open panel the prompt by message. The card's
+answer travels inside the selection's untrusted boundary, labelled as an earlier answer that
+may contain mistakes and
capped at 6,000 characters, so model output derived from page text never becomes trusted
instruction. The selection and the answer go to the configured provider like any other
model call.
diff --git a/src/chrome/src/background.js b/src/chrome/src/background.js
index dc2bafa22..461644c43 100644
--- a/src/chrome/src/background.js
+++ b/src/chrome/src/background.js
@@ -11,6 +11,10 @@ import { probeDecisionVision } from './agent/decision-vision-probe.js';
import { installSafeSocialBackground } from './safesocial/background.js';
import { createFeedbackHandoff } from './feedback-handoff.js';
const feedbackHandoff = createFeedbackHandoff(chrome);
+import { createSidePanelPresence } from './sidepanel-presence.js';
+// Which side panels are on screen; see openSidePanelForContextMenu().
+const sidePanelPresence = createSidePanelPresence(chrome);
+chrome.runtime.onConnect.addListener((port) => { sidePanelPresence.attach(port); });
import { ProviderManager } from './providers/manager.js';
import {
WEBGPU_COMPASS_TINY_V2_MODEL_ID,
@@ -1668,12 +1672,18 @@ function openSidePanelForContextMenu(tab) {
if (!tab?.id) return;
panelTabs.add(tab.id);
savePanelTabs();
- chrome.sidePanel.setOptions({
- tabId: tab.id,
- path: 'src/ui/sidepanel.html',
- enabled: true,
- });
- chrome.sidePanel.open({ tabId: tab.id });
+ // A panel that is already showing in this window needs nothing here: callers hand it
+ // the prompt by message. Running setOptions + open again on an open panel makes
+ // Chrome tear it down, which is how a follow-up used to close the sidebar. This check
+ // must stay synchronous: open() loses the user's gesture across an await.
+ if (!sidePanelPresence.isVisibleInWindow(tab.windowId)) {
+ chrome.sidePanel.setOptions({
+ tabId: tab.id,
+ path: 'src/ui/sidepanel.html',
+ enabled: true,
+ });
+ chrome.sidePanel.open({ tabId: tab.id });
+ }
ensureWebBrainGroup(tab).catch(() => {});
}
diff --git a/src/chrome/src/content/selection-shortcut.js b/src/chrome/src/content/selection-shortcut.js
index 5fc33ccd1..23daa1290 100644
--- a/src/chrome/src/content/selection-shortcut.js
+++ b/src/chrome/src/content/selection-shortcut.js
@@ -207,7 +207,7 @@
host.dir = localization.dir;
shortcut.setAttribute('aria-label', strings.askHighlightedText);
popup.setAttribute('aria-label', strings.askHighlightedText);
- for (const action of ['summarize', 'explain', 'quiz', 'proofread', 'humanize', 'translate']) {
+ for (const action of ['summarize', 'quiz', 'humanize']) {
const label = shadow.querySelector(`[data-action="${action}"] .action-label`);
if (label) label.textContent = strings[action];
}
@@ -327,7 +327,7 @@
color:var(--text); box-shadow:var(--shadow); pointer-events:auto;
font:15px/1.35 -apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;
}
- .actions { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:2px; }
+ .actions { display:grid; grid-template-columns:minmax(0,1fr); gap:2px; }
.action,.hide {
border:0; border-radius:10px; background:transparent;
color:var(--text); text-align:start; cursor:pointer;
@@ -495,12 +495,6 @@
</svg>
<span class="action-label">Summarize</span>
</button>
- <button class="action" type="button" data-action="explain">
- <svg class="action-icon" viewBox="0 0 20 20" fill="none" aria-hidden="true" focusable="false">
- <path d="M6.5 11.5a5 5 0 1 1 7 0c-.9.8-1.3 1.6-1.4 2.5H7.9c-.1-.9-.5-1.7-1.4-2.5ZM8.2 17h3.6M8 14h4"/>
- </svg>
- <span class="action-label">Explain</span>
- </button>
<button class="action" type="button" data-action="quiz">
<svg class="action-icon" viewBox="0 0 20 20" fill="none" aria-hidden="true" focusable="false">
<circle cx="10" cy="10" r="7"/>
@@ -508,12 +502,6 @@
</svg>
<span class="action-label">Quiz me</span>
</button>
- <button class="action" type="button" data-action="proofread">
- <svg class="action-icon" viewBox="0 0 20 20" fill="none" aria-hidden="true" focusable="false">
- <path d="M5 3.5h7l3 3v10H5zM12 3.5v3h3M7.3 11.8l1.6 1.6 3.5-3.7"/>
- </svg>
- <span class="action-label">Proofread</span>
- </button>
<button class="action" type="button" data-action="humanize">
<svg class="action-icon" viewBox="0 0 20 20" fill="none" aria-hidden="true" focusable="false">
<circle cx="10" cy="7" r="2.5"/>
@@ -521,12 +509,6 @@
</svg>
<span class="action-label">Humanize</span>
</button>
- <button class="action" type="button" data-action="translate">
- <svg class="action-icon" viewBox="0 0 20 20" fill="none" aria-hidden="true" focusable="false">
- <path d="M3.5 5h9M8 3v2M5.2 8.5c1.2 2 3 3.6 5.4 4.7M11.2 7.5c-1 2.6-3.2 4.8-6.5 6.5M12.5 16.5l2.8-7 2.8 7M13.5 14h3.6"/>
- </svg>
- <span class="action-label">Translate</span>
- </button>
</div>
<div class="question-wrap">
<textarea maxlength="2000" rows="3" aria-label="Ask WebBrain a question" placeholder="Ask WebBrain…"></textarea>
@@ -1274,7 +1256,9 @@
? Object.fromEntries(INLINE_ACTIONS.map((kind) => [kind, rectOf(`[data-inline="${kind}"]`)]))
: null,
summarizeRect: popup && !popup.hidden ? rectOf('[data-action="summarize"]') : null,
- translateRect: popup && !popup.hidden ? rectOf('[data-action="translate"]') : null,
+ popupActions: popup
+ ? Array.from(popup.querySelectorAll('[data-action]'), (button) => button.dataset.action)
+ : [],
hideRect: popup && !popup.hidden ? rectOf('.hide') : null,
questionRect: popup && !popup.hidden ? question?.getBoundingClientRect().toJSON() || null : null,
questionValue: question?.value || '',
@@ -1284,7 +1268,6 @@
actionIconCount: shadow?.querySelectorAll('.action > .action-icon').length || 0,
direction: host?.dir || 'ltr',
summarizeLabel: shadow?.querySelector('[data-action="summarize"] .action-label')?.textContent || '',
- explainLabel: shadow?.querySelector('[data-action="explain"] .action-label')?.textContent || '',
quizLabel: shadow?.querySelector('[data-action="quiz"] .action-label')?.textContent || '',
cardVisible: !!card && !card.hidden,
cardKind: cardState?.kind || '',
diff --git a/src/chrome/src/sidepanel-presence.js b/src/chrome/src/sidepanel-presence.js
new file mode 100644
index 000000000..b2d5a5e1f
--- /dev/null
+++ b/src/chrome/src/sidepanel-presence.js
@@ -0,0 +1,110 @@
+/**
+ * Which WebBrain side panels are on screen, per browser window.
+ *
+ * Running `sidePanel.setOptions()` + `sidePanel.open()` on a panel that is already
+ * open makes Chrome tear it down again, so a request that arrives while the panel is
+ * showing (a follow-up typed in a page card, a right-click action) must not repeat
+ * them. The background cannot ask the panel first: `sidePanel.open()` has to run
+ * before the first await of the handler that received the user's gesture. So each
+ * panel keeps a port to the background and says whether it is visible, and the
+ * background reads that answer synchronously.
+ */
+
+export const SIDEPANEL_PRESENCE_PORT = 'wb-sidepanel-presence';
+
+const RECONNECT_BASE_MS = 500;
+const RECONNECT_MAX_MS = 30_000;
+// A port that closes this soon after it opened was refused, not outlived.
+const QUICK_CLOSE_MS = 1_000;
+
+/** Background side: accepts presence ports from the side panel page only. */
+export function createSidePanelPresence(api) {
+ const panelUrl = api.runtime.getURL('src/ui/sidepanel.html');
+ const visibleWindowByPort = new Map();
+
+ function fromSidePanel(port) {
+ return port?.name === SIDEPANEL_PRESENCE_PORT
+ && port.sender?.id === api.runtime.id
+ && String(port.sender?.url || '').split(/[?#]/)[0] === panelUrl;
+ }
+
+ function attach(port) {
+ if (!fromSidePanel(port)) return false;
+ port.onMessage.addListener((message) => {
+ if (message?.visible === true && Number.isInteger(message.windowId)) {
+ visibleWindowByPort.set(port, message.windowId);
+ } else {
+ visibleWindowByPort.delete(port);
+ }
+ });
+ port.onDisconnect.addListener(() => {
+ visibleWindowByPort.delete(port);
+ });
+ return true;
+ }
+
+ function isVisibleInWindow(windowId) {
+ if (!Number.isInteger(windowId)) return false;
+ for (const visibleWindowId of visibleWindowByPort.values()) {
+ if (visibleWindowId === windowId) return true;
+ }
+ return false;
+ }
+
+ return { attach, isVisibleInWindow };
+}
+
+/**
+ * Side panel side: keeps a port open and reports whether this page is visible.
+ * The port is reopened when the background worker restarts, which drops it.
+ */
+export function reportSidePanelPresence({
+ runtime,
+ doc,
+ windowId,
+ schedule = (callback, delay) => setTimeout(callback, delay),
+ now = () => Date.now(),
+}) {
+ if (!Number.isInteger(windowId)) return { stop() {} };
+ let port = null;
+ let stopped = false;
+ let quickCloses = 0;
+
+ const report = () => {
+ try {
+ port?.postMessage({ visible: doc.visibilityState === 'visible', windowId });
+ } catch { /* the port closed under us; its disconnect handler reconnects */ }
+ };
+
+ const connect = () => {
+ if (stopped) return;
+ let next;
+ try {
+ next = runtime.connect({ name: SIDEPANEL_PRESENCE_PORT });
+ } catch {
+ stopped = true; // the extension was reloaded or removed; this page is stale
+ return;
+ }
+ const openedAt = now();
+ port = next;
+ next.onDisconnect.addListener(() => {
+ void runtime.lastError;
+ if (port === next) port = null;
+ quickCloses = now() - openedAt < QUICK_CLOSE_MS ? quickCloses + 1 : 0;
+ const delay = Math.min(RECONNECT_MAX_MS, RECONNECT_BASE_MS * 2 ** quickCloses);
+ schedule(connect, delay);
+ });
+ report();
+ };
+
+ doc.addEventListener('visibilitychange', report);
+ connect();
+ return {
+ stop() {
+ stopped = true;
+ doc.removeEventListener('visibilitychange', report);
+ try { port?.disconnect(); } catch { /* already closed */ }
+ port = null;
+ },
+ };
+}
diff --git a/src/chrome/src/ui/sidepanel.js b/src/chrome/src/ui/sidepanel.js
index db9108bd0..3f951b271 100644
--- a/src/chrome/src/ui/sidepanel.js
+++ b/src/chrome/src/ui/sidepanel.js
@@ -9,6 +9,7 @@ import { appendGeneratedMedia, restoreGeneratedMedia } from './generated-media-v
*/
import { createQuotaController } from './compass-quota.js';
+import { reportSidePanelPresence } from '../sidepanel-presence.js';
import { t, getLocale, setLocale, LANGUAGES, applyDOMTranslations, translationsForKey } from './i18n.js';
import { CAPABILITY_LABEL } from '../agent/permission-gate.js';
import { sanitizeMarkdownLinks } from './markdown-link.js';
@@ -5063,6 +5064,15 @@ async function init() {
switchToTab,
});
+ // Lets the background reuse this panel instead of re-opening it (which closes it).
+ if (!isBtwWindow) {
+ reportSidePanelPresence({
+ runtime: chrome.runtime,
+ doc: document,
+ windowId: initialWindowId ?? tab?.windowId ?? null,
+ });
+ }
+
if (windowScope) {
chrome.tabs.onActivated.addListener(async (info) => {
await windowScope.handleActivated(info);
diff --git a/src/firefox/src/content/selection-shortcut.js b/src/firefox/src/content/selection-shortcut.js
index 5fc33ccd1..23daa1290 100644
--- a/src/firefox/src/content/selection-shortcut.js
+++ b/src/firefox/src/content/selection-shortcut.js
@@ -207,7 +207,7 @@
host.dir = localization.dir;
shortcut.setAttribute('aria-label', strings.askHighlightedText);
popup.setAttribute('aria-label', strings.askHighlightedText);
- for (const action of ['summarize', 'explain', 'quiz', 'proofread', 'humanize', 'translate']) {
+ for (const action of ['summarize', 'quiz', 'humanize']) {
const label = shadow.querySelector(`[data-action="${action}"] .action-label`);
if (label) label.textContent = strings[action];
}
@@ -327,7 +327,7 @@
color:var(--text); box-shadow:var(--shadow); pointer-events:auto;
font:15px/1.35 -apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;
}
- .actions { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:2px; }
+ .actions { display:grid; grid-template-columns:minmax(0,1fr); gap:2px; }
.action,.hide {
border:0; border-radius:10px; background:transparent;
color:var(--text); text-align:start; cursor:pointer;
@@ -495,12 +495,6 @@
</svg>
<span class="action-label">Summarize</span>
</button>
- <button class="action" type="button" data-action="explain">
- <svg class="action-icon" viewBox="0 0 20 20" fill="none" aria-hidden="true" focusable="false">
- <path d="M6.5 11.5a5 5 0 1 1 7 0c-.9.8-1.3 1.6-1.4 2.5H7.9c-.1-.9-.5-1.7-1.4-2.5ZM8.2 17h3.6M8 14h4"/>
- </svg>
- <span class="action-label">Explain</span>
- </button>
<button class="action" type="button" data-action="quiz">
<svg class="action-icon" viewBox="0 0 20 20" fill="none" aria-hidden="true" focusable="false">
<circle cx="10" cy="10" r="7"/>
@@ -508,12 +502,6 @@
</svg>
<span class="action-label">Quiz me</span>
</button>
- <button class="action" type="button" data-action="proofread">
- <svg class="action-icon" viewBox="0 0 20 20" fill="none" aria-hidden="true" focusable="false">
- <path d="M5 3.5h7l3 3v10H5zM12 3.5v3h3M7.3 11.8l1.6 1.6 3.5-3.7"/>
- </svg>
- <span class="action-label">Proofread</span>
- </button>
<button class="action" type="button" data-action="humanize">
<svg class="action-icon" viewBox="0 0 20 20" fill="none" aria-hidden="true" focusable="false">
<circle cx="10" cy="7" r="2.5"/>
@@ -521,12 +509,6 @@
</svg>
<span class="action-label">Humanize</span>
</button>
- <button class="action" type="button" data-action="translate">
- <svg class="action-icon" viewBox="0 0 20 20" fill="none" aria-hidden="true" focusable="false">
- <path d="M3.5 5h9M8 3v2M5.2 8.5c1.2 2 3 3.6 5.4 4.7M11.2 7.5c-1 2.6-3.2 4.8-6.5 6.5M12.5 16.5l2.8-7 2.8 7M13.5 14h3.6"/>
- </svg>
- <span class="action-label">Translate</span>
- </button>
</div>
<div class="question-wrap">
<textarea maxlength="2000" rows="3" aria-label="Ask WebBrain a question" placeholder="Ask WebBrain…"></textarea>
@@ -1274,7 +1256,9 @@
? Object.fromEntries(INLINE_ACTIONS.map((kind) => [kind, rectOf(`[data-inline="${kind}"]`)]))
: null,
summarizeRect: popup && !popup.hidden ? rectOf('[data-action="summarize"]') : null,
- translateRect: popup && !popup.hidden ? rectOf('[data-action="translate"]') : null,
+ popupActions: popup
+ ? Array.from(popup.querySelectorAll('[data-action]'), (button) => button.dataset.action)
+ : [],
hideRect: popup && !popup.hidden ? rectOf('.hide') : null,
questionRect: popup && !popup.hidden ? question?.getBoundingClientRect().toJSON() || null : null,
questionValue: question?.value || '',
@@ -1284,7 +1268,6 @@
actionIconCount: shadow?.querySelectorAll('.action > .action-icon').length || 0,
direction: host?.dir || 'ltr',
summarizeLabel: shadow?.querySelector('[data-action="summarize"] .action-label')?.textContent || '',
- explainLabel: shadow?.querySelector('[data-action="explain"] .action-label')?.textContent || '',
quizLabel: shadow?.querySelector('[data-action="quiz"] .action-label')?.textContent || '',
cardVisible: !!card && !card.hidden,
cardKind: cardState?.kind || '',
diff --git a/test/fixtures/run.mjs b/test/fixtures/run.mjs
index 6629fdc31..0b1581a23 100644
--- a/test/fixtures/run.mjs
+++ b/test/fixtures/run.mjs
@@ -1680,9 +1680,9 @@ for (const [label, sourcePath, manualOpen] of [
await setupSelectionShortcut(page, sourcePath, { requiresManualOpen: manualOpen, locale: 'zh' });
const localized = await selectFixtureText(page);
if (localized.summarizeLabel !== '总结'
- || localized.explainLabel !== '解释'
|| localized.quizLabel !== '测验我'
- || localized.actionIconCount !== 6
+ || localized.popupActions.join('|') !== 'summarize|quiz|humanize'
+ || localized.actionIconCount !== 3
|| localized.barLabels.join('|') !== '翻译|解释|校对|更多…'
|| localized.followUpPlaceholder !== '继续追问'
|| localized.direction !== 'ltr') {
@@ -1701,7 +1701,7 @@ for (const [label, sourcePath, manualOpen] of [
await page.evaluate(() => window.__setSelectionShortcutLocale('ar'));
await page.waitForFunction(() => window.__webbrainSelectionShortcut.getState().direction === 'rtl');
const rtl = await page.evaluate(() => window.__webbrainSelectionShortcut.getState());
- if (rtl.summarizeLabel !== 'تلخيص' || rtl.actionIconCount !== 6) {
+ if (rtl.summarizeLabel !== 'تلخيص' || rtl.actionIconCount !== 3) {
throw new Error(`live Arabic localization mismatch: ${JSON.stringify(rtl)}`);
}
});
@@ -1807,8 +1807,8 @@ for (const [label, sourcePath, manualOpen] of [
}
if (!openState.hideRect
|| openState.hideLabel !== 'Hide this'
- || openState.hideRect.width >= openState.translateRect.width
- || Math.abs(openState.hideRect.right - openState.translateRect.right) > 0.5) {
+ || openState.hideRect.width >= openState.summarizeRect.width
+ || Math.abs(openState.hideRect.right - openState.summarizeRect.right) > 0.5) {
throw new Error(`Hide this should be a compact right-aligned footer action: ${JSON.stringify(openState)}`);
}
await page.mouse.click(
@@ -1943,20 +1943,20 @@ for (const [label, sourcePath, manualOpen] of [
translationShortcutRect.left + translationShortcutRect.width / 2,
translationShortcutRect.top + translationShortcutRect.height / 2,
);
- const translateState = await page.evaluate(() => window.__webbrainSelectionShortcut.getState());
- const translateRect = translateState.translateRect;
- if (!translateRect) throw new Error('Translate action was not visible in the popup');
- await page.mouse.click(translateRect.left + translateRect.width / 2, translateRect.top + translateRect.height / 2);
+ const presetState = await page.evaluate(() => window.__webbrainSelectionShortcut.getState());
+ const presetRect = presetState.summarizeRect;
+ if (!presetRect) throw new Error('Summarize action was not visible in the popup');
+ await page.mouse.click(presetRect.left + presetRect.width / 2, presetRect.top + presetRect.height / 2);
await page.waitForFunction(() => window.__selectionMessages.length === 3);
- const translated = await page.evaluate(() => ({
+ const summarized = await page.evaluate(() => ({
message: window.__selectionMessages[2],
state: window.__webbrainSelectionShortcut.getState(),
}));
- if (translated.message.action !== 'translate' || translated.message.language !== 'tr') {
- throw new Error(`translation request was not submitted correctly: ${JSON.stringify(translated.message)}`);
+ if (summarized.message.action !== 'summarize' || summarized.message.language !== 'tr') {
+ throw new Error(`popup preset was not submitted correctly: ${JSON.stringify(summarized.message)}`);
}
- if (translated.state.popupVisible || translated.state.shortcutVisible) {
- throw new Error(`Translate should submit directly and dismiss the surface: ${JSON.stringify(translated.state)}`);
+ if (summarized.state.popupVisible || summarized.state.shortcutVisible) {
+ throw new Error(`a popup preset should submit directly and dismiss the surface: ${JSON.stringify(summarized.state)}`);
}
await page.evaluate(() => window.__setSelectionShortcutLocale('fr'));
@@ -1968,13 +1968,13 @@ for (const [label, sourcePath, manualOpen] of [
);
const updatedLocaleState = await page.evaluate(() => window.__webbrainSelectionShortcut.getState());
await page.mouse.click(
- updatedLocaleState.translateRect.left + updatedLocaleState.translateRect.width / 2,
- updatedLocaleState.translateRect.top + updatedLocaleState.translateRect.height / 2,
+ updatedLocaleState.summarizeRect.left + updatedLocaleState.summarizeRect.width / 2,
+ updatedLocaleState.summarizeRect.top + updatedLocaleState.summarizeRect.height / 2,
);
await page.waitForFunction(() => window.__selectionMessages.length === 4);
const updatedLocaleMessage = await page.evaluate(() => window.__selectionMessages[3]);
- if (updatedLocaleMessage.action !== 'translate' || updatedLocaleMessage.language !== 'fr') {
- throw new Error(`Translate did not follow the updated plugin locale: ${JSON.stringify(updatedLocaleMessage)}`);
+ if (updatedLocaleMessage.action !== 'summarize' || updatedLocaleMessage.language !== 'fr') {
+ throw new Error(`the popup preset did not follow the updated plugin locale: ${JSON.stringify(updatedLocaleMessage)}`);
}
});
diff --git a/test/run.js b/test/run.js
index dd906dc74..3eed2f9fe 100644
--- a/test/run.js
+++ b/test/run.js
@@ -52059,6 +52059,185 @@ test('WebGPU provider stops waiting and cancels the worker when its caller abort
}
});
+test('side panel presence: the background learns which windows show a panel, and only from the panel page', async () => {
+ const { createSidePanelPresence, reportSidePanelPresence, SIDEPANEL_PRESENCE_PORT } = await import(
+ pathToFileURL(path.join(ROOT, 'src/chrome/src/sidepanel-presence.js')).href
+ );
+ const panelUrl = 'chrome-extension://abc/src/ui/sidepanel.html';
+ const api = { runtime: { id: 'abc', getURL: relative => `chrome-extension://abc/${relative}` } };
+ const makePort = (overrides = {}) => {
+ const listeners = { message: [], disconnect: [] };
+ return {
+ name: SIDEPANEL_PRESENCE_PORT,
+ sender: { id: 'abc', url: panelUrl },
+ onMessage: { addListener: callback => listeners.message.push(callback) },
+ onDisconnect: { addListener: callback => listeners.disconnect.push(callback) },
+ say: message => listeners.message.forEach(callback => callback(message)),
+ close: () => listeners.disconnect.forEach(callback => callback()),
+ ...overrides,
+ };
+ };
+
+ const presence = createSidePanelPresence(api);
+ assert.equal(presence.isVisibleInWindow(7), false, 'nothing is visible before a panel reports');
+ const port = makePort();
+ assert.equal(presence.attach(port), true);
+ port.say({ visible: true, windowId: 7 });
+ assert.equal(presence.isVisibleInWindow(7), true);
+ assert.equal(presence.isVisibleInWindow(8), false, 'a panel in another window says nothing about this one');
+ assert.equal(presence.isVisibleInWindow(undefined), false);
+ assert.equal(presence.isVisibleInWindow('7'), false);
+ port.say({ visible: false, windowId: 7 });
+ assert.equal(presence.isVisibleInWindow(7), false, 'a hidden panel is not showing');
+ port.say({ visible: true, windowId: 7 });
+ port.close();
+ assert.equal(presence.isVisibleInWindow(7), false, 'a closed panel is forgotten');
+
+ // Two panels in one window: closing one must not hide the other.
+ const first = makePort();
+ const second = makePort();
+ presence.attach(first);
+ presence.attach(second);
+ first.say({ visible: true, windowId: 3 });
+ second.say({ visible: true, windowId: 3 });
+ first.close();
+ assert.equal(presence.isVisibleInWindow(3), true);
+ second.close();
+ assert.equal(presence.isVisibleInWindow(3), false);
+
+ // Pages that are not the side panel cannot claim a window.
+ for (const bad of [
+ makePort({ name: 'something-else' }),
+ makePort({ sender: { id: 'other', url: panelUrl } }),
+ makePort({ sender: { id: 'abc', url: 'https://example.com/src/ui/sidepanel.html' } }),
+ makePort({ sender: { id: 'abc', url: 'chrome-extension://abc/src/ui/settings.html' } }),
+ makePort({ sender: { id: 'abc' } }),
+ ]) {
+ assert.equal(presence.attach(bad), false);
+ bad.say({ visible: true, windowId: 9 });
+ assert.equal(presence.isVisibleInWindow(9), false);
+ }
+ assert.equal(presence.attach(makePort({ sender: { id: 'abc', url: `${panelUrl}?window=1#x` } })), true,
+ 'a query string or hash on the panel URL is still the panel');
+
+ // The panel side: reports on connect and on every visibility change.
+ const posted = [];
+ const connections = [];
+ const timers = [];
+ let clock = 0;
+ const doc = {
+ visibilityState: 'visible',
+ listeners: [],
+ addEventListener(type, callback) { if (type === 'visibilitychange') this.listeners.push(callback); },
+ removeEventListener(type, callback) { this.listeners = this.listeners.filter(item => item !== callback); },
+ };
+ const runtime = {
+ lastError: undefined,
+ connect({ name }) {
+ const disconnectListeners = [];
+ const connection = {
+ name,
+ postMessage: message => posted.push(message),
+ onDisconnect: { addListener: callback => disconnectListeners.push(callback) },
+ drop: () => disconnectListeners.forEach(callback => callback()),
+ disconnect() { this.disconnected = true; },
+ };
+ connections.push(connection);
+ return connection;
+ },
+ };
+ const reporter = reportSidePanelPresence({
+ runtime,
+ doc,
+ windowId: 5,
+ schedule: (callback, delay) => timers.push({ callback, delay }),
+ now: () => clock,
+ });
+ assert.deepEqual(connections.map(connection => connection.name), [SIDEPANEL_PRESENCE_PORT]);
+ assert.deepEqual(posted, [{ visible: true, windowId: 5 }]);
+ doc.visibilityState = 'hidden';
+ doc.listeners.forEach(callback => callback());
+ assert.deepEqual(posted.at(-1), { visible: false, windowId: 5 });
+ doc.visibilityState = 'visible';
+ doc.listeners.forEach(callback => callback());
+ assert.deepEqual(posted.at(-1), { visible: true, windowId: 5 });
+
+ // A restarted background drops the port; the panel reconnects and says where it stands.
+ clock = 60_000;
+ connections[0].drop();
+ assert.equal(timers.length, 1);
+ assert.equal(timers[0].delay, 500);
+ timers.shift().callback();
+ assert.equal(connections.length, 2, 'the panel reopens its port');
+ assert.deepEqual(posted.at(-1), { visible: true, windowId: 5 });
+
+ // A port that keeps being refused backs off instead of spinning.
+ connections[1].drop();
+ assert.equal(timers[0].delay, 1_000);
+ timers.shift().callback();
+ connections[2].drop();
+ assert.equal(timers[0].delay, 2_000);
+ timers.shift().callback();
+ assert.equal(connections.length, 4);
+
+ reporter.stop();
+ assert.equal(connections.at(-1).disconnected, true);
+ assert.equal(doc.listeners.length, 0);
+ connections.at(-1).drop();
+ timers.splice(0).forEach(timer => timer.callback());
+ assert.equal(connections.length, 4, 'a stopped reporter does not reconnect');
+
+ // Without a window it reports nothing, which keeps the old always-open behaviour.
+ const anonymous = reportSidePanelPresence({ runtime, doc, windowId: null });
+ assert.equal(connections.length, 4);
+ anonymous.stop();
+});
+
+test('background does not re-open a side panel that is already showing, and still opens one that is not', () => {
+ const background = fs.readFileSync(path.join(ROOT, 'src/chrome/src/background.js'), 'utf8');
+ const start = background.indexOf('function openSidePanelForContextMenu(tab) {');
+ const end = background.indexOf('\nasync function handleContextMenuAsk', start);
+ assert.ok(start > 0 && end > start, 'openSidePanelForContextMenu should be found');
+ const source = background.slice(start, end);
+ assert.doesNotMatch(source.replace(/\/\/.*$/gm, ''), /\bawait\b/, 'open() has to run before any await so the user gesture survives');
+
+ const run = (visibleWindowId, tab) => {
+ const calls = [];
+ const context = vm.createContext({
+ panelTabs: new Set(),
+ savePanelTabs: () => calls.push('save'),
+ ensureWebBrainGroup: () => { calls.push('group'); return Promise.resolve(); },
+ sidePanelPresence: { isVisibleInWindow: windowId => windowId === visibleWindowId },
+ chrome: {
+ sidePanel: {
+ setOptions: options => calls.push(['setOptions', options.tabId]),
+ open: options => calls.push(['open', options.tabId]),
+ },
+ },
+ });
+ vm.runInContext(`${source}\nopenSidePanelForContextMenu(${JSON.stringify(tab)});`, context);
+ return calls;
+ };
+
+ assert.deepEqual(run(null, { id: 11, windowId: 4 }),
+ ['save', ['setOptions', 11], ['open', 11], 'group'],
+ 'a closed panel is enabled and opened as before');
+ assert.deepEqual(run(4, { id: 11, windowId: 4 }), ['save', 'group'],
+ 'a panel already showing in the tab\'s window is left alone');
+ assert.deepEqual(run(9, { id: 11, windowId: 4 }),
+ ['save', ['setOptions', 11], ['open', 11], 'group'],
+ 'a panel showing in another window does not count');
+ assert.deepEqual(run(4, { id: 12 }),
+ ['save', ['setOptions', 12], ['open', 12], 'group'],
+ 'a tab with no window id (the PDF viewer stub) keeps opening');
+
+ assert.match(background, /chrome\.runtime\.onConnect\.addListener\(\(port\) => \{ sidePanelPresence\.attach\(port\); \}\);/,
+ 'the presence port must be accepted at the top level of the worker');
+ const panel = fs.readFileSync(path.join(ROOT, 'src/chrome/src/ui/sidepanel.js'), 'utf8');
+ assert.match(panel, /if \(!isBtwWindow\) \{\s*reportSidePanelPresence\(\{[\s\S]*?runtime: chrome\.runtime,[\s\S]*?windowId: initialWindowId \?\? tab\?\.windowId \?\? null,/,
+ 'the side panel must tell the background when it is on screen');
+});
+
test('WebGPU provider drops a request whose caller aborts while the offscreen document is starting', async () => {
const previousChrome = globalThis.chrome;
const sent = [];
@@ -53565,8 +53744,12 @@ test('selection shortcut is shipped, enabled by default, and keeps browser-speci
assert.match(content, /attachShadow\(\{ mode: 'closed' \}\)/, `${label}: selection UI should use a closed Shadow DOM`);
assert.match(content, /const STORAGE_KEY = 'selectionShortcutEnabled';/, `${label}: content script should use the persistent setting`);
assert.match(content, /const LOCALE_STORAGE_KEY = 'wbLocale';/, `${label}: content script should use the plugin interface language`);
- assert.match(content, /data-action="translate">[\s\S]*?<span class="action-label">Translate<\/span>[\s\S]*?<\/button>/, `${label}: floating popup should expose one-click Translate`);
- assert.equal((content.match(/<svg class="action-icon" viewBox="0 0 20 20" fill="none" aria-hidden="true" focusable="false">/g) || []).length, 6, `${label}: all six floating actions should use the same accessible icon shell`);
+ assert.deepEqual(
+ [...content.matchAll(/<button class="action" type="button" data-action="([a-z]+)">/g)].map(match => match[1]),
+ ['summarize', 'quiz', 'humanize'],
+ `${label}: More… should list only what the bar does not already offer (no Translate, Explain or Proofread)`,
+ );
+ assert.equal((content.match(/<svg class="action-icon" viewBox="0 0 20 20" fill="none" aria-hidden="true" focusable="false">/g) || []).length, 3, `${label}: all three More… actions should use the same accessible icon shell`);
assert.match(content, /\.action-icon \{[\s\S]*?width:17px; height:17px; flex:0 0 17px; color:var\(--accent\);[\s\S]*?stroke-width:1\.7;[\s\S]*?stroke-linecap:round; stroke-linejoin:round;/, `${label}: action icons should share one compact line-icon treatment`);
assert.doesNotMatch(content, /knowledge-option|Use general knowledge|generalKnowledge|allowGeneralKnowledge/, `${label}: custom questions should not expose or retain a redundant grounding checkbox`);
assert.match(content, /class="context-option"[\s\S]*?<input type="checkbox" checked>[\s\S]*?<span>Include page &amp; conversation context<\/span>/, `${label}: custom questions should expose a default-on page and conversation context choice`);