Skip to content

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

Mode picker: a tab switch cancels a pick still being checked

Claudecaa882cabfdd
diff --git a/src/chrome/src/ui/sidepanel.js b/src/chrome/src/ui/sidepanel.js
index 2de1d33be..4b32e9c81 100644
--- a/src/chrome/src/ui/sidepanel.js
+++ b/src/chrome/src/ui/sidepanel.js
@@ -1895,6 +1895,9 @@ function syncComposerModeForCurrentTab() {
// On startup and tab switches: a reopened panel finds the tab's kept mode.
function restoreComposerModeForCurrentTab() {
+ // A tab switch supersedes a pick still waiting on its checks, even when the
+ // user comes back to the same tab before they finish.
+ composerModePickGeneration += 1;
syncComposerModeForCurrentTab();
const tabId = currentTabId;
if (isStandaloneWindow || tabId == null) return;
diff --git a/src/firefox/src/ui/sidepanel.js b/src/firefox/src/ui/sidepanel.js
index 0138ab1e1..7ea6e00a7 100644
--- a/src/firefox/src/ui/sidepanel.js
+++ b/src/firefox/src/ui/sidepanel.js
@@ -2070,6 +2070,9 @@ function syncComposerModeForCurrentTab() {
// On startup and tab switches: a reopened panel finds the tab's kept mode.
function restoreComposerModeForCurrentTab() {
+ // A tab switch supersedes a pick still waiting on its checks, even when the
+ // user comes back to the same tab before they finish.
+ composerModePickGeneration += 1;
syncComposerModeForCurrentTab();
const tabId = currentTabId;
if (isStandaloneWindow || tabId == null) return;
diff --git a/test/sidepanel-permission-gate-ui.mjs b/test/sidepanel-permission-gate-ui.mjs
index 8c388d1ab..6150b5ed2 100644
--- a/test/sidepanel-permission-gate-ui.mjs
+++ b/test/sidepanel-permission-gate-ui.mjs
@@ -386,6 +386,20 @@ for (const [build, engine, api] of [['chrome', chromium, 'chrome'], ['firefox',
});
});
+ test('a tab switch cancels a pick still being checked, even back to the same tab', async () => {
+ await fixture(async ({ page }) => {
+ await page.click('#btn-permission-gate');
+ await page.evaluate(() => { window.__release = null; window.__gates.act = new Promise(resolve => { window.__release = resolve; }); });
+ await page.click('.composer-mode-option[data-composer-mode="act"]');
+ await page.evaluate(() => { window.switchTab(8); window.switchTab(7); });
+ await page.evaluate(() => window.__release());
+ await page.waitForTimeout(50);
+ const p = await picker(page);
+ assert.deepEqual(p.state, { auto: true, agentMode: 'ask', pin: null });
+ assert.equal('composerModePin:7' in p.session, false);
+ });
+ });
+
test('a kept mode the new provider cannot run goes back to Auto, after the run', async () => {
await fixture(async ({ page }) => {
await page.click('#btn-permission-gate');