{
  "id": 22881084,
  "title": "Writing a Cookie AutoDelete-Compatible Domain Rule Parser in Vanilla JS",
  "url": "https://urgent.news/2026/12/01/writing-a-cookie-autodelete-compatible-domain-rule-parser-in-vanilla",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-12-01T01:58:30.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/larkandlever/writing-a-cookie-autodelete-compatible-domain-rule-parser-in-vanilla-js-9ld"
  },
  "original_language": null,
  "account": "When users switch away from older Manifest V2 cookie managers, the most demanding part isn't implementing chrome.cookies.remove() — it's respecting the keep-list rules end-users have painstakingly crafted over time. If a user marked *.github.com as WHITE, accounts.google.com as GREY (clear upon browser restart, but retained while open), or created a regex rule /^staging./ for the Cookie AutoDelete (CAD) extension, improperly matching rules could silently log users out of all their sessions. To address these challenges, the team behind Lark Cookie Sweep (MIT licensed on GitHub, available on Microsoft Edge Add-ons) isolated all rule parsing and import/export logic into two lightweight, zero-dependency ES modules (src/lib/rules.js and src/lib/cad-import.js). This allows thorough unit testing of edge cases in Node before integrating with a browser.\n\nTo ensure consistent rule application regardless of input format, the code normalizes hostnames before performing matching. The normalizeHost() function takes a host string, trims whitespace, converts it to lowercase, and removes leading/trailing periods and whitespace. It also handles IPv6 literal addresses and removes the www. prefix. This ensures that a rule specifying example.com will also match www.example.com, eliminating the need for users to maintain duplicate entries.\n\nCAD syntax supports three types of rules: exact hostnames (example.com), wildcard hosts (* example.com), and regular expressions (/regex/). The globToRegExpSource() function translates wildcard expressions into regular expressions that can be compiled and tested against hostnames. The function handles cases where the wildcard appears at the beginning or end of the pattern, as well as cases where the pattern includes literal asterisks which should be treated as wildcards. By properly escaping special characters and constructing a regular expression that matches the intended pattern, this function allows users to define complex matching rules while maintaining deterministic behavior.\n\nAdditionally, the code provides functions for mapping Chrome, Edge, and Firefox cookie storage identifiers to a consistent \"storeId\" format. Chrome and Edge assign \"0\" for the default profile and \"1\" for Incognito sessions, while Firefox uses different identifiers for different types of accounts and containers. The storeKey() function translates these identifiers into a simpler \"default\" value for most cases, ensuring that the main keep-list rules apply consistently across all sessions while still allowing per-store protection for more granular control.",
  "summary": "When users migrate away from legacy Manifest V2 cookie managers, the hardest part isn't writing chrome.cookies.remove() — it's honoring the keep-list rules they've spent years curating. If someone exported *.github.com as WHITE , accounts.google.com as GREY (clear on browser restart, keep while open), or /^staging\\./ as a regex rule in Cookie AutoDelete (CAD) , breaking subtle matching semantics…",
  "summary_source": "publisher",
  "key_points": [],
  "editors_take": null,
  "opinion": false,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "machine_translated": false,
  "ai_generated": true,
  "disclaimer": "Accounts, briefs, key points, the editor’s take and translations are written by software from other outlets’ reporting and may contain errors. A summary whose summary_source is \"publisher\" is the outlet’s own feed text. Always check the linked original."
}