IHOR.DEVKNOWLEDGE_BASE
MENU

~/blog / Extensions / how-to-build-a-chrome-extension-with-manifest-v3.md

// pillar guide · 5 min read

How to Build a Chrome Extension with Manifest V3

Build a small Manifest V3 extension that reads the current page title: minimal files, temporary access, unpacked installation, and explicit failure handling.

Quick answer

Start with three files: a Manifest V3 manifest, an HTML popup, and an external JavaScript file. This example opens from the toolbar, reads the current page title after the user clicks a button, and displays it in the popup. It needs activeTab and scripting; it does not need a background worker, a server, or persistent access to every website.

A popup is an extension page. The injected function runs in the selected web page and returns a serializable value. That separation is the first useful architectural decision: the popup owns controls and feedback, while page code owns the DOM query. A background worker becomes useful later when work must respond to events outside the popup’s lifetime.

Practical implementation steps

  1. Create an empty folder and save the three files below at its root. Manifest paths are relative to the installed extension, so popup.html must exist with that exact spelling. JSON cannot contain comments or trailing commas.
  2. Open chrome://extensions, enable Developer mode, choose Load unpacked, and select that folder. Pin the extension if you want its action visible on the toolbar. This loads local files; it does not publish anything to the Store.
  3. Open an ordinary HTTPS page and invoke the extension. Click Read title and compare the result with the page’s title. Then try a chrome:// page to observe the failure message. Temporary permission does not make protected browser pages injectable.
  4. Edit JavaScript, reload the extension from its management card, and reopen the popup. If you later add content scripts, reload the target page too: reloading the extension does not replace the old code inside an already open document.
  5. Keep the first release focused. Add settings only when users have a preference to save. Add a worker only when an event or job needs it. A toolbar tool that inspects a font or a page title can begin with an on-demand interaction rather than a script on every page.

Use the popup’s own developer tools for UI errors. Injection errors belong to the calling extension context; page-side logs appear in the target tab. Reading the wrong console is an easy way to conclude that a handler never ran. The example’s visible error state avoids requiring a user to understand any console.

Implementation example

manifest.json:

{
  "manifest_version": 3,
  "name": "Read page title",
  "version": "1.0.0",
  "action": { "default_popup": "popup.html" },
  "permissions": ["activeTab", "scripting"]
}

Save popup.html with a button whose id is read, an output element whose id is result, and an external script tag pointing to popup.js. Put the script after those elements, or use defer. Do not use an inline event handler: extension pages apply a content security policy that restricts inline JavaScript.

popup.js:

const button = document.querySelector("#read");
const output = document.querySelector("#result");
button.addEventListener("click", async () => {
  button.disabled = true;
  output.textContent = "Reading…";
  try {
    const [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
    if (!Number.isInteger(tab?.id)) throw new Error("No active tab");
    const [frame] = await chrome.scripting.executeScript({
      target: { tabId: tab.id },
      func: () => document.title,
    });
    output.textContent = String(frame?.result ?? "Untitled page");
  } catch {
    output.textContent = "Open a regular web page and try again.";
  } finally {
    button.disabled = false;
  }
});

The injected function is self-contained because Chrome serializes it into another execution context. Referencing a variable from popup.js inside that function would fail; pass JSON-serializable values through args when you need parameters. textContent also ensures a page title is displayed as text rather than interpreted as HTML.

Tradeoffs and alternatives

Use a popup for a short command and a result that fits in a small surface. A side panel better suits a task that should remain visible while the user moves around the page. Static content scripts suit automatic behavior on a defined set of sites, while activeTab suits an explicit invocation. These choices change when and where code runs; they are more consequential than choosing a UI framework.

Plain JavaScript keeps this example directly loadable. TypeScript or React can be useful as the UI grows, but Chrome installs the compiled package, not source TSX. Verify that the output manifest points to the output assets and that the package contains no development-server dependency.

Font Picker is a real portfolio example of a focused inspection tool. Its existence demonstrates a product scope, not that it uses this exact tutorial implementation. Do not infer its permissions or architecture from the screenshot alone.

Common mistakes

  • Adding tabs simply because the code calls tabs.query: querying tab identifiers does not by itself require that permission. Sensitive tab properties have additional access rules.
  • Expecting activeTab to run automatically after install: access follows a qualifying user invocation.
  • Adding an action.onClicked handler while also configuring a popup: the click opens the popup instead.
  • Placing source files in the ZIP while the manifest points to missing compiled paths.
  • Assuming a successful HTTPS example proves behavior on browser pages, file URLs, or third-party frames.

Production checklist

  • Load the exact distributable folder into a separate browser profile.
  • Check a normal page, a protected page, a closed tab, and repeated button clicks.
  • Reopen the popup and confirm that transient results may disappear as intended.
  • Use the button with a keyboard and give the result an accessible status announcement.
  • Remove unused permissions and include required Store artwork before publication.
  • Record browser version and observed results; this tutorial does not claim a browser run of your package.

FAQ

Do I need a service worker?

Not for this example. Introduce one for extension-wide events, commands, installation handling, or work that belongs outside a popup. A worker is optional in the manifest.

Can I fetch code from a CDN?

Package executable extension code with the extension. A framework’s development CDN example is not an appropriate production extension setup. Treat remote data and executable code as different decisions.

What should I build next?

Choose one useful page-inspection task and keep the same path: explicit invocation, narrow DOM work, a serializable result, and visible failure. Then decide whether persistent settings or a longer-lived surface actually improve that task.

Primary sources

Ihor Kharchyshyn

Independent full-stack product engineer writing source-backed implementation guides for browser extensions and modern web products.

Need this implemented in a real product?

Browser tools with a clear purpose, focused permissions, and a maintainable Manifest V3 architecture.