Skip to content

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

Keep the connection status across language changes

Emre Sokullud7d27bd96551
diff --git a/src/chrome/src/ui/sidepanel.html b/src/chrome/src/ui/sidepanel.html
index b21c24a88..f0e5c95b3 100644
--- a/src/chrome/src/ui/sidepanel.html
+++ b/src/chrome/src/ui/sidepanel.html
@@ -406,7 +406,7 @@
<path d="M3 11v4"/>
<path d="M3 13h4"/>
</svg>
- <span id="status-dot" class="status-dot offline" data-i18n-title="sp.status.disconnected"></span>
+ <span id="status-dot" class="status-dot offline"></span>
</span>
<span class="provider-picker-label" id="provider-picker-label"></span>
<span class="provider-picker-caret" aria-hidden="true">
diff --git a/src/chrome/src/ui/sidepanel.js b/src/chrome/src/ui/sidepanel.js
index 85cfb0cc2..0542b7a42 100644
--- a/src/chrome/src/ui/sidepanel.js
+++ b/src/chrome/src/ui/sidepanel.js
@@ -730,6 +730,12 @@ const languagePickerBtn = document.getElementById('language-picker-btn');
const languagePickerMenu = document.getElementById('language-picker-menu');
const MORE_PROVIDERS_OPTION_VALUE = '__more_providers__';
const statusDot = document.getElementById('status-dot');
+// The dot's title is also the model button's accessible description. It is
+// kept as a function of the language (setStatusDot), so a language change
+// says the live status again (syncProviderPickerButton) instead of a fixed
+// first value.
+let statusDotTitle = () => t('sp.status.disconnected');
+if (statusDot) statusDot.title = statusDotTitle();
// Short labels for the closed picker button (menu rows keep the longer status text).
const providerPickerLabelById = new Map();
// The configured model of each provider, for the picker's tooltip and name.
@@ -8356,6 +8362,9 @@ function syncProviderPickerButton() {
providerPickerBtn.title = label;
providerPickerBtn.setAttribute('aria-label', label);
}
+ // The dot's title is the button's description: a language change renders the
+ // name again here, so it says the live status again too.
+ if (statusDot) statusDot.title = statusDotTitle();
if (providerPickerMenu) {
providerPickerMenu.querySelectorAll('.provider-picker-option').forEach((btn) => {
btn.setAttribute('aria-selected', btn.dataset.value === id ? 'true' : 'false');
@@ -8715,14 +8724,12 @@ function isWebBrainCloudProviderSelected() {
}
function markSelectedProviderUntested() {
- statusDot.className = 'status-dot';
- statusDot.title = providerSelect?.selectedOptions?.[0]?.textContent || providerSelect?.value || '';
+ setStatusDot('', () => providerSelect?.selectedOptions?.[0]?.textContent || providerSelect?.value || '');
}
function markSelectedProviderFailed(error) {
- const msg = error?.message || t('sp.status.failed');
- statusDot.className = 'status-dot offline';
- statusDot.title = t('sp.status.error', { msg });
+ const reason = error?.message;
+ setStatusDot('offline', () => t('sp.status.error', { msg: reason || t('sp.status.failed') }));
}
async function testConnection(options = {}) {
@@ -8734,28 +8741,34 @@ async function testConnection(options = {}) {
}
return;
}
- statusDot.className = 'status-dot connecting';
- // The dot's title is the picker button's description: replace the last
- // result while the check runs.
- statusDot.title = t('sp.status.connecting');
+ // The title says so too: it is the picker button's description, which must
+ // not repeat the last result while the check runs.
+ setStatusDot('connecting', () => t('sp.status.connecting'));
try {
const res = await sendToBackground('test_provider', {
providerId,
});
if (requestId !== providerTestRequestId || providerSelect.value !== providerId) return;
- statusDot.className = `status-dot ${res.ok ? 'online' : 'offline'}`;
- statusDot.title = res.ok
- ? t('sp.status.connected', { model: res.model || providerId })
- : t('sp.status.error', { msg: res.error });
+ setStatusDot(res.ok ? 'online' : 'offline', res.ok
+ ? () => t('sp.status.connected', { model: res.model || providerId })
+ : () => t('sp.status.error', { msg: res.error }));
return res;
} catch (error) {
if (requestId !== providerTestRequestId || providerSelect.value !== providerId) return;
- statusDot.className = 'status-dot offline';
- statusDot.title = t('sp.status.failed');
+ setStatusDot('offline', () => t('sp.status.failed'));
return { ok: false, error: error?.message || t('sp.status.failed') };
}
}
+// Sets the connection dot's state ('' while untested) and its title, which is
+// kept as a function so syncProviderPickerButton can say it again after a
+// language change.
+function setStatusDot(state, title) {
+ statusDot.className = state ? `status-dot ${state}` : 'status-dot';
+ statusDotTitle = title;
+ statusDot.title = title();
+}
+
function getSlashAutocompleteContext() {
if (!inputEl) return null;
const value = inputEl.value;
diff --git a/src/firefox/src/ui/sidepanel.html b/src/firefox/src/ui/sidepanel.html
index 5e76bd15f..f2b9c10c4 100644
--- a/src/firefox/src/ui/sidepanel.html
+++ b/src/firefox/src/ui/sidepanel.html
@@ -368,7 +368,7 @@
<path d="M3 11v4"/>
<path d="M3 13h4"/>
</svg>
- <span id="status-dot" class="status-dot offline" data-i18n-title="sp.status.disconnected"></span>
+ <span id="status-dot" class="status-dot offline"></span>
</span>
<span class="provider-picker-label" id="provider-picker-label"></span>
<span class="provider-picker-caret" aria-hidden="true">
diff --git a/src/firefox/src/ui/sidepanel.js b/src/firefox/src/ui/sidepanel.js
index d76930dfc..aa57289f0 100644
--- a/src/firefox/src/ui/sidepanel.js
+++ b/src/firefox/src/ui/sidepanel.js
@@ -605,6 +605,12 @@ const languagePickerBtn = document.getElementById('language-picker-btn');
const languagePickerMenu = document.getElementById('language-picker-menu');
const MORE_PROVIDERS_OPTION_VALUE = '__more_providers__';
const statusDot = document.getElementById('status-dot');
+// The dot's title is also the model button's accessible description. It is
+// kept as a function of the language (setStatusDot), so a language change
+// says the live status again (syncProviderPickerButton) instead of a fixed
+// first value.
+let statusDotTitle = () => t('sp.status.disconnected');
+if (statusDot) statusDot.title = statusDotTitle();
// Short labels for the closed picker button (menu rows keep the longer status text).
const providerPickerLabelById = new Map();
// The configured model of each provider, for the picker's tooltip and name.
@@ -8186,6 +8192,9 @@ function syncProviderPickerButton() {
providerPickerBtn.title = label;
providerPickerBtn.setAttribute('aria-label', label);
}
+ // The dot's title is the button's description: a language change renders the
+ // name again here, so it says the live status again too.
+ if (statusDot) statusDot.title = statusDotTitle();
if (providerPickerMenu) {
providerPickerMenu.querySelectorAll('.provider-picker-option').forEach((btn) => {
btn.setAttribute('aria-selected', btn.dataset.value === id ? 'true' : 'false');
@@ -8496,14 +8505,12 @@ function isWebBrainCloudProviderSelected() {
}
function markSelectedProviderUntested() {
- statusDot.className = 'status-dot';
- statusDot.title = providerSelect?.selectedOptions?.[0]?.textContent || providerSelect?.value || '';
+ setStatusDot('', () => providerSelect?.selectedOptions?.[0]?.textContent || providerSelect?.value || '');
}
function markSelectedProviderFailed(error) {
- const msg = error?.message || t('sp.status.failed');
- statusDot.className = 'status-dot offline';
- statusDot.title = t('sp.status.error', { msg });
+ const reason = error?.message;
+ setStatusDot('offline', () => t('sp.status.error', { msg: reason || t('sp.status.failed') }));
}
async function testConnection(options = {}) {
@@ -8515,28 +8522,34 @@ async function testConnection(options = {}) {
}
return;
}
- statusDot.className = 'status-dot connecting';
- // The dot's title is the picker button's description: replace the last
- // result while the check runs.
- statusDot.title = t('sp.status.connecting');
+ // The title says so too: it is the picker button's description, which must
+ // not repeat the last result while the check runs.
+ setStatusDot('connecting', () => t('sp.status.connecting'));
try {
const res = await sendToBackground('test_provider', {
providerId,
});
if (requestId !== providerTestRequestId || providerSelect.value !== providerId) return;
- statusDot.className = `status-dot ${res.ok ? 'online' : 'offline'}`;
- statusDot.title = res.ok
- ? t('sp.status.connected', { model: res.model || providerId })
- : t('sp.status.error', { msg: res.error });
+ setStatusDot(res.ok ? 'online' : 'offline', res.ok
+ ? () => t('sp.status.connected', { model: res.model || providerId })
+ : () => t('sp.status.error', { msg: res.error }));
return res;
} catch (error) {
if (requestId !== providerTestRequestId || providerSelect.value !== providerId) return;
- statusDot.className = 'status-dot offline';
- statusDot.title = t('sp.status.failed');
+ setStatusDot('offline', () => t('sp.status.failed'));
return { ok: false, error: error?.message || t('sp.status.failed') };
}
}
+// Sets the connection dot's state ('' while untested) and its title, which is
+// kept as a function so syncProviderPickerButton can say it again after a
+// language change.
+function setStatusDot(state, title) {
+ statusDot.className = state ? `status-dot ${state}` : 'status-dot';
+ statusDotTitle = title;
+ statusDot.title = title();
+}
+
function getSlashAutocompleteContext() {
if (!inputEl) return null;
const value = inputEl.value;
diff --git a/test/model-picker-icon.mjs b/test/model-picker-icon.mjs
index e7a3d1bcd..8e4161776 100644
--- a/test/model-picker-icon.mjs
+++ b/test/model-picker-icon.mjs
@@ -16,10 +16,13 @@ for (const build of ['chrome', 'firefox']) {
test(`${build}: the closed model picker is an engine icon`, () => {
const html = read(build, 'src/ui/sidepanel.html');
const button = html.match(/<button type="button" id="provider-picker-btn"[\s\S]*?<\/button>/)[0];
- assert.match(button, /<span class="provider-picker-engine">\s*<svg class="provider-picker-icon"[^>]*aria-hidden="true">[\s\S]*?<\/svg>\s*<span id="status-dot" class="status-dot offline" data-i18n-title="sp\.status\.disconnected"><\/span>\s*<\/span>\s*<span class="provider-picker-label" id="provider-picker-label"><\/span>/,
+ assert.match(button, /<span class="provider-picker-engine">\s*<svg class="provider-picker-icon"[^>]*aria-hidden="true">[\s\S]*?<\/svg>\s*<span id="status-dot" class="status-dot offline"><\/span>\s*<\/span>\s*<span class="provider-picker-label" id="provider-picker-label"><\/span>/,
'the icon comes first, hidden from assistive technology, with the connection dot on it');
assert.match(button, /aria-describedby="status-dot"/, 'the connection status describes the button');
assert.equal(html.match(/id="status-dot"/g).length, 1, 'the dot is no longer a separate toolbar item');
+ // applyDOMTranslations would reset a data-i18n-title to its first value on
+ // every language change; the live status is rendered by sidepanel.js.
+ assert.doesNotMatch(button, /id="status-dot"[^>]*data-i18n/, 'the dot title is not a fixed translation');
const css = read(build, 'styles/sidepanel.css');
assert.match(css, /\.composer-toolbar \.provider-picker-label \{\s*display: none;\s*\}/, 'the name is not shown in the composer');
assert.doesNotMatch(css, /\.composer-toolbar \.provider-picker \{\s*\/\* 100% minus/, 'the picker no longer claims a whole row at large scales');
@@ -40,6 +43,8 @@ for (const build of ['chrome', 'firefox']) {
providerPickerModelById: new Map([['openrouter', 'openai/gpt-6-luna'], ['local', 'gpt-6-luna']]),
providerPickerBtn: { title: '', setAttribute(k, v) { attributes[k] = v; } },
providerPickerMenu: { querySelectorAll: () => options },
+ statusDot: { title: '' },
+ statusDotTitle: () => en['sp.status.connecting'],
});
vm.runInContext(extract(panel, 'syncProviderPickerButton'), context);
context.syncProviderPickerButton();
@@ -80,7 +85,7 @@ for (const build of ['chrome', 'firefox']) {
sendToBackground: async () => new Promise((resolve) => { answer = resolve; }),
markSelectedProviderUntested() { throw new Error('openrouter is tested'); },
});
- vm.runInContext(extract(panel, 'testConnection'), context);
+ vm.runInContext(extract(panel, 'setStatusDot') + extract(panel, 'testConnection'), context);
const pending = context.testConnection();
assert.equal(context.statusDot.className, 'status-dot connecting');
assert.equal(context.statusDot.title, 'Checking connection…');
@@ -89,6 +94,49 @@ for (const build of ['chrome', 'firefox']) {
assert.equal(context.statusDot.className, 'status-dot online');
assert.equal(context.statusDot.title, 'Connected (gpt-6-luna)');
});
+
+ test(`${build}: a language change says the live status again, not "Disconnected"`, async () => {
+ const dicts = {
+ en: (await import(`../src/${build}/src/ui/locales/en.js`)).default,
+ tr: (await import(`../src/${build}/src/ui/locales/tr.js`)).default,
+ };
+ const panel = read(build, 'src/ui/sidepanel.js');
+ let locale = 'en';
+ let answer;
+ const context = vm.createContext({
+ t: (key, params = {}) => String(dicts[locale][key] || key).replace(/\{(\w+)\}/g, (_, k) => params[k] ?? ''),
+ providerSelect: { value: 'openrouter', selectedOptions: [{ textContent: 'OpenRouter — Active' }] },
+ providerTestRequestId: 0,
+ providerPickerLabel: { textContent: '' },
+ providerPickerLabelById: new Map([['openrouter', 'OpenRouter']]),
+ providerPickerModelById: new Map(),
+ providerPickerBtn: { title: '', setAttribute() {} },
+ providerPickerMenu: null,
+ statusDot: { className: 'status-dot offline', title: '' },
+ sendToBackground: async () => new Promise((resolve) => { answer = resolve; }),
+ });
+ vm.runInContext(['setStatusDot', 'testConnection', 'syncProviderPickerButton', 'markSelectedProviderFailed', 'markSelectedProviderUntested']
+ .map((name) => extract(panel, name)).join('\n'), context);
+ const relabel = (code) => { locale = code; context.syncProviderPickerButton(); return context.statusDot.title; };
+
+ const pending = context.testConnection();
+ assert.equal(relabel('tr'), dicts.tr['sp.status.connecting'], 'checking, in the new language');
+ answer({ ok: true, model: 'gpt-6-luna' });
+ await pending;
+ assert.equal(context.statusDot.title, 'Bağlı (gpt-6-luna)');
+ assert.equal(relabel('en'), 'Connected (gpt-6-luna)');
+ assert.equal(context.statusDot.className, 'status-dot online', 'the state is kept');
+
+ context.markSelectedProviderFailed(new Error('401 Unauthorized'));
+ assert.equal(relabel('tr'), 'Hata: 401 Unauthorized');
+ context.markSelectedProviderFailed(null);
+ assert.equal(relabel('en'), 'Error: Connection failed');
+ assert.equal(relabel('tr'), 'Hata: Bağlantı başarısız');
+
+ context.markSelectedProviderUntested();
+ assert.equal(context.statusDot.className, 'status-dot');
+ assert.equal(relabel('en'), 'OpenRouter — Active', 'untested: the provider row, as before');
+ });
}
test('every language names the active model', async () => {
diff --git a/test/run.js b/test/run.js
index d31e46159..7bcd70374 100644
--- a/test/run.js
+++ b/test/run.js
@@ -50363,17 +50363,17 @@ test('sidepanel drops stale provider selection and connection checks', () => {
const managedCloudSkipIdx = testBody.indexOf("['webbrain_cloud', 'webbrain_cloud_max'].includes(providerId)");
const sendIdx = testBody.indexOf("sendToBackground('test_provider'");
const staleGuardIdx = testBody.indexOf('if (requestId !== providerTestRequestId || providerSelect.value !== providerId) return;');
- const statusIdx = testBody.indexOf("statusDot.className = `status-dot ${res.ok ? 'online' : 'offline'}`;");
+ const statusIdx = testBody.indexOf("setStatusDot(res.ok ? 'online' : 'offline', res.ok");
assert.notEqual(captureIdx, -1, `${label}: provider test should capture the intended provider`);
assert.notEqual(requestIdx, -1, `${label}: provider test should increment a request sequence`);
assert.notEqual(managedCloudSkipIdx, -1, `${label}: startup connection tests should skip both managed cloud profiles`);
assert.notEqual(sendIdx, -1, `${label}: provider test background request missing`);
assert.notEqual(staleGuardIdx, -1, `${label}: stale provider test results should be dropped`);
assert.notEqual(statusIdx, -1, `${label}: provider status update missing`);
- assert.match(testBody, /statusDot\.className = 'status-dot connecting';[\s\S]*?statusDot\.title = t\('sp\.status\.connecting'\);[\s\S]*?sendToBackground\('test_provider'/, `${label}: a check in progress replaces the last result in the dot's title (the picker's description)`);
+ assert.match(testBody, /setStatusDot\('connecting', \(\) => t\('sp\.status\.connecting'\)\);[\s\S]*?sendToBackground\('test_provider'/, `${label}: a check in progress replaces the last result in the dot's title (the picker's description)`);
assert.equal(captureIdx < requestIdx && requestIdx < sendIdx && sendIdx < staleGuardIdx && staleGuardIdx < statusIdx, true, `${label}: provider test stale guard must run after the async request and before status updates`);
assert.doesNotMatch(testBody, /providerId: providerSelect\.value/, `${label}: provider test should not read the mutable selection after async delay`);
- assert.match(panel, /function markSelectedProviderFailed\(error\) \{[\s\S]*?const msg = error\?\.message \|\| t\('sp\.status\.failed'\);[\s\S]*?statusDot\.className = 'status-dot offline';[\s\S]*?statusDot\.title = t\('sp\.status\.error', \{ msg \}\);[\s\S]*?\}/, `${label}: provider activation failures should surface on the selected provider`);
+ assert.match(panel, /function markSelectedProviderFailed\(error\) \{[\s\S]*?const reason = error\?\.message;[\s\S]*?setStatusDot\('offline', \(\) => t\('sp\.status\.error', \{ msg: reason \|\| t\('sp\.status\.failed'\) \}\)\);[\s\S]*?\}/, `${label}: provider activation failures should surface on the selected provider`);
const changeStart = panel.indexOf("providerSelect.addEventListener('change', async () => {");
assert.notEqual(changeStart, -1, `${label}: provider change handler missing`);