Home › Chrome extensions › Browser extension with WXT AGENTS.md

Browser extension with WXT AGENTS.md

AGENTS.md for cross-browser Manifest V3 extensions built with WXT: entrypoints, messaging, storage, and permissions.

AGENTS.mdChrome extensions

How to use

Save this as AGENTS.md in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.

Note: Review and test before use. Provided as is, without warranty. See Terms.

AGENTS.mdDownload  
# AGENTS.md: Browser extension (WXT)

## Commands
`pnpm dev` (Chrome) · `pnpm dev:firefox` · `pnpm build` · `pnpm zip` · `pnpm compile` (typecheck) · `pnpm test` (Vitest with WXT's testing plugin)

## Structure
- Entrypoints in `entrypoints/`: `background.ts` (`defineBackground`), `*.content.ts` (`defineContentScript({ matches, main })`), `popup/`, `options/`, `sidepanel/`. WXT generates the manifest from these plus `wxt.config.ts`; don't hand-write `manifest.json`.
- Shared code in `utils/`, `components/`; auto-imports are enabled.

## Rules
- Use the `browser` API (WXT's polyfilled global), not `chrome.*`, for cross-browser support.
- The background is a service worker in MV3: no long-lived globals; persist state with `storage.defineItem('local:settings', { fallback })` from WXT storage.
- Messaging through a typed wrapper (e.g., `@webext-core/messaging`) with defined message types; validate data from content scripts.
- Content scripts: inject UI with `createShadowRootUi` to avoid CSS conflicts; clean up on `ctx.onInvalidated`. Never `innerHTML` page-controlled text.
- Permissions: request the minimum in `wxt.config.ts` (`manifest.permissions`, `host_permissions`); prefer `activeTab` and optional permissions requested at runtime.
- No remote code: everything ships in the bundle (store policies forbid remotely hosted code).
- Fetch external APIs from the background, not content scripts, and keep API keys out of the extension when possible (use your backend).

## Don't
Don't upload to the Chrome Web Store or Firefox Add-ons from the agent.

## Done
Typecheck, tests, and `pnpm build` pass for Chrome and Firefox.

More: all Chrome extensions rules · all AGENTS.md rules

Related rules

Chrome extension (Manifest V3) rules

Cursor rules for building Manifest V3 browser extensions with TypeScript and minimal permissions.

CursorChrome extensions

htmx + server-rendered HTML AGENTS.md

AGENTS.md for htmx 2 apps with server-rendered templates (any backend), partials, and progressive enhancement.

AGENTS.mdhtmx

Next.js AGENTS.md

AGENTS.md for Next.js 16 App Router projects: commands, folder layout, data access, auth, and done criteria.

AGENTS.mdNext.js

Nuxt 4 AGENTS.md

AGENTS.md for Nuxt 4 apps: the app/ directory layout, data fetching keys, server routes with validation, and runtime config.

AGENTS.mdVue / Nuxt

SvelteKit AGENTS.md

AGENTS.md for SvelteKit 2 + Svelte 5 (runes) apps with TypeScript.

AGENTS.mdSvelteKit

TypeScript npm library AGENTS.md

AGENTS.md for publishing TypeScript npm packages: ESM exports maps, bundling with tsdown, type checks, and changesets.

AGENTS.mdTypeScript

Get new rules weekly

One email a week: fresh rule files, agent tips, and what's changing in Cursor, Claude Code and Copilot. Free, unsubscribe anytime.

Opens the Rulestack Newsletter on beehiiv in a new tab. Or subscribe directly on beehiiv.