Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

fix(browser-extension): refresh static assets in watch builds (#834)

Rudy Mizrahi Celekli9d39fd6ab0d1
diff --git a/browser-extension/README.md b/browser-extension/README.md
index 3ed6c23c..fae47b21 100644
--- a/browser-extension/README.md
+++ b/browser-extension/README.md
@@ -92,6 +92,9 @@ npm run record:fixtures -- --site claude|chatgpt --name <n> # capture a fixtur
npm run report # open the last HTML report
```
+Watch mode also refreshes the manifest, popup/options HTML and icons. Reload the unpacked
+extension to apply manifest changes; reload an extension page to see its updated markup.
+
## Loading the extension in your own browser
One build serves every Chromium browser: Chrome, Edge, Brave, Opera, Vivaldi and Arc. The
diff --git a/browser-extension/esbuild.config.mjs b/browser-extension/esbuild.config.mjs
index e6c9c1a5..09a41d86 100644
--- a/browser-extension/esbuild.config.mjs
+++ b/browser-extension/esbuild.config.mjs
@@ -1,4 +1,5 @@
import * as esbuild from 'esbuild';
+import { watch as watchFiles } from 'node:fs';
import { cp, mkdir, readFile, rm, writeFile } from 'node:fs/promises';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
@@ -54,7 +55,8 @@ async function copyStatic() {
for (const surface of ['popup', 'options']) {
await cp(path.join(src, surface, `${surface}.html`), path.join(dist, `${surface}.html`));
}
- // icons/ is optional; copy if present.
+ // icons/ is optional; remove stale output when a watched asset disappears.
+ await rm(path.join(dist, 'icons'), { recursive: true, force: true });
await cp(path.join(src, 'icons'), path.join(dist, 'icons'), { recursive: true }).catch(() => {});
}
@@ -78,6 +80,18 @@ async function run() {
const ctx = await esbuild.context(buildOptions);
await copyStatic();
await ctx.watch();
+ // esbuild watches its module graph, not the files copied into the bundle.
+ // Keep static refreshes serialized so a burst of edits cannot race writes.
+ let staticRefresh = Promise.resolve();
+ watchFiles(src, { recursive: true }, (_event, filename) => {
+ const name = filename?.replaceAll('\\', '/');
+ if (name && name !== 'manifest.json' && name !== 'popup/popup.html' &&
+ name !== 'options/options.html' && name !== 'icons' && !name.startsWith('icons/')) return;
+ staticRefresh = staticRefresh.then(async () => {
+ await copyStatic();
+ console.log('[esbuild] static assets refreshed');
+ }).catch((err) => console.error(err));
+ });
console.log('[esbuild] watching…');
} else {
await esbuild.build(buildOptions);