deniz.in

Markets

Weather

Loading weather

· via dev.to (home feed)

MV3 replacement for Cookie AutoDelete tackles ephemeral workers and CHIPS cookies

After Google's MV2 shutdown cost Cookie AutoDelete its 200,000 Chrome users, a developer has shipped an MV3 replacement that solves ephemeral service workers, cookie-jar scoping, and CHIPS partitioned cookies.

MV3 replacement for Cookie AutoDelete tackles ephemeral workers and CHIPS cookies

What happened

Google's completed Manifest V2 shutdown in Chrome swept away one of the more widely used privacy extensions: Cookie AutoDelete. According to an engineering write-up on dev.to by the developer of a new replacement, the extension had more than 200,000 Chrome users before removal, and over 160,000 Firefox users are still running a build from 2022.

That developer, publishing as larkandlever, has now released Lark Cookie Sweep — an MIT-licensed, zero-dependency Manifest V3 replacement targeting Chrome, Edge, and Firefox. The post documents five concrete problems solved during the port, and they generalize to any MV2 extension that depends on long-lived background state.

The ephemeral service worker problem

Old-style MV2 cookie cleaners ran a persistent background page that held Redux state, a map of open tabs, and queued setTimeout calls in memory. MV3 replaces this with a service worker that Chrome may terminate roughly 30 seconds after its last event, which directly breaks the cleaner's core feature: the configurable grace period after a tab closes, so an accidental close followed by Ctrl+Shift+T does not wipe the user's session.

The replacement uses a hybrid schedule, per the post. A setTimeout fires the cleanup quickly when the worker stays warm, while a chrome.alarms entry serves as a persistent fallback that survives worker suspension. Because Chrome enforces a minimum of roughly 30 seconds on alarms, the backup alarm is set at whichever is larger — the grace period or 30 seconds — plus one second. Sweeps never trust cached tab state across restarts; each one re-queries chrome.tabs and chrome.cookies under a lock that serializes concurrent runs.

Separating cookie jars from rule scope

Supporting incognito windows and Firefox Multi-Account Containers exposes a subtle distinction, the post explains. Open-tab protection must be scoped per raw cookie jar — normal, incognito, and each firefox-container store — so having example.com open in a normal tab must not protect the same site's cookies in a closed incognito window. Keep-list rules, by contrast, deliberately share a single default scope between normal and incognito stores to match Cookie AutoDelete's behavior, while containers keep their own scopes.

The author isolates this logic in a pure planner module that can be unit-tested in Node.js without mocking Chrome APIs.

Handling CHIPS-partitioned cookies

Modern browsers increasingly store third-party cookies with a partitionKey containing a topLevelSite, under the CHIPS scheme. The write-up flags two pitfalls for naive cleaners. First, calling chrome.cookies.getAll without an empty partitionKey filter can miss partitioned cookies depending on browser version, so a fallback query is needed to catch both partitioned and unpartitioned entries. Second, chrome.cookies.remove requires forwarding the exact partitionKey object to delete a partitioned cookie — and while the top-level site is still open in a tab, that partitioned cookie deserves open-tab protection just like the first-party cookies of that tab.

Importing legacy Expression backups

To let users switch tools without retyping dozens of whitelisted domains, the extension imports Cookie AutoDelete's Expressions.json format directly. Three details keep imported lists behaving identically, according to the post: stripping leading www. and www2. from both rules and hostnames before matching; treating *.example.com as matching the bare domain and every subdomain while example.com matches only the exact host; and resolving conflicts so exact rules beat wildcards and regex, and whitelist entries beat greylist entries, so cookies users asked to keep are never accidentally deleted.

Rendering imported rules also avoids innerHTML entirely, using a small createElement-based helper instead. That removes the possibility of XSS from malformed imports and brings web-ext lint results down to zero errors and zero warnings.

Tested against real browsers

Unit tests cover the planner and expression parser, with 24 of 24 passing under node --test, per the post. Beyond that, end-to-end scripts exercise real browsers. A Chrome run driven by Puppeteer with extension support enabled uses a local HTTP server setting cookies on loopback hosts, and 15 checks verify open-tab protection, tab-close cleanup, greylist survival combined with a browser-start sweep, the Expressions.json upload flow, and toolbar badge updates. A Firefox run via WebDriver BiDi temporarily installs the packaged build and asserts on the actual Cookie header received by the local server, passing 7 of 7 checks. The MIT source and v1.0.0 packages are available on GitHub.

Why it matters

The MV2 shutdown did not just deprecate an API; it invalidated an entire architecture built on permanent background pages, and privacy tools that depend on timed cleanup were hit hardest. This port demonstrates a workable pattern for the MV3 world: precise timers paired with durable alarms, fresh queries instead of in-memory caches, and explicit scoping rules for the multiplying number of cookie jars — normal, incognito, containers, and now CHIPS partitions. Those techniques are reusable by any extension developer facing the same migration. And with Cookie AutoDelete's Firefox install base still on a 2022 build, per the post, a maintained, cross-browser, MIT-licensed replacement with one-click import substantially lowers the switching cost for stranded users.

  • #chrome-extensions
  • #manifest-v3
  • #cookies
  • #privacy
  • #open-source

Related posts