An agentic browser harness: an AI side panel & orb in your own logged-in Chrome, Edge, Arc, Brave or even Firefox run by the agent/subscription you already use (Claude Code, Codex, Antigravity). Free, open source, no API key. Also an MCP server.
TypeScript agentic-browseragentic-browsingagy-cliaiai-agentai-browser-extensionai-toolsbrave-extensionbrowser-agentbrowser-automationbrowser-extensionbrowser-usebrowserskillchrome-extensionclaude-codecodexfirefox-addonmcp-servernanobrowserweb-automation
feat(extension): an update pill above the prompt — once the browser has downloaded a newer extension, Browsentic vX is ready offers Update, which restarts the extension onto it instead of waiting for an idle moment a live Bridge never allows; a Bridge newer than the extension asks the store at once, and an unpacked copy offers the folder the Bridge rewrote
Shahriar1a537c34c599
diff --git a/docs/guide/install.md b/docs/guide/install.mdindex 2a18418..6eed480 100644--- a/docs/guide/install.md+++ b/docs/guide/install.md@@ -123,11 +123,11 @@ detail.| What | How it updates || --- | --- |-| The extension from the Chrome Web Store or Edge Add-ons | On its own, when the browser checks (every few hours). **Update** at `chrome://extensions` (`edge://extensions` in Edge), with Developer mode on, checks now |-| The Firefox add-on | On its own, about once a day. `about:addons` → the gear → **Check for Updates** checks now |+| The extension from the Chrome Web Store or Edge Add-ons | The browser downloads it when it checks (every few hours), or as soon as the Bridge is newer than the extension; then the side panel says the new version is ready above the prompt; press **Update**. A browser restart installs it too |+| The Firefox add-on | Firefox downloads it about once a day, or as soon as the Bridge is newer; then the side panel says the new version is ready above the prompt; press **Update**. `about:addons` → the gear → **Check for Updates** checks now || Browsentic Bridge, from an app | The app offers each release on its Overview tab; one press updates the app and the Bridge || Browsentic Bridge, from `npx` | `npx browsentic@latest update` |-| An unpacked copy | `browsentic update` rewrites the folder in place; press ↻ on its card |+| An unpacked copy | `browsentic update` rewrites the folder in place; press **Update** in the side panel, or ↻ on its card |The extension and the Bridge do not have to be the same version. A store copy can update before orafter the Bridge does, and they go on working: Browsentic Bridge 0.8 works with the extension from@@ -168,8 +168,9 @@ yet, Mozilla is still signing that version; it appears within minutes, occasiona**2. Enter the pairing code** in the popup and press **Connect**.-Firefox checks for a newer signed build about once a day and updates itself; there is no ↻ step and-nothing to reload.+Firefox checks for a newer signed build about once a day, and sooner once the Bridge is newer. When+it has one, the side panel says so above the prompt; press **Update**, or let the next Firefox start+install it. There is no ↻ step.Nine tools that need Chrome's debugger (the trusted click, the captcha, diagnostics and page-codetools) do not exist on Firefox, and the agent there is not offered them. [Limits](limits.md) hasdiff --git a/docs/guide/mac-app.md b/docs/guide/mac-app.mdindex 067959a..6d79429 100644--- a/docs/guide/mac-app.md+++ b/docs/guide/mac-app.md@@ -116,8 +116,9 @@ the release, checks its signature and that it is the version it claims to be, thand reopens it. The new app replaces the Bridge and restarts it. **Check for updates** on the samecard checks again immediately.-The extension updates itself from its store. Only an unpacked copy needs ↻ on its card at-`chrome://extensions`, and the app tells you when. The extension and the Bridge do not have to be+The extension downloads its updates from its store, and the side panel offers **Update** once one+is ready. An unpacked copy needs ↻ on its card at `chrome://extensions`, or **Update** in the side+panel, and the app tells you when. The extension and the Bridge do not have to bethe same version.A release reaches npm a few minutes before its Mac build is attached; until then the card says sodiff --git a/docs/guide/maintenance.md b/docs/guide/maintenance.mdindex e6f69a1..f9b842c 100644--- a/docs/guide/maintenance.md+++ b/docs/guide/maintenance.md@@ -13,11 +13,11 @@ working whether it updates first or last.| What | How || --- | --- |-| The extension from the Chrome Web Store or Edge Add-ons | Updates itself when the browser checks, every few hours. **Update** at `chrome://extensions` (`edge://extensions` in Edge), with Developer mode on, checks now |-| The Firefox add-on | Updates itself: every release publishes a signed `.xpi` and an `updates.json` beside it, Firefox polls that file about once a day, and **Check for Updates** in `about:addons` polls it now |+| The extension from the Chrome Web Store or Edge Add-ons | The browser downloads the update when it checks, every few hours, or as soon as the Bridge is newer than the extension. It holds it until the extension restarts, so the side panel says the new version is ready above the prompt; press **Update**. Restarting the browser installs it too |+| The Firefox add-on | Every release publishes a signed `.xpi` and an `updates.json` beside it. Firefox polls that file about once a day, or as soon as the Bridge is newer, and **Check for Updates** in `about:addons` polls it now. The update then waits for **Update** in the side panel, or the next Firefox start || Browsentic Bridge, from the Mac or Windows app | The app's **Update now** card ([macOS](mac-app.md#updating), [Windows](windows-app.md#updating)) || Browsentic Bridge, from `npx` or `npm` | `browsentic update`, below |-| An unpacked copy | `browsentic update` rewrites the folder, then press ↻ on its card |+| An unpacked copy | `browsentic update` rewrites the folder, then press **Update** in the side panel, or ↻ on its card |```shbrowsentic updatediff --git a/docs/guide/troubleshooting.md b/docs/guide/troubleshooting.mdindex 32340b6..d295c29 100644--- a/docs/guide/troubleshooting.md+++ b/docs/guide/troubleshooting.md@@ -24,7 +24,7 @@ Those three answer most questions. The Bridge's log is at `~/.browsentic/daemon.| --- | --- | --- || The popup says `protocol version mismatch: daemon speaks v20` (any number below 22) | Browsentic Bridge is older than 0.7.14, too old for this extension | Update the Bridge (**Update now** in the app, or `npx browsentic@latest update`), then enter a new pairing code in the popup: after a refusal, this version of the extension waits for one || The popup says `protocol version mismatch: Browsentic Bridge speaks v22 and takes extensions from v22 on` | The extension is older than 0.7.14, usually an unpacked copy that was never updated | Remove it and install the extension from its store, or run `browsentic update` and press ↻ on its card |-| The store copy is a version behind the Bridge | The browser has not checked for updates yet | Nothing breaks meanwhile, because the two work across versions. To update now, turn on Developer mode at `chrome://extensions` and press **Update** |+| The store copy is a version behind the Bridge | The store has not published that version yet, or the browser checked before it did. A browser allows the extension one early check every few hours | Nothing breaks meanwhile, because the two work across versions. Once the browser has the update, the side panel says so above the prompt: press **Update**. To check now, turn on Developer mode at `chrome://extensions` and press **Update** there || `browsentic status` says two copies of Browsentic answer in one browser | An unpacked copy and a store copy are both installed, and both inject into every page | Remove the unpacked copy on the browser's extensions page || Edge will not install from the Chrome Web Store | Edge blocks other stores until you allow them | Install from [Edge Add-ons](https://microsoftedge.microsoft.com/addons/detail/browsentic/cbkjhkgjcpihokphhdkbahilpcjojpdc) instead. Or press **Allow extensions from other stores** in the bar at the top of the store page, confirm, then press **Add to Chrome** || `browsentic setup` keeps waiting for the browser | The extension is installed but not paired yet | Click Browsentic in the toolbar and enter the code `setup` printed. Ctrl-C stops the wait without undoing anything |@@ -46,7 +46,7 @@ Those three answer most questions. The Bridge's log is at `~/.browsentic/daemon.| A scheduled task shows **Missed** | The browser was closed, the computer was asleep, or no Bridge was running at that time | Nothing to fix: the task runs once when they are back, unless it is set to **Skip it**. `browsentic status` shows whether the browser can start the Bridge itself || "Load unpacked" cannot see `~/browsentic` | The browser is a Flatpak or Snap, sandboxed away from your home directory (Snap Chromium is the Ubuntu default) | Install the extension from the Chrome Web Store instead, which needs no folder. Or grant access: `flatpak override --user --filesystem=~/browsentic com.google.Chrome`. Or install where the sandbox can read: `browsentic setup --unpacked --dir ~/snap/chromium/common/browsentic-extension` || The folder picker does not show `~/browsentic` | The folder exists; some pickers open elsewhere by default | macOS: press ⇧⌘G and paste the path. Linux: press Ctrl+L. Windows: paste `%USERPROFILE%\browsentic\extension\chrome-mv3` into the picker's address bar |-| Updated, but an unpacked copy still runs the old build | A browser never reloads an unpacked extension by itself | Press ↻ on the Browsentic card; `browsentic status` shows both versions. A store copy updates itself |+| Updated, but an unpacked copy still runs the old build | A browser never reloads an unpacked extension by itself | Press **Update** in the side panel, or ↻ on the Browsentic card; `browsentic status` shows both versions || `browsentic update` says "already current" forever, and reinstalling still lands on an old build | npm's `npx` cache serves the version it first resolved and never asks the registry again | Run `browsentic update`, which now replaces the cached command before installing. To clear the cache by hand, delete every `~/.npm/_npx/*` directory containing `node_modules/browsentic` || Deleted `~/.browsentic`, but a daemon is still holding port 8765 | The lockfile was deleted, but the process did not notice | Run `browsentic stop`: it probes the ports rather than reading the lockfile, so it finds the process. `browsentic uninstall` does the same as part of its sweep |diff --git a/docs/guide/windows-app.md b/docs/guide/windows-app.mdindex 4209379..399427e 100644--- a/docs/guide/windows-app.md+++ b/docs/guide/windows-app.md@@ -119,8 +119,9 @@ new installer, checks that it carries a signature from Browsentic's release key,the app. The app then replaces the Bridge and restarts it. **Check for updates** on the same cardchecks again immediately.-The extension updates itself from its store. Only an unpacked copy needs ↻ on its card at-`chrome://extensions`, and the app tells you when. The extension and the Bridge do not have to be+The extension downloads its updates from its store, and the side panel offers **Update** once one+is ready. An unpacked copy needs ↻ on its card at `chrome://extensions`, or **Update** in the side+panel, and the app tells you when. The extension and the Bridge do not have to bethe same version.If an update fails, nothing changes, and the card shows the PowerShell line, which installs the samediff --git a/docs/internals/extension.md b/docs/internals/extension.mdindex b9c9474..3bca707 100644--- a/docs/internals/extension.md+++ b/docs/internals/extension.md@@ -511,6 +511,35 @@ scope, not on each move within it, once `load` has fired and the DOM has gone 40mutation (3 s at most). The approved code is wrapped the way the installer wraps it, and it isevaluated once per document.+## Updates wait for the panel++A browser installs a store update only once the extension is idle, and a live Bridge link means it+never is: a worker that stops reconnects within a second. So a downloaded update used to sit, held+by the browser, until the next browser start. Chrome records this in `Secure Preferences` as+`idle_install_info` with `delay_install_reason: 2` (wait for idle).++`extension-update.ts` holds the update for the panel instead. `runtime.onUpdateAvailable` gives the+held version, which goes to `storage.session` under `browsentic/waitingUpdate`. The panel shows the+pill above the prompt while that version is newer than the one running and no run is going.+**Update** calls `runtime.reload()`, which installs the held update at once (Chromium's+`ExtensionRegistrar` finishes a delayed install on reload). A reload closes the side panel and+every extension page, and clears `storage.session`.++A Bridge newer than the extension, read from the welcome, means a release is out, so the background+asks the store now with `runtime.requestUpdateCheck()` rather than waiting for the browser's own+check. Chrome allows one such check every five hours (its backoff starts at the update frequency),+so `browsentic/updateCheckedFor` spends it once per Bridge version. The call resolves as soon as the+store names a version, before the download, so the pill waits for `onUpdateAvailable` rather than+trusting that answer. A Bridge-only release finds nothing and shows nothing.++Firefox applies an update at once when nothing listens to `onUpdateAvailable`, mid-run included.+The listener makes it wait for the pill too.++An unpacked copy has no store. Its files are read from the folder the Bridge rewrites, so on a+newer Bridge the worker fetches `/manifest.json`, which reports the version on disk, not the one+loaded. If that is newer, it is held the same way, and **Update** reloads the extension from the+folder.+---## Nextdiff --git a/src/daemon/self-update.test.ts b/src/daemon/self-update.test.tsindex 3b7f7f8..97208b6 100644--- a/src/daemon/self-update.test.ts+++ b/src/daemon/self-update.test.ts@@ -66,26 +66,6 @@ afterEach(() => {said.mockRestore();});-describe('comparing versions', () => {- const cases: [string, string, boolean][] = [- ['0.7.0', '0.6.2', true],- ['0.6.2', '0.6.2', false],- ['0.6.10', '0.6.9', true],- ['1.0.0', '0.99.99', true],- ['0.6.2', '0.7.0', false],- ['0.7', '0.6.9', true],- ['0.7.0', '0.7.0-rc.1', true],- ['0.7.0-rc.1', '0.7.0', false],- ['0.7.0-rc.2', '0.7.0-rc.1', true],- ['0.7.0-rc.1', '0.6.2', true],- ];- for (const [candidate, current, newer] of cases) {- test(`${candidate} is ${newer ? '' : 'not '}newer than ${current}`, () => {- expect(selfUpdate.isNewer(candidate, current)).toBe(newer);- });- }-});-describe('asking the registry', () => {test('the published version is read from the registry’s latest tag', async () => {expect([await selfUpdate.publishedVersion(), asked[0].url, asked[0].headers.accept]).toEqual([diff --git a/src/daemon/self-update.ts b/src/daemon/self-update.tsindex 071b802..f16ae9a 100644--- a/src/daemon/self-update.ts+++ b/src/daemon/self-update.ts@@ -1,5 +1,6 @@import { spawnSync } from 'node:child_process';import { rmSync } from 'node:fs';+import { isNewer } from '@/lib/version';import { installKind, npxEntries, pinnedVersion } from './npx';const REGISTRY = process.env.BROWSENTIC_REGISTRY ?? 'https://registry.npmjs.org';@@ -19,20 +20,6 @@ export async function publishedVersion(timeoutMs = 4_000): Promise<string | null}}-export function isNewer(candidate: string, current: string): boolean {- const release = (version: string) => version.split('-')[0].split('.').map((part) => Number.parseInt(part, 10) || 0);- const [a, b] = [release(candidate), release(current)];- for (let i = 0; i < 3; i++) if ((a[i] ?? 0) !== (b[i] ?? 0)) return (a[i] ?? 0) > (b[i] ?? 0);-- // Same release: a final beats the prerelease that led to it, and two prereleases fall back- // to string order, which is right for the -rc.1 / -rc.2 shape this project actually uses.- const [pre, currentPre] = [candidate.split('-')[1], current.split('-')[1]];- if (pre === currentPre) return false;- if (!pre) return true;- if (!currentPre) return false;- return pre > currentPre;-}-/*** Replace this CLI with the published one, then re-run the original command under it.*diff --git a/src/extension/components/update-pill.tsx b/src/extension/components/update-pill.tsxnew file mode 100644index 0000000..78d745c--- /dev/null+++ b/src/extension/components/update-pill.tsx@@ -0,0 +1,36 @@+import { RefreshCw, X } from 'lucide-react';++import { cn } from '@/lib/utils';++const PART = 'flex h-full cursor-pointer items-center outline-none transition-colors hover:bg-brand/15 focus-visible:bg-brand/15';++export const UPDATE_RESTARTS = 'Restarts the extension on the new version. This panel closes; open it again to carry on.';++export function UpdatePill({ version, onUpdate, onLater }: { version: string; onUpdate: () => void; onLater: () => void }) {+ return (+ <div className="enters mb-2 flex h-8 items-center overflow-hidden rounded-full border border-brand/45 bg-brand/10">+ <p className="flex min-w-0 flex-1 items-center gap-2 pl-3 text-xs text-ink">+ <RefreshCw className="size-3.5 shrink-0 text-brand" />+ <span className="truncate">Browsentic v{version} is ready</span>+ </p>+ <button+ type="button"+ onClick={onUpdate}+ title={UPDATE_RESTARTS}+ className={cn(PART, 'px-3 text-xs font-medium whitespace-nowrap text-brand')}+ >+ Update+ </button>+ <span aria-hidden="true" className="h-4 w-px bg-brand/30" />+ <button+ type="button"+ onClick={onLater}+ title="Later"+ aria-label="Later: hide the update notice"+ className={cn(PART, 'pr-3 pl-2 text-ink-dim hover:text-ink focus-visible:text-ink')}+ >+ <X className="size-3.5" />+ </button>+ </div>+ );+}diff --git a/src/extension/entrypoints/background.ts b/src/extension/entrypoints/background.tsindex b0ec3bb..ec3fa83 100644--- a/src/extension/entrypoints/background.ts+++ b/src/extension/entrypoints/background.ts@@ -22,6 +22,7 @@ import { serveHandsFree } from '@/lib/bridge/hands-free';import { endHandsFree } from '@/lib/bridge/panel-view';import { serveLaunchers } from '@/lib/bridge/launchers';import { servePreferences } from '@/lib/bridge/preferences';+import { serveExtensionUpdates } from '@/lib/bridge/extension-update';import { isAgentKind } from '@/lib/agents/catalog';import { isPreferenceChange } from '@/lib/settings/preferences';import {@@ -214,6 +215,7 @@ export default defineBackground(() => {serveToast();serveHandsFree();servePreferences();+ serveExtensionUpdates();void syncRail();onWelcome(() => {diff --git a/src/extension/entrypoints/sidepanel/App.tsx b/src/extension/entrypoints/sidepanel/App.tsxindex 3a78724..a723bc0 100644--- a/src/extension/entrypoints/sidepanel/App.tsx+++ b/src/extension/entrypoints/sidepanel/App.tsx@@ -26,6 +26,7 @@ import { SiteMapReview } from '@/extension/components/site-map-review';import { SkillsPanel } from '@/extension/components/skills-panel';import { StarBadge } from '@/extension/components/star-badge';import { TaskPanel } from '@/extension/components/task-panel';+import { UpdatePill } from '@/extension/components/update-pill';import type { TaskSeed } from '@/extension/components/task-editor';import { StatusPill, describeStatus } from '@/extension/components/status-pill';import { Button } from '@/extension/components/ui/button';@@ -49,6 +50,7 @@ import { useStoredSessions } from '@/lib/bridge/use-stored-sessions';import { useStoredSkills } from '@/lib/bridge/use-stored-skills';import { useStoredTasks } from '@/lib/bridge/use-stored-tasks';import { useVoiceComposer } from '@/lib/bridge/use-voice-composer';+import { useWaitingUpdate } from '@/lib/bridge/use-waiting-update';import { useHandsFreeSupported, useVoiceEnabled } from '@/lib/bridge/use-speech';import { cn } from '@/lib/utils';@@ -63,6 +65,7 @@ export default function App() {const daemon = useDaemonState();const run = useRun();const star = useStarNudge(run.completed, run.sessionId, run.running);+ const update = useWaitingUpdate();const [voiceEnabled, setVoiceEnabled] = useVoiceEnabled();const [actionCues, setActionCues] = useActionCues();const handsFree = useHandsFreeSupported();@@ -471,6 +474,9 @@ export default function App() {{tab === 'chat' && (<footer className="shrink-0 border-t border-line p-3">+ {update.version && !run.running && (+ <UpdatePill version={update.version} onUpdate={update.restart} onLater={update.later} />+ )}{blockedHere && <BlockedSiteNote pattern={blockedHere} />}{run.toolOffer && (<KeepToolPromptdiff --git a/src/lib/bridge/extension-update.test.ts b/src/lib/bridge/extension-update.test.tsnew file mode 100644index 0000000..9b8501f--- /dev/null+++ b/src/lib/bridge/extension-update.test.ts@@ -0,0 +1,81 @@+import { beforeEach, describe, expect, it, vi } from 'vitest';+import { fakeBrowser } from 'wxt/testing';+import { WAITING_UPDATE_KEY, asWaitingVersion, followBridge, serveExtensionUpdates } from './extension-update';++const RUNNING = '0.8.2';++let installType: string;+let onDisk: string;+const checkForUpdate = vi.fn();++const waiting = async () => (await fakeBrowser.storage.session.get(WAITING_UPDATE_KEY))[WAITING_UPDATE_KEY];++beforeEach(() => {+ fakeBrowser.reset();+ installType = 'normal';+ onDisk = RUNNING;+ checkForUpdate.mockReset().mockResolvedValue({ status: 'no_update' });+ vi.spyOn(fakeBrowser.runtime, 'getManifest').mockReturnValue({ version: RUNNING } as never);+ vi.spyOn(fakeBrowser.runtime, 'requestUpdateCheck').mockImplementation(checkForUpdate);+ vi.spyOn(fakeBrowser.management, 'getSelf').mockImplementation(async () => ({ installType }) as never);+ vi.stubGlobal('fetch', async () => new Response(JSON.stringify({ version: onDisk })));+});++describe('an update the browser has downloaded', () => {+ it('is held for the panel instead of waiting for the extension to go idle', async () => {+ serveExtensionUpdates();+ await fakeBrowser.runtime.onUpdateAvailable.trigger({ version: '0.8.3' });+ await vi.waitFor(async () => expect(await waiting()).toBe('0.8.3'));+ });++ it('stops being offered once the extension runs it, or anything newer', () => {+ expect([asWaitingVersion('0.8.3'), asWaitingVersion('0.8.2'), asWaitingVersion('0.8.1'), asWaitingVersion(undefined)]).toEqual([+ '0.8.3',+ null,+ null,+ null,+ ]);+ });+});++describe('a store copy following a newer Bridge', () => {+ it('asks the store as soon as the Bridge says it is newer', async () => {+ await followBridge('0.8.3');+ expect(checkForUpdate).toHaveBeenCalledOnce();+ });++ it('spends the browser’s one check in a few hours only once for each Bridge version', async () => {+ await followBridge('0.8.3');+ await followBridge('0.8.3');+ await followBridge('0.8.4');+ expect(checkForUpdate).toHaveBeenCalledTimes(2);+ });++ it('leaves the store alone while the Bridge is the same version or older', async () => {+ await followBridge('0.8.2');+ await followBridge('0.8.1');+ expect(checkForUpdate).not.toHaveBeenCalled();+ });++ it('survives a browser that will not check at all', async () => {+ checkForUpdate.mockRejectedValue(new Error('updates disabled'));+ await expect(followBridge('0.8.3')).resolves.toBeUndefined();+ });+});++describe('an unpacked copy following a newer Bridge', () => {+ beforeEach(() => {+ installType = 'development';+ });++ it('offers a reload once the Bridge has rewritten its folder', async () => {+ onDisk = '0.8.3';+ await followBridge('0.8.3');+ expect([await waiting(), checkForUpdate.mock.calls.length]).toEqual(['0.8.3', 0]);+ });++ it('offers nothing while the folder still holds the running build', async () => {+ await followBridge('0.8.3');+ expect(await waiting()).toBeUndefined();+ });+});diff --git a/src/lib/bridge/extension-update.ts b/src/lib/bridge/extension-update.tsnew file mode 100644index 0000000..0a5dc47--- /dev/null+++ b/src/lib/bridge/extension-update.ts@@ -0,0 +1,54 @@+import { browser } from 'wxt/browser';+import { isNewer } from '@/lib/version';+import { onWelcome } from './socket';++export const WAITING_UPDATE_KEY = 'browsentic/waitingUpdate';++const CHECKED_FOR_KEY = 'browsentic/updateCheckedFor';++export const runningVersion = (): string => browser.runtime.getManifest().version;++/** The version a restart would run, as long as it is newer than the one running now. */+export const asWaitingVersion = (value: unknown, running = runningVersion()): string | null =>+ typeof value === 'string' && isNewer(value, running) ? value : null;++const hold = (version: string) => browser.storage.session.set({ [WAITING_UPDATE_KEY]: version });++/**+ * A browser installs a store update only once the extension goes idle, and a live Bridge link keeps it+ * from ever going idle, so a downloaded update is held for the panel to restart into. A Bridge newer+ * than this extension is the sign a release is out, so it asks the store now rather than on the+ * browser's own timer.+ */+export function serveExtensionUpdates(): void {+ browser.runtime.onUpdateAvailable.addListener(({ version }) => void hold(version));+ onWelcome((daemonVersion) => void followBridge(daemonVersion));+}++export async function followBridge(daemonVersion: string): Promise<void> {+ if (!isNewer(daemonVersion, runningVersion())) return;+ const { installType } = await browser.management.getSelf();+ if (installType === 'development') {+ const rebuilt = asWaitingVersion(await unpackedVersion());+ if (rebuilt) await hold(rebuilt);+ return;+ }+ // The browser grants one check every few hours, so each newer Bridge spends it once.+ const checked = await browser.storage.session.get(CHECKED_FOR_KEY);+ if (checked[CHECKED_FOR_KEY] === daemonVersion) return;+ await browser.storage.session.set({ [CHECKED_FOR_KEY]: daemonVersion });+ await browser.runtime.requestUpdateCheck().catch(() => undefined);+}++/** An unpacked copy reads its files from the folder the Bridge rewrites, so the manifest there names the build a reload loads. */+async function unpackedVersion(): Promise<string | null> {+ try {+ const response = await fetch('/manifest.json', { cache: 'no-store' });+ const { version } = (await response.json()) as { version?: unknown };+ return typeof version === 'string' ? version : null;+ } catch {+ return null;+ }+}++export const restartIntoUpdate = (): void => browser.runtime.reload();diff --git a/src/lib/bridge/socket.ts b/src/lib/bridge/socket.tsindex 4c2fdcb..e60927f 100644--- a/src/lib/bridge/socket.ts+++ b/src/lib/bridge/socket.ts@@ -92,7 +92,7 @@ let connecting: Promise<void> | null = null;let reconnectTimer: ReturnType<typeof setTimeout> | undefined;let stableTimer: ReturnType<typeof setTimeout> | undefined;let runListener: ((runId: string, event: RunEvent) => void) | null = null;-const welcomeListeners = new Set<() => void>();+const welcomeListeners = new Set<(daemonVersion: string) => void>();let draftListener: ((runId: string, draft: SiteMapDraft) => void) | null = null;let taskRunner: ((order: TaskOrder) => Promise<ActionResult>) | null = null;let preferencesListener: ((preferences: Preferences) => void) | null = null;@@ -113,7 +113,7 @@ export function onRunEvent(listener: (runId: string, event: RunEvent) => void):runListener = listener;}-export function onWelcome(listener: () => void): void {+export function onWelcome(listener: (daemonVersion: string) => void): void {welcomeListeners.add(listener);}@@ -603,7 +603,7 @@ async function handle(ws: WebSocket, raw: string, attempt: Attempt): Promise<voierror: undefined,lastChangeAt: Date.now(),});- for (const listener of welcomeListeners) listener();+ for (const listener of welcomeListeners) listener(frame.daemonVersion);return;}diff --git a/src/lib/bridge/use-waiting-update.ts b/src/lib/bridge/use-waiting-update.tsnew file mode 100644index 0000000..e4b29ef--- /dev/null+++ b/src/lib/bridge/use-waiting-update.ts@@ -0,0 +1,36 @@+import { useEffect, useState } from 'react';+import { browser } from 'wxt/browser';+import { WAITING_UPDATE_KEY, asWaitingVersion, restartIntoUpdate } from './extension-update';++export interface WaitingUpdateView {+ version: string | null;+ restart: () => void;+ later: () => void;+}++/** The update the browser holds for this extension. Later hides it until the panel opens again or a newer one arrives. */+export function useWaitingUpdate(): WaitingUpdateView {+ const [waiting, setWaiting] = useState<string | null>(null);+ const [deferred, setDeferred] = useState<string | null>(null);++ useEffect(() => {+ let live = true;+ void browser.storage.session.get(WAITING_UPDATE_KEY).then((stored) => {+ if (live) setWaiting(asWaitingVersion(stored[WAITING_UPDATE_KEY]));+ });+ const listener = (changes: Record<string, { newValue?: unknown }>) => {+ if (WAITING_UPDATE_KEY in changes) setWaiting(asWaitingVersion(changes[WAITING_UPDATE_KEY].newValue));+ };+ browser.storage.session.onChanged.addListener(listener);+ return () => {+ live = false;+ browser.storage.session.onChanged.removeListener(listener);+ };+ }, []);++ return {+ version: waiting !== deferred ? waiting : null,+ restart: restartIntoUpdate,+ later: () => setDeferred(waiting),+ };+}diff --git a/src/lib/version.test.ts b/src/lib/version.test.tsnew file mode 100644index 0000000..bec402d--- /dev/null+++ b/src/lib/version.test.ts@@ -0,0 +1,22 @@+import { describe, expect, test } from 'vitest';+import { isNewer } from './version';++describe('comparing versions', () => {+ const cases: [string, string, boolean][] = [+ ['0.7.0', '0.6.2', true],+ ['0.6.2', '0.6.2', false],+ ['0.6.10', '0.6.9', true],+ ['1.0.0', '0.99.99', true],+ ['0.6.2', '0.7.0', false],+ ['0.7', '0.6.9', true],+ ['0.7.0', '0.7.0-rc.1', true],+ ['0.7.0-rc.1', '0.7.0', false],+ ['0.7.0-rc.2', '0.7.0-rc.1', true],+ ['0.7.0-rc.1', '0.6.2', true],+ ];+ for (const [candidate, current, newer] of cases) {+ test(`${candidate} is ${newer ? '' : 'not '}newer than ${current}`, () => {+ expect(isNewer(candidate, current)).toBe(newer);+ });+ }+});diff --git a/src/lib/version.ts b/src/lib/version.tsnew file mode 100644index 0000000..0aa6ba6--- /dev/null+++ b/src/lib/version.ts@@ -0,0 +1,13 @@+export function isNewer(candidate: string, current: string): boolean {+ const release = (version: string) => version.split('-')[0].split('.').map((part) => Number.parseInt(part, 10) || 0);+ const [a, b] = [release(candidate), release(current)];+ for (let i = 0; i < 3; i++) if ((a[i] ?? 0) !== (b[i] ?? 0)) return (a[i] ?? 0) > (b[i] ?? 0);++ // Same release: a final beats the prerelease that led to it, and two prereleases fall back+ // to string order, which is right for the -rc.1 / -rc.2 shape this project actually uses.+ const [pre, currentPre] = [candidate.split('-')[1], current.split('-')[1]];+ if (pre === currentPre) return false;+ if (!pre) return true;+ if (!currentPre) return false;+ return pre > currentPre;+}