Open-source AI browser agent for Chrome and Firefox (monorepo) ðŸ§
JavaScript ai-agentai-agentsai-toolsbrowser-aibrowser-automationbrowser-extensionchrome-aichrome-devtoolschrome-extensionchrome-extensionsfirefox-addonfirefox-addonsfirefox-extensionfirefox-extensionsgemmagemma4minimaxoffline-aioffline-llmqwen
Refresh billing status after payment recovery and update regressions
Codex release-state test267c2a57e242
diff --git a/src/chrome/src/ui/settings.js b/src/chrome/src/ui/settings.jsindex 0e1544a59..27b9d1dfe 100644--- a/src/chrome/src/ui/settings.js+++ b/src/chrome/src/ui/settings.js@@ -3016,6 +3016,13 @@ async function handleWebgpuDownloadButton(btn) {}async function refreshWebbrainPaymentNotice() {+ if (!refreshWebbrainPaymentNotice._focusBound && typeof window !== 'undefined') {+ window.addEventListener('focus', () => {+ refreshWebbrainPaymentNotice._cache = null;+ void refreshWebbrainPaymentNotice();+ });+ refreshWebbrainPaymentNotice._focusBound = true;+ }const notice = providersContainer.querySelector('.webbrain-payment-notice');const deviceGuid = providersData.webbrain_cloud?.deviceGuid;if (!notice || !deviceGuid) return;@@ -3023,7 +3030,12 @@ async function refreshWebbrainPaymentNotice() {? WEBBRAIN_BILLING_STATUS_URL: 'https://api.webbrain.one/v1/billing/status';const renderNotice = (subscriptionStatus) => {- if (!notice.isConnected || !['past_due', 'unpaid'].includes(subscriptionStatus)) return;+ if (!notice.isConnected) return;+ if (!['past_due', 'unpaid'].includes(subscriptionStatus)) {+ notice.hidden = true;+ notice.replaceChildren();+ return;+ }const message = document.createElement('p');message.textContent = t('st.account.payment_failed');const link = document.createElement('a');@@ -3035,10 +3047,9 @@ async function refreshWebbrainPaymentNotice() {notice.style.cssText = 'margin-top:10px;padding:12px;border-radius:6px;border:1px solid var(--warning,#b7791f);';notice.hidden = false;};- // Per-session cache: renderProviders() runs on every search keystroke and the- // status only changes after a Stripe redirect, so reuse the last lookup.+ // Reuse recent results during search, but refresh on focus or after 30 seconds.const cached = refreshWebbrainPaymentNotice._cache;- if (cached?.deviceGuid === deviceGuid) {+ if (cached?.deviceGuid === deviceGuid && Date.now() - cached.fetchedAt < 30000) {renderNotice(cached.subscriptionStatus);return;}@@ -3065,7 +3076,7 @@ async function refreshWebbrainPaymentNotice() {refreshWebbrainPaymentNotice._inflight = null;}if (subscriptionStatus == null) return;- refreshWebbrainPaymentNotice._cache = { deviceGuid, subscriptionStatus };+ refreshWebbrainPaymentNotice._cache = { deviceGuid, subscriptionStatus, fetchedAt: Date.now() };renderNotice(subscriptionStatus);} catch {if (refreshWebbrainPaymentNotice._inflight?.deviceGuid === deviceGuid) {diff --git a/src/firefox/src/ui/settings.js b/src/firefox/src/ui/settings.jsindex 1dcbfa8fe..275c847c9 100644--- a/src/firefox/src/ui/settings.js+++ b/src/firefox/src/ui/settings.js@@ -2418,6 +2418,13 @@ function providerSubscriptionGuideHtml(definitionId) {}async function refreshWebbrainPaymentNotice() {+ if (!refreshWebbrainPaymentNotice._focusBound && typeof window !== 'undefined') {+ window.addEventListener('focus', () => {+ refreshWebbrainPaymentNotice._cache = null;+ void refreshWebbrainPaymentNotice();+ });+ refreshWebbrainPaymentNotice._focusBound = true;+ }const notice = providersContainer.querySelector('.webbrain-payment-notice');const deviceGuid = providersData.webbrain_cloud?.deviceGuid;if (!notice || !deviceGuid) return;@@ -2425,7 +2432,12 @@ async function refreshWebbrainPaymentNotice() {? WEBBRAIN_BILLING_STATUS_URL: 'https://api.webbrain.one/v1/billing/status';const renderNotice = (subscriptionStatus) => {- if (!notice.isConnected || !['past_due', 'unpaid'].includes(subscriptionStatus)) return;+ if (!notice.isConnected) return;+ if (!['past_due', 'unpaid'].includes(subscriptionStatus)) {+ notice.hidden = true;+ notice.replaceChildren();+ return;+ }const message = document.createElement('p');message.textContent = t('st.account.payment_failed');const link = document.createElement('a');@@ -2437,10 +2449,9 @@ async function refreshWebbrainPaymentNotice() {notice.style.cssText = 'margin-top:10px;padding:12px;border-radius:6px;border:1px solid var(--warning,#b7791f);';notice.hidden = false;};- // Per-session cache: renderProviders() runs on every search keystroke and the- // status only changes after a Stripe redirect, so reuse the last lookup.+ // Reuse recent results during search, but refresh on focus or after 30 seconds.const cached = refreshWebbrainPaymentNotice._cache;- if (cached?.deviceGuid === deviceGuid) {+ if (cached?.deviceGuid === deviceGuid && Date.now() - cached.fetchedAt < 30000) {renderNotice(cached.subscriptionStatus);return;}@@ -2467,7 +2478,7 @@ async function refreshWebbrainPaymentNotice() {refreshWebbrainPaymentNotice._inflight = null;}if (subscriptionStatus == null) return;- refreshWebbrainPaymentNotice._cache = { deviceGuid, subscriptionStatus };+ refreshWebbrainPaymentNotice._cache = { deviceGuid, subscriptionStatus, fetchedAt: Date.now() };renderNotice(subscriptionStatus);} catch {if (refreshWebbrainPaymentNotice._inflight?.deviceGuid === deviceGuid) {diff --git a/test/billing-payment-notice.mjs b/test/billing-payment-notice.mjsindex 6367799ac..86defe9b4 100644--- a/test/billing-payment-notice.mjs+++ b/test/billing-payment-notice.mjs@@ -62,8 +62,13 @@ for (const browser of ['chrome', 'firefox']) {{let fetchCount = 0;+ let backendStatus = 'past_due';+ let now = 0;+ const listeners = {};let currentNotice = { hidden: true, isConnected: true, style: {}, children: [], replaceChildren(...children) { this.children = children; } };const cacheContext = vm.createContext({+ Date: { now: () => now },+ window: { addEventListener: (type, callback) => { listeners[type] = callback; } },providersContainer: { querySelector: () => currentNotice },providersData: { webbrain_cloud: { deviceGuid: 'test-browser', baseUrl: 'https://untrusted.example/v1' } },AbortSignal,@@ -74,7 +79,7 @@ for (const browser of ['chrome', 'firefox']) {fetch: async (url) => {fetchCount += 1;assert.equal(url, 'https://api.webbrain.one/v1/billing/status');- return { ok: true, json: async () => ({ subscription_status: 'past_due' }) };+ return { ok: true, json: async () => ({ subscription_status: backendStatus }) };},});vm.runInContext(source, cacheContext, { filename: fileURLToPath(new URL(`../src/${browser}/src/ui/settings.js`, import.meta.url)) });@@ -85,6 +90,18 @@ for (const browser of ['chrome', 'firefox']) {await vm.runInContext('refreshWebbrainPaymentNotice()', cacheContext);assert.equal(currentNotice.hidden, false, `${browser}: cached second render must still show a payment warning`);assert.equal(fetchCount, 1, `${browser}: second renderProviders() must reuse the per-session billing cache`);+ backendStatus = 'active';+ listeners.focus();+ await vm.runInContext('refreshWebbrainPaymentNotice()', cacheContext);+ assert.equal(fetchCount, 2, `${browser}: billing return must refetch with inflight dedupe`);+ assert.equal(currentNotice.hidden, true, `${browser}: recovery must hide the existing warning`);+ assert.equal(currentNotice.children.length, 0, `${browser}: recovery must clear the old payment link`);+ backendStatus = 'past_due';+ now = 30001;+ await vm.runInContext('refreshWebbrainPaymentNotice()', cacheContext);+ assert.equal(fetchCount, 3, `${browser}: expired active cache must detect payment failures`);+ assert.equal(currentNotice.hidden, false, `${browser}: new payment failure must show the warning`);+}const { OpenAICompatibleProvider: OpenAIProvider } = await import(new URL(`../src/${browser}/src/providers/openai.js`, import.meta.url));@@ -126,6 +143,15 @@ for (const browser of ['chrome', 'firefox']) {const renderCard = vm.runInNewContext(`${declaration}\n${actionLabelsSrc}\n${resumeLabelsSrc}\n${cardSource}\nrenderSubscribeError`, {parseSubscribeError: parse, document: { createElement: element }, t: key => en[key],});+ for (const [action, prefix, actionKey, resumeKey] of [+ ['subscribe', 'Subscribe for more usage', 'sp.subscribe.btn', 'sp.subscribe.resume'],+ ['upgrade', 'Upgrade to WebBrain Plus', 'sp.subscribe.upgrade', 'sp.subscribe.resume_upgrade'],+ ]) {+ const actionCard = element();+ assert.equal(renderCard(actionCard, `Allowance used.\n${prefix}: https://api.webbrain.one/account`, 'act'), true);+ assert.equal(actionCard.children[1].children[0].textContent, en[actionKey], `${browser}: ${action} action label`);+ assert.equal(actionCard.children[1].children[1].textContent, en[resumeKey], `${browser}: ${action} resume label`);+ }const card = element();assert.equal(renderCard(card, error, 'ask'), true);assert.equal(card.children[1].children[0].textContent, en['st.account.update_payment']);diff --git a/test/run.js b/test/run.jsindex 98dd6fdae..055c5e14d 100644--- a/test/run.js+++ b/test/run.js@@ -45829,8 +45829,8 @@ test('sidepanel subscribe error card clears DOM without HTML reinterpretation',assert.doesNotMatch(body, /textEl\.innerHTML\s*=\s*'';/, `${label}: subscribe card should not clear via innerHTML`);assert.match(body, /msg\.textContent = parsed\.message \|\| t\('sp\.subscribe\.allowance_used'\);/, `${label}: subscribe message must remain textContent`);assert.match(body, /actions\.className = 'subscribe-actions';/, `${label}: subscribe actions should share a responsive row`);- assert.match(body, /resumeBtn\.textContent = t\(parsed\.action === 'upgrade' \? 'sp\.subscribe\.resume_upgrade' : 'sp\.subscribe\.resume'\);/, `${label}: billing card should render a localized action-specific resume label`);- assert.match(body, /btn\.textContent = t\(parsed\.action === 'upgrade' \? 'sp\.subscribe\.upgrade' : 'sp\.subscribe\.btn'\);/, `${label}: billing card should distinguish subscription and Plus upgrades`);+ assert.match(body, /resumeBtn\.textContent = t\(SUBSCRIBE_RESUME_LABELS\[parsed\.action\] \|\| SUBSCRIBE_RESUME_LABELS\.subscribe\);/, `${label}: billing card should render a localized action-specific resume label`);+ assert.match(body, /btn\.textContent = t\(SUBSCRIBE_ACTION_LABELS\[parsed\.action\] \|\| SUBSCRIBE_ACTION_LABELS\.subscribe\);/, `${label}: billing card should distinguish subscription and Plus upgrades`);assert.match(body, /resumeBtn\.dataset\.resumeMode = \['ask', 'act', 'dev'\]\.includes\(resumeMode\)[\s\S]*?\? resumeMode[\s\S]*?: \(textEl\.closest\('\.message\.assistant'\)\?\.dataset\.runMode \|\| agentMode\);/, `${label}: resume action should prefer an explicitly captured failed run mode`);assert.match(body, /resumeAfterSubscription\(resumeBtn\)/, `${label}: subscribe card should use the shared resume handler`);assert.match(panel, /function resumeAfterSubscription\(btn\) \{[\s\S]*?const mode = \['ask', 'act', 'dev'\]\.includes\(btn\?\.dataset\?\.resumeMode\)[\s\S]*?setMode\(mode\);[\s\S]*?continueAgent\(\{[\s\S]*?mode,[\s\S]*?foreground: btn\?\.dataset\?\.resumeForeground === 'true',[\s\S]*?\}\);[\s\S]*?\}/, `${label}: subscribe resume should synchronize the visible mode and preserve foreground mode before continuing`);