Skip to content

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

Leave a showing side panel alone for selections made in the PDF viewer too

Claudec44ef98ef3a3
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a7eed40ed..13175c7a6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,7 +10,7 @@ This changelog was generated from the repository Git history and release tags. V
- 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, once the answer is there, 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, which picks up from the unfinished text instead of starting over (a side-panel reply that is cut off again says so, including when an OpenAI Responses model reports the limit as an error, in which case the text it wrote is kept), 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 A panel that was open while the background restarted tells the new worker about itself at once instead of after a delay, so a request in that moment does not close it.
+- 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 A panel that was open while the background restarted tells the new worker about itself at once instead of after a delay, so a request in that moment does not close it. The same holds for actions chosen on a selection in WebBrain's PDF viewer.
- 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 500c91b0e..261e56de2 100644
--- a/docs/architecture.md
+++ b/docs/architecture.md
@@ -549,7 +549,10 @@ open panel closes it, so each panel reports its visibility over a long-lived por
(`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. A panel whose port
was dropped by a background restart reconnects at once (only a port that is refused straight
-away backs off), so the restarted worker is not left unaware of a panel that is still showing. The card's
+away backs off), so the restarted worker is not left unaware of a panel that is still showing.
+A selection made in the bundled PDF viewer, whose message carries only a tab id, brings the
+window too (Chrome's `sender.tab` for that tab, else the window the viewer reported from
+`windows.getCurrent()`), so the same check applies there. 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
diff --git a/src/chrome/src/background.js b/src/chrome/src/background.js
index fd39757e6..2a614f8c8 100644
--- a/src/chrome/src/background.js
+++ b/src/chrome/src/background.js
@@ -1903,9 +1903,15 @@ chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
}
// sidePanel.open() must run synchronously in this handler to preserve the
// click gesture; chrome.tabs.get() would lose it. Open for the claimed tab
- // now (stub is enough for setOptions/open), then verify the live tab.
+ // now (stub is enough for setOptions/open), then verify the live tab. The stub
+ // carries the window too, known without an await, so a side panel that is already
+ // showing there is left alone instead of being closed by a second open(): Chrome's
+ // own sender.tab when it is this tab, otherwise the window the viewer reports.
+ const windowId = sender?.tab?.id === tabId && Number.isInteger(sender.tab.windowId)
+ ? sender.tab.windowId
+ : (Number.isInteger(msg.windowId) ? msg.windowId : undefined);
try {
- openSidePanelForContextMenu({ id: tabId });
+ openSidePanelForContextMenu(windowId === undefined ? { id: tabId } : { id: tabId, windowId });
} catch {}
chrome.tabs.get(tabId)
.then(tab => queueSelectionShortcutPrompt(msg, tab, sendResponse))
diff --git a/src/chrome/src/ui/pdf-handler.js b/src/chrome/src/ui/pdf-handler.js
index adec9f04b..73657e89b 100644
--- a/src/chrome/src/ui/pdf-handler.js
+++ b/src/chrome/src/ui/pdf-handler.js
@@ -694,11 +694,16 @@ async function initialize() {
state.streamInfo = streamInfo;
if (streamInfo.embedded === true) document.body.dataset.embedded = 'true';
elements['pdf-title'].textContent = String(streamInfo.originalUrl || 'WebBrain PDF');
+ // The window this viewer is in. The background needs it before its first await to
+ // tell whether WebBrain's side panel is already showing there (re-opening it closes it).
+ let windowId = null;
+ try { windowId = (await api.windows?.getCurrent?.())?.id ?? null; } catch { /* optional */ }
globalThis.__webbrainSelectionShortcutConfig = {
submitMessage: 'WB_PDF_SELECTION_SHORTCUT_SUBMIT',
submitFields: {
tabId: streamInfo.tabId,
originalUrl: String(streamInfo.originalUrl || ''),
+ ...(Number.isInteger(windowId) ? { windowId } : {}),
},
allowNestedFrame: true,
};
diff --git a/test/pdf-selection.mjs b/test/pdf-selection.mjs
index 6c543604b..02b932830 100644
--- a/test/pdf-selection.mjs
+++ b/test/pdf-selection.mjs
@@ -317,7 +317,7 @@ async function testPdfSelectionCarriesItsTabScope() {
};
window.__webbrainSelectionShortcutConfig = {
submitMessage: 'WB_PDF_SELECTION_SHORTCUT_SUBMIT',
- submitFields: { tabId: 73, originalUrl: 'https://papers.example.test/reading.pdf' },
+ submitFields: { tabId: 73, originalUrl: 'https://papers.example.test/reading.pdf', windowId: 5 },
allowNestedFrame: true,
};
` });
@@ -339,6 +339,7 @@ async function testPdfSelectionCarriesItsTabScope() {
assert.equal(message.type, 'WB_PDF_SELECTION_SHORTCUT_SUBMIT');
assert.equal(message.tabId, 73);
assert.equal(message.originalUrl, 'https://papers.example.test/reading.pdf');
+ assert.equal(message.windowId, 5, 'the viewer\'s window travels with the selection');
assert.equal(message.action, 'summarize');
assert.match(message.selectionText, /Selectable text rendered by the PDF text layer/);
} finally {
diff --git a/test/run.js b/test/run.js
index bb22cf2a6..1b0c2db78 100644
--- a/test/run.js
+++ b/test/run.js
@@ -52754,7 +52754,7 @@ test('background does not re-open a side panel that is already showing, and stil
'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');
+ 'a tab with no window id 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');
@@ -52763,6 +52763,63 @@ test('background does not re-open a side panel that is already showing, and stil
'the side panel must tell the background when it is on screen');
});
+test('a PDF viewer selection leaves a side panel that is already showing in its window alone', () => {
+ const background = fs.readFileSync(path.join(ROOT, 'src/chrome/src/background.js'), 'utf8');
+ const helperStart = background.indexOf('function openSidePanelForContextMenu(tab) {');
+ const helperEnd = background.indexOf('\nasync function handleContextMenuAsk', helperStart);
+ const listenerStart = background.indexOf("chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {\n if (msg?.type !== 'WB_PDF_SELECTION_SHORTCUT_SUBMIT') return;");
+ const listenerEnd = background.indexOf('\n// (See the panel visibility comment above', listenerStart);
+ assert.ok(helperStart > 0 && helperEnd > helperStart && listenerStart > 0 && listenerEnd > listenerStart,
+ 'the helper and the PDF listener should be found');
+
+ const run = ({ visibleWindowId, message, sender }) => {
+ const calls = [];
+ let listener = null;
+ const context = vm.createContext({
+ panelTabs: new Set(),
+ savePanelTabs: () => {},
+ ensureWebBrainGroup: () => Promise.resolve(),
+ isPdfHandlerSender: () => true,
+ queueSelectionShortcutPrompt: () => {},
+ sidePanelPresence: { isVisibleInWindow: windowId => windowId === visibleWindowId },
+ chrome: {
+ sidePanel: {
+ setOptions: options => calls.push(['setOptions', options.tabId]),
+ open: options => calls.push(['open', options.tabId]),
+ },
+ tabs: { get: () => new Promise(() => {}) },
+ runtime: { onMessage: { addListener: callback => { listener = callback; } } },
+ },
+ });
+ vm.runInContext(
+ `${background.slice(helperStart, helperEnd)}\n${background.slice(listenerStart, listenerEnd)}`,
+ context,
+ );
+ listener({ type: 'WB_PDF_SELECTION_SHORTCUT_SUBMIT', tabId: 7, ...message }, sender, () => {});
+ return calls;
+ };
+ const opened = [['setOptions', 7], ['open', 7]];
+
+ assert.deepEqual(run({ visibleWindowId: 4, message: { windowId: 4 }, sender: {} }), [],
+ 'a panel showing in the window the viewer reports is left alone');
+ assert.deepEqual(run({ visibleWindowId: 4, message: {}, sender: { tab: { id: 7, windowId: 4 } } }), [],
+ 'Chrome\'s own sender.tab is enough');
+ assert.deepEqual(run({ visibleWindowId: 4, message: { windowId: 9 }, sender: { tab: { id: 7, windowId: 4 } } }), [],
+ 'sender.tab for the claimed tab wins over what the page says');
+ assert.deepEqual(run({ visibleWindowId: 4, message: { windowId: 4 }, sender: { tab: { id: 99, windowId: 9 } } }), [],
+ 'a sender.tab for some other tab is not used');
+ assert.deepEqual(run({ visibleWindowId: 9, message: { windowId: 4 }, sender: {} }), opened,
+ 'a panel showing in another window does not count');
+ assert.deepEqual(run({ visibleWindowId: 4, message: {}, sender: {} }), opened,
+ 'with no window known the panel is opened as before');
+ assert.deepEqual(run({ visibleWindowId: 4, message: { windowId: '4' }, sender: {} }), opened,
+ 'a window id that is not a number is ignored');
+
+ const viewer = fs.readFileSync(path.join(ROOT, 'src/chrome/src/ui/pdf-handler.js'), 'utf8');
+ assert.match(viewer, /windowId = \(await api\.windows\?\.getCurrent\?\.\(\)\)\?\.id \?\? null;[\s\S]*?submitFields: \{[\s\S]*?\.\.\.\(Number\.isInteger\(windowId\) \? \{ windowId \} : \{\}\),/,
+ 'the PDF viewer must report the window it is in');
+});
+
test('WebGPU provider drops a request whose caller aborts while the offscreen document is starting', async () => {
const previousChrome = globalThis.chrome;
const sent = [];