How to understand a Chrome extension (Manifest V3) codebase
A browser extension is several scripts running in different contexts: a background service worker, content scripts injected into web pages, and extension pages such as the popup. They can't share variables, so they talk through `chrome.runtime` messages. The manifest is the map.
How to tell it's Chrome extension (Manifest V3)
manifest.jsonwith"manifest_version": 3chrome.runtime.sendMessage,chrome.runtime.onMessageandchrome.storagecalls- Frameworks such as WXT or Plasmo, which generate the manifest from config
Where things usually live
- manifest.json
- Permissions, host permissions, background worker, content script matches, popup.
- background.ts or service-worker.ts
- Event-driven background logic.
- content/ or content-scripts/
- Scripts injected into matching pages, with access to the page's DOM.
- popup/
- The toolbar popup UI.
- options/
- Settings page.
Conventions, not rules. Real projects rename and move things, so confirm against the repository.
Where to start reading
manifest.json, to see what runs where and with which permissions- Message listeners in the background worker
- Content scripts and the URLs they match
How a request moves through the code
- The browser loads the service worker when an event it listens for fires.
- On matching pages, content scripts run and read or change the DOM.
- A content script sends a message; the background worker receives it in
onMessage. - The worker calls extension APIs or the network and replies.
- State that must survive is kept in
chrome.storage, not in variables.
Questions to ask about the repository
- What does each permission in the manifest allow, and is each one needed?
- List every message type and its sender and receiver.
- Which pages do content scripts run on, and what do they change?
What trips people up
- The MV3 service worker shuts down when idle, so global variables are lost; this causes many intermittent bugs.
- Content scripts run in an isolated world: they share the DOM with the page but not its JavaScript variables.