Manifest V3 Chrome Extensions: Changes & Migration
In this article
Manifest V3 (MV3) is the current Chrome extension platform, replacing Manifest V2 (MV2) with key changes to background pages, security, and network request handling. To migrate, you must update your manifest.json, replace persistent background pages with service workers, and move from blocking webRequest to declarativeNetRequest.
Why Manifest V3 Exists
Google introduced MV3 to improve privacy, security, and performance. MV2 extensions could run persistent background pages that consumed memory and had broad access to user data. MV3 shifts to event-driven service workers that are unloaded when idle, reducing resource usage. It also restricts remote code execution and requires stricter permission justifications, aiming to reduce malicious extensions.
Key Changes in Manifest V3
- Background pages replaced by service workers: Persistent background pages are gone; service workers are non-persistent and must be registered in the manifest.
- Network request blocking via declarativeNetRequest: The blocking capability of webRequest is limited to observation; actual blocking must use the declarativeNetRequest API with static or dynamic rules.
- Remote code execution prohibited: Extensions cannot load and execute code from remote servers; all code must be bundled in the extension package.
- Permissions changes: Host permissions are separated from other permissions, and some permissions like 'unlimitedStorage' no longer require a warning.
- Content security policy (CSP) tightened: MV3 requires a stricter CSP, disallowing 'unsafe-eval' and remote script sources.
- Minimum Chrome version: MV3 requires Chrome 88 or later.
How to Migrate from MV2 to MV3
Migration involves several steps, depending on your extension's features. Here is a general checklist:
- Update manifest.json: Change the manifest version to 3, and adjust the background declaration to use a service worker (e.g.,
"background": {"service_worker": "background.js"}). - Replace background page with a service worker: Move your background logic into a service worker script. Ensure you use
chrome.runtime.onInstalledfor initialization and avoid long-running tasks. - Convert webRequest blocking to declarativeNetRequest: If you used
chrome.webRequest.onBeforeRequestwithblocking: true, switch tochrome.declarativeNetRequestwith rules. For simple URL filtering, define rules in a JSON file; for dynamic rules, useupdateDynamicRules. - Remove remote code: Move any code fetched from remote servers into your extension package. If you used
eval()ornew Function(), refactor to avoid them. - Update permissions: Review your permissions. Host permissions are now declared under
host_permissionsseparately from other permissions. Some permissions may have changed names or warnings. - Adjust content security policy: Set a CSP that meets MV3 requirements, typically
"content_security_policy": {"extension_pages": "script-src 'self'; object-src 'self'"}. - Test thoroughly: Use Chrome's extension debugging tools to test service worker lifecycle, event handling, and rule behavior.
Common Migration Challenges
Many developers struggle with the service worker lifecycle. Service workers are terminated after a few seconds of inactivity, so you cannot rely on global state. Use chrome.storage or IndexedDB to persist data. Another challenge is the declarativeNetRequest rule limit: static rules are limited to 30,000, and dynamic rules to 5,000. If you need complex blocking logic, you may need to split rules or use a service worker to update dynamic rules.
Another issue is that some APIs like chrome.webRequest still exist but only for observation. If you need to block requests, you must use declarativeNetRequest. Also, note that chrome.browserAction is now chrome.action; you must migrate to the new API.
Comparison: MV2 vs MV3
| Aspect | MV2 | MV3 |
|---|---|---|
| Background pages | Persistent or event pages | Service workers (non-persistent) |
| Network blocking | webRequest with blocking | declarativeNetRequest |
| Remote code | Allowed with CSP | Prohibited |
| Permissions | Combined | Separated host_permissions |
| Minimum Chrome | Chrome 22+ | Chrome 88+ |
Impact on Users and Developers
For users, MV3 promises better performance and privacy, but some ad blockers have faced limitations because of the rule caps and removal of blocking webRequest. For developers, the migration requires learning new APIs and adjusting architecture. Many popular extensions have already migrated, but some features like content script injection have become more complex. The Chrome Web Store stopped accepting new MV2 extensions in 2021, and MV2 extensions will be disabled for all users in 2024 (with enterprise exceptions).
Frequently Asked Questions
Will my existing MV2 extension stop working?
Yes, Chrome will disable MV2 extensions after the official phase-out. The timeline: Chrome 88+ supports MV3; MV2 extensions are being phased out starting 2023, with full disablement in 2024. You need to migrate before then.
Can I still use webRequest to block requests?
No, blocking is not allowed in MV3. You can only observe requests with webRequest. For blocking, you must use declarativeNetRequest.
How do I persist data in a service worker?
Use chrome.storage (local or session) or IndexedDB. Service workers are terminated after a few seconds of inactivity, so in-memory variables are lost.
What are the rule limits for declarativeNetRequest?
Static rulesets are limited to 30,000 rules per extension, and dynamic rules to 5,000. There is also a total limit of 50,000 rules across all extensions for free users.
Can I use external libraries like jQuery in MV3?
Yes, but they must be bundled locally. You cannot load them from a CDN because remote code execution is prohibited.
Is MV3 more secure?
MV3 reduces the attack surface by disallowing remote code and limiting background execution, but it doesn't make extensions inherently secure. Malicious extensions can still abuse permissions.