Unit-testing pure planner functions with mocked chrome.* APIs only proves your logic matches your assumptions. The real bugs in Manifest V3 extensions happen at the browser boundary: onInstalled racing with test setup, ephemeral service workers shutting down between tab closes, and subtle differences between Chrome's CDP and Firefox's WebDriver BiDi.

While building Lark Cookie Sweep (an open-source MV3 successor to Cookie AutoDelete, MIT on GitHub, live on Microsoft Edge Add-ons) and Lark Markdown Clipper, we wrote zero-framework E2E runners in plain Node.js using puppeteer-core and Node's built-in http module.

Here are the patterns that made both suites fast and reliable.

1. Test Real Cookie & Host Isolation With Two Local Origins

Instead of pointing tests at external websites, spin up a tiny node:http server on 127.0.0.1:0 and hit it through two distinct origins pointing to the same port:

  • http://127.0.0.1:<PORT> (unlisted — cookies must be deleted after tab close)
  • http://localhost:<PORT> (whitelisted — cookies must survive)
const server = http.createServer((req, res) => { if (req.url.startsWith("/set")) { res.setHeader("Set-Cookie", [ "sid=abc; Path=/; Max-Age=3600", "pref=dark; Path=/; Max-Age=3600", ]); } res.setHeader("Content-Type", "text/plain; charset=utf-8"); res.end(req.url.startsWith("/echo") ? `COOKIE=${req.headers.cookie || ""}` : "ok"); }); 

That gives you deterministic real-browser Set-Cookie headers and server-observed Cookie echo checks in under 50 ms, completely offline.

2. Chrome MV3: enableExtensions: true and Waiting for onInstalled

In Chrome with puppeteer-core, launch with pipe: true and enableExtensions: true, then load your built dist/chrome folder via browser.installExtension(EXT):

const browser = await puppeteer.launch({ executablePath: CHROME, headless: "new", pipe: true, enableExtensions: true, userDataDir: profile, args: ["--no-first-run", "--no-default-browser-check"], }); const extId = await browser.installExtension(EXT); const swTarget = await browser.waitForTarget( (t) => t.type() === "service_worker" && t.url().startsWith(`chrome-extension://${extId}/`), { timeout: 15000 } ); const sw = await swTarget.worker(); 

Watch out for the onInstalled race: if your test immediately writes test settings to chrome.storage.local right after installExtension(), the extension's runtime.onInstalled handler may still be persisting default settings asynchronously and overwrite your test config. Poll chrome.storage.local.get("settings") inside sw.evaluate(...) until defaults exist before mutating storage for the test scenario.

3. Firefox BiDi: Work Around Unreachable moz-extension:// Pages

Firefox's WebDriver BiDi implementation lets puppeteer-core install a temporary unsigned add-on directly (browser: "firefox" + browser.installExtension(EXT)), returning the extension's gecko.id.

However, unlike Chrome's service worker target, Firefox's remote agent does not expose moz-extension:// contexts for arbitrary evaluate() calls. To test default background behavior cleanly:

  1. Copy dist/firefox into a temp directory.
  2. Patch only the default config constant (e.g., flipping autoClean: true and delaySec: 1).
  3. Verify behavior strictly from the web page / HTTP server side via /echo (COOKIE=sid=abc vs COOKIE=).

(Bonus Windows gotcha: on Node 22 with non-ASCII workspace paths on Windows, fs.cpSync can crash with 0xC0000409. Writing a 6-line recursive readdirSync + readFileSync/writeFileSync helper avoids the native path bug completely.)

4. Keep Core Logic Pure So E2E Only Tests Browser Wiring

Because our rule parser, expression matcher (*.domain.com, exact host, /regex/), and sweep planner live in dependency-free ES modules tested by node --test, the E2E scripts stay under 170 lines and focus purely on real chrome.tabs, chrome.cookies, and storage events.

If you want to inspect the full Chrome and Firefox E2E harnesses, they're MIT-licensed inside larkandlever/cookie-sweep, and you can also check out our free online developer tools on larkandlever.github.io.