Frontend · Skill

Build a browser extension

build-chrome-extension

Builds a Manifest V3 browser extension in JavaScript or TypeScript - manifest, service worker, content script, popup, message passing and storage, with the smallest permission set. Use when the user wants a Chrome extension, a browser add-on, or a popup that talks to a content script.

Works with: Any AI Not yet model-tested; testing Jan 2027

Paste it into ChatGPT, Claude, Gemini or any AI chat, then tell it about your project. How it works

Install in Claude Code, Cursor or Codex (optional)

Only for AI coding tools that read skill folders. Run one line in a terminal, in your project folder. It downloads this skill's text files from TheSkillVault and nothing else; you can read them first with “View raw SKILL.md”.

Claude Code (all your projects)

curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/build-chrome-extension/raw' -o ~/'.claude/skills/build-chrome-extension/SKILL.md' && curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/build-chrome-extension/files/LICENSE.txt' -o ~/'.claude/skills/build-chrome-extension/LICENSE.txt'

Cursor (this project)

curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/build-chrome-extension/raw' -o '.cursor/skills/build-chrome-extension/SKILL.md' && curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/build-chrome-extension/files/LICENSE.txt' -o '.cursor/skills/build-chrome-extension/LICENSE.txt'

Codex and other Agent Skills tools (this project)

curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/build-chrome-extension/raw' -o '.agents/skills/build-chrome-extension/SKILL.md' && curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/build-chrome-extension/files/LICENSE.txt' -o '.agents/skills/build-chrome-extension/LICENSE.txt'

Or connect the whole library over MCP

Add TheSkillVault to Cursor or add this to your app's MCP settings (read-only; help):

{
  "mcpServers": {
    "theskillvault": {
      "url": "https://theskillvault.ai/mcp"
    }
  }
}

A Manifest V3 extension is a small package. It has a manifest, a service worker, optional content scripts and a popup.

When to use

  • You want a Chrome or Chromium extension with a toolbar popup.
  • A page needs a content script that messages the extension.
  • You are moving an old Manifest V2 extension to V3.

When not to use

  • You want to inspect a page you did not write. Use debug-with-chrome-devtools.
  • You want an automated test of a website. Use test-web-app-with-playwright.

Steps

  1. Start with manifest.json. Set manifest_version to 3 and name the extension.
  2. Put background work in a service worker (background.service_worker). It wakes for events. It does not stay running.
  3. Add a popup (action.default_popup) for the toolbar UI. Keep that page small.
  4. Add a content script only for the sites that need it. List those hosts in matches. Do not use <all_urls> unless you must.
  5. Ask for the smallest permissions. Prefer optional permissions for anything you can request later.
  6. Pass messages with chrome.runtime.sendMessage. Give each message a TypeScript interface.
  7. Store settings with chrome.storage. Do not put passwords or tokens in the package.
  8. Schedule work with chrome.alarms, not setInterval. The worker can stop at any time.
  9. Load the unpacked folder from the browser extensions page. When a message fails, read the worker error.
type SaveNote = { type: "save-note"; text: string };

chrome.runtime.onMessage.addListener((message: SaveNote, _sender, sendResponse) => {
  if (message.type !== "save-note") return;
  chrome.storage.local.set({ note: message.text }).then(() => sendResponse({ ok: true }));
  return true;
});

Gotchas

  • Manifest V2 background pages are gone. A timer in the worker will not keep running.
  • A content script does not share the page's JavaScript world. Pass data with messages.
  • A wide host pattern will scare users and the store review. Narrow matches.
  • Set a content security policy. Load scripts from the package. Do not run remote code. Use HTTPS for network calls.
  • Treat page text and user input as untrusted. Escape anything you insert into the page.
  • Never ship an API key or a password inside the extension folder.

Portability

The same package works in Chrome and other Chromium browsers. Firefox and Safari speak the WebExtensions API, with small differences. If you are using another browser, check that your calls exist on both chrome and browser. This is not a desktop editor app.

Example prompt

"Build a Manifest V3 Chrome extension with a popup that saves a note and a content script that reads the page title."

Done when

  • The manifest is version 3 and lists only the permissions you use.
  • The popup, the worker and the content script pass typed messages.
  • No secret is stored in the package, and the unpacked extension loads.

---

Based on the Chrome extension JavaScript and TypeScript rules file in PatrickJS/awesome-cursorrules (CC0 1.0, public domain). See LICENSE.txt.

Bundled files

Licence

Adapted from awesome-cursorrules contributors (chrome-extension-dev rules) (Public domain (CC0 1.0) - rules contributed to PatrickJS/awesome-cursorrules), CC0 1.0. Adapted by TheSkillVault: turned a rules file into a build order with an original message type; kept Manifest V3, least privilege, messaging and storage; dropped editor, class-style and full-file output rules; added safety notes, gotchas, portability and done-when.

Licence: CC0 1.0. Attribution when you reuse it: Based on work by awesome-cursorrules contributors (chrome-extension-dev rules) (Public domain (CC0 1.0) - rules contributed to PatrickJS/awesome-cursorrules, CC0 1.0), https://github.com/PatrickJS/awesome-cursorrules/blob/b044f956f021b6e8877f16781bcfc466a6a120e9/rules/chrome-extension-dev-js-typescript-cursorrules-pro.mdc; adapted by TheSkillVault, https://theskillvault.ai