Skip to content

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.json with "manifest_version": 3
  • chrome.runtime.sendMessage, chrome.runtime.onMessage and chrome.storage calls
  • 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

  1. manifest.json, to see what runs where and with which permissions
  2. Message listeners in the background worker
  3. Content scripts and the URLs they match

How a request moves through the code

  1. 1The browser loads the service worker when an event it listens for fires.
  2. 2On matching pages, content scripts run and read or change the DOM.
  3. 3A content script sends a message; the background worker receives it in onMessage.
  4. 4The worker calls extension APIs or the network and replies.
  5. 5State 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.