Skip to content

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

Mode picker: a tab switch never drains another tab's Dev run

Claudeb8b7f4b98b4e
diff --git a/src/chrome/src/ui/sidepanel.js b/src/chrome/src/ui/sidepanel.js
index e7664a5a0..3758eba3c 100644
--- a/src/chrome/src/ui/sidepanel.js
+++ b/src/chrome/src/ui/sidepanel.js
@@ -1907,7 +1907,12 @@ function restoreComposerModeForCurrentTab() {
function setComposerModePinForTab(tabId, mode) {
if (isStandaloneWindow || tabId == null) return;
+ const previous = composerModePins.get(tabId);
void composerModePins.set(tabId, mode);
+ // Leaving a kept Dev drains that tab's diagnostics, never another tab's.
+ if (previous === 'dev' && mode !== 'dev') {
+ sendToBackground('disable_dev_diagnostics', { tabId: Number(tabId) }).catch(() => {});
+ }
if (sameTabId(currentTabId, tabId)) syncComposerModeForCurrentTab();
}
@@ -14996,7 +15001,10 @@ function setMode(mode, { pinned = false } = {}) {
else if (!pinned && composerModePinForCurrentTab()) return;
const previousMode = agentMode;
agentMode = mode;
- if (previousMode === 'dev' && mode !== 'dev') {
+ // A kept mode follows the visible tab, so a tab switch must not drain a
+ // Dev run still going in another tab: leaving a kept Dev drains only its
+ // own tab (setComposerModePinForTab).
+ if (previousMode === 'dev' && mode !== 'dev' && !pinned) {
// Dev mode is panel-wide, while diagnostics may be active on a tab the
// user switched away from. Ask the background to drain its tracked set
// instead of assuming currentTabId is the tab that started capture.
diff --git a/test/auto-mode.mjs b/test/auto-mode.mjs
index cc90cf781..6cc10cad3 100644
--- a/test/auto-mode.mjs
+++ b/test/auto-mode.mjs
@@ -855,6 +855,11 @@ for (const build of BUILDS) {
assert.match(panel, /isProcessing = effectiveProcessing;\s*renderComposerModePicker\(\);\s*if \(!effectiveProcessing && composerModePinCheckPending\) void revalidateComposerModePin\(\);/);
assert.match(panel, /if \(changes\.providers \|\| changes\.activeProvider\) \{\s*void loadProviders\(\);[^}]*void revalidateComposerModePin\(\);\s*\}/);
assert.match(panel, /if \(agentMode === 'dev' && switchMode\) return true;/);
+ if (build === 'chrome') {
+ // Following the visible tab's kept mode never drains another tab's Dev run.
+ assert.match(panel, /if \(previousMode === 'dev' && mode !== 'dev' && !pinned\) \{/);
+ assert.match(panel, /if \(previous === 'dev' && mode !== 'dev'\) \{\s*sendToBackground\('disable_dev_diagnostics', \{ tabId: Number\(tabId\) \}\)/);
+ }
// The menu checks Act and Dev like the shortcuts but never switches through them.
assert.match(panel, /const allowed = pin === 'act' \? await ensureActMode\(\{ switchMode: false \}\)\s*: pin === 'dev' \? await ensureDevMode\(\{ switchMode: false \}\)\s*: true;/);
const input = { value: '/act book it', focus() {}, setSelectionRange() {} };
diff --git a/test/sidepanel-permission-gate-ui.mjs b/test/sidepanel-permission-gate-ui.mjs
index bfe14bb7f..3012404d4 100644
--- a/test/sidepanel-permission-gate-ui.mjs
+++ b/test/sidepanel-permission-gate-ui.mjs
@@ -47,7 +47,8 @@ for (const [build, engine, api] of [['chrome', chromium, 'chrome'], ['firefox',
await page.addScriptTag({ type: 'module', content: `
import { t, applyDOMTranslations } from '/src/${build}/src/ui/i18n.js';
import { createComposerModePins } from '/src/${build}/src/ui/composer-mode-pin.js';
- const log = window.__log = { writes: [], notices: [], toasts: [], opened: [], actWarning: 0, placeholder: 0, scaleClosed: 0, setMode: [], ensure: [] };
+ const log = window.__log = { writes: [], notices: [], toasts: [], opened: [], actWarning: 0, placeholder: 0, scaleClosed: 0, setMode: [], ensure: [], background: [] };
+ const sendToBackground = async (action, params = {}) => { log.background.push({ action, params }); return {}; };
// The mode picker's collaborators: the panel's mode state and checks.
const session = window.__session = { ${storedPin ? `'composerModePin:7': ${JSON.stringify(storedPin)}` : ''} };
const sessionArea = {
@@ -395,6 +396,23 @@ for (const [build, engine, api] of [['chrome', chromium, 'chrome'], ['firefox',
});
});
+ test('a tab switch never drains Dev diagnostics; leaving a kept Dev drains only its tab', async () => {
+ await fixture(async ({ page }) => {
+ await page.click('#btn-permission-gate');
+ await page.click('.composer-mode-option[data-composer-mode="dev"]');
+ await page.waitForFunction(() => window.modeState().pin === 'dev');
+ // Tab 7 runs Dev; the user looks at tab 8 (Auto) and back.
+ await page.evaluate(() => { window.switchTab(8); window.switchTab(7); });
+ await page.waitForFunction(() => window.modeState().pin === 'dev');
+ assert.deepEqual((await picker(page)).log.background, [], 'switching tabs drains nothing');
+ await page.click('.composer-mode-option[data-composer-mode="auto"]');
+ await page.waitForFunction(() => window.modeState().auto === true);
+ assert.deepEqual((await picker(page)).log.background,
+ build === 'chrome' ? [{ action: 'disable_dev_diagnostics', params: { tabId: 7 } }] : [],
+ 'only the tab that left Dev is drained (Chrome has Dev diagnostics)');
+ });
+ });
+
test('a kept mode keeps the toolbar on one row in a narrow panel', async () => {
await fixture(async ({ page }) => {
await page.click('#btn-permission-gate');