Understanding the Chrome Extension Manifest V3
A deep dive into Chrome Extension Manifest V3 and how to migrate from V2.
javascript browser-extension chrome
What Changed in Manifest V3?
Manifest V3 is the latest version of the Chrome Extensions platform. It introduces significant changes focused on security, privacy, and performance.
Key Differences
Background Scripts → Service Workers
The biggest change: persistent background pages are gone. They’re replaced by service workers which are event-driven and terminate when idle.
// manifest.json (V3){ "manifest_version": 3, "background": { "service_worker": "background.js", "type": "module" }}Content Security Policy
Inline scripts are no longer allowed. You must use external script files:
{ "content_security_policy": { "extension_pages": "script-src 'self'; object-src 'self'" }}declarativeNetRequest
The webRequest API is replaced by declarativeNetRequest for most use cases:
// Block ads declarativelychrome.declarativeNetRequest.updateDynamicRules({ removeRuleIds: [1], addRules: [{ id: 1, priority: 1, action: { type: "block" }, condition: { urlFilter: "||ads.example.com", resourceTypes: ["script", "image"] } }]});Migrating Your Extension
- Update
manifest_versionto 3 - Convert background scripts to service workers
- Replace
webRequestwithdeclarativeNetRequest - Move inline scripts to external files
- Update permission declarations
My Experience Migrating WhatsApp-Toggle
When I migrated my WhatsApp-Toggle extension, the main challenge was handling state in the service worker since it can terminate at any time.
// Use chrome.storage for persistent statechrome.storage.local.get(["enabled"], (result) => { if (result.enabled) { activateToggle(); }});Tips
- Use
chrome.storagefor anything that needs to persist - Keep your service worker lean — it should wake up, do work, and sleep
- Test with DevTools > Application > Service Workers
- Use
chrome.runtime.sendMessagefor component communication
Resources
The transition to MV3 is mandatory now. Start migrating early to avoid last-minute issues.