manifest.json is the root of every browser extension. It declares what the extension is called, what code runs where and what it can access. Chrome, Edge, Brave and Opera all run Manifest V3 now.
The required three
{ "manifest_version": 3, "name": "JSON Peek", "version": "1.0.0" }
version is one to four dot-separated integers. It is not full semver, so 1.0.0-beta is rejected.
Background: a service worker, not a page
"background": { "service_worker": "background.js", "type": "module" }
MV3 replaced always-on background pages with an event-driven service worker. Chrome stops it when idle, so:
- keep state in
chrome.storage, not global variables; - register listeners (
chrome.runtime.onMessage,chrome.alarms.onAlarm) at the top level; - use
chrome.alarmsinstead of longsetTimeouttimers.
The toolbar button: action
"action": { "default_popup": "popup.html", "default_title": "JSON Peek" }
action replaces MV2's browser_action and page_action.
Content scripts
"content_scripts": [
{ "matches": ["https://api.example.com/*"], "js": ["content.js"], "run_at": "document_idle" }
]
Content scripts run inside matching pages, in an isolated world. To inject only on demand, use chrome.scripting.executeScript with the scripting permission instead.
Permissions without scary warnings
"permissions": ["activeTab", "storage", "scripting"],
"optional_host_permissions": ["https://*/*"]
- activeTab grants temporary access to the current tab only when the user clicks your action. No install warning.
- host_permissions grants standing access to sites. Every pattern adds to the warning, and
<all_urls>triggers the strongest one. - optional_host_permissions lets you ask at runtime, when the user needs the feature.
Migrating from V2
| Manifest V2 | Manifest V3 |
|---|---|
"background": { "scripts": [...] } | "background": { "service_worker": "..." } |
browser_action / page_action | action |
hosts inside permissions | host_permissions |
blocking webRequest | declarativeNetRequest |
chrome.tabs.executeScript | chrome.scripting.executeScript |
| remotely hosted code | forbidden: bundle everything |
web_accessible_resources: [...] | objects with resources + matches |
Security notes
- MV3 forbids remote code. Every script ships in the package and is reviewed with it.
- Treat messages from content scripts as untrusted. A malicious page can talk to your content script.
- Request the narrowest host patterns you can, and drop permissions you no longer use.
Open the Manifest V3 template and ask the workspace to "replace host_permissions with activeTab" or "add an options page", then review the diff.