@extension.dev/mcp 3.17.0-canary.1779905934.1151df3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +36 -0
- package/README.md +101 -0
- package/bin/extension-mcp.js +3 -0
- package/claude/ARCHITECTURE.md +161 -0
- package/claude/CLAUDE.md +264 -0
- package/claude/README.md +72 -0
- package/claude/commands/extension-add.md +63 -0
- package/claude/commands/extension-debug.md +43 -0
- package/claude/commands/extension-publish.md +62 -0
- package/claude/commands/extension.md +76 -0
- package/claude/examples/add-sidebar.md +56 -0
- package/claude/examples/create-extension.md +49 -0
- package/claude/rules/cross-browser.md +84 -0
- package/claude/rules/extension-dev.md +83 -0
- package/claude/rules/mcp-tools.md +889 -0
- package/dist/module.cjs +2979 -0
- package/dist/module.d.ts +1 -0
- package/dist/rslib.config.d.ts +2 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/lib/act.d.ts +21 -0
- package/dist/src/lib/cdp.d.ts +48 -0
- package/dist/src/lib/exec.d.ts +13 -0
- package/dist/src/lib/process-manager.d.ts +5 -0
- package/dist/src/lib/templates-cache.d.ts +11 -0
- package/dist/src/lib/types.d.ts +68 -0
- package/dist/src/tools/add-feature.d.ts +29 -0
- package/dist/src/tools/build.d.ts +36 -0
- package/dist/src/tools/create.d.ts +29 -0
- package/dist/src/tools/detect-browsers.d.ts +20 -0
- package/dist/src/tools/dev.d.ts +34 -0
- package/dist/src/tools/dom-inspect.d.ts +56 -0
- package/dist/src/tools/eval.d.ts +44 -0
- package/dist/src/tools/get-template-source.d.ts +25 -0
- package/dist/src/tools/inspect.d.ts +29 -0
- package/dist/src/tools/install-browser.d.ts +18 -0
- package/dist/src/tools/list-browsers.d.ts +9 -0
- package/dist/src/tools/list-templates.d.ts +41 -0
- package/dist/src/tools/logs.d.ts +80 -0
- package/dist/src/tools/manifest-validate.d.ts +26 -0
- package/dist/src/tools/open.d.ts +31 -0
- package/dist/src/tools/preview.d.ts +23 -0
- package/dist/src/tools/publish.d.ts +32 -0
- package/dist/src/tools/reload.d.ts +33 -0
- package/dist/src/tools/source-inspect.d.ts +57 -0
- package/dist/src/tools/start.d.ts +29 -0
- package/dist/src/tools/storage.d.ts +51 -0
- package/dist/src/tools/wait.d.ts +29 -0
- package/dist/vitest.config.d.ts +3 -0
- package/package.json +84 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# @extension.dev/mcp — Changelog
|
|
2
|
+
|
|
3
|
+
## Unreleased — agent-bridge tools
|
|
4
|
+
|
|
5
|
+
Adds the MCP client surface for the Extension.js **agent bridge** (dev-time
|
|
6
|
+
observe + act + inspect). All new tools shell out to the `extension` CLI verbs
|
|
7
|
+
(lockstep invariant: the CLI is the single source of behavior), so they require
|
|
8
|
+
a recent **`extension` CLI that ships the bridge verbs** (`logs`, `eval`,
|
|
9
|
+
`storage`, `reload`, `open`, `inspect`, `publish`).
|
|
10
|
+
|
|
11
|
+
> ⚠️ **Release order:** publish this package ONLY after the `extension` /
|
|
12
|
+
> `extension-develop` suite that ships those verbs is on npm. The published CLI
|
|
13
|
+
> at the time of writing (`3.17.0`) does NOT have them — publishing this package
|
|
14
|
+
> before the suite would ship tools that fail with "unknown command". Bump the
|
|
15
|
+
> version + `extension-*` deps to that suite release, then publish.
|
|
16
|
+
|
|
17
|
+
New tools (22 total):
|
|
18
|
+
|
|
19
|
+
- **`extension_logs`** — read/stream logs from every extension context
|
|
20
|
+
(background, content, popup/options/sidebar/devtools); filters
|
|
21
|
+
`level`/`context`/`url`/`tab`/`since`, bounded `follow` window.
|
|
22
|
+
- **`extension_eval`** — evaluate an expression in a context (requires the dev
|
|
23
|
+
session started with `--allow-eval`; MV3 service worker is CSP-gated).
|
|
24
|
+
- **`extension_storage`** — read/write `chrome.storage` (requires `--allow-control`).
|
|
25
|
+
- **`extension_reload`** — reload the extension or a tab (`--allow-control`).
|
|
26
|
+
- **`extension_open`** — open popup/options/sidebar (`--allow-control`).
|
|
27
|
+
- **`extension_dom_inspect`** — CDP-free DOM snapshot of content/page or an open
|
|
28
|
+
surface (popup/options/sidebar/devtools); `withConsole` merges recent logs.
|
|
29
|
+
- **`extension_publish`** — publish to extension.dev and return a shareable URL
|
|
30
|
+
(auth-gated; requires `EXTENSION_DEV_TOKEN`).
|
|
31
|
+
- **`extension_source_inspect`** gains **`deepDom`** — pierce CLOSED shadow roots
|
|
32
|
+
via CDP (Chromium only).
|
|
33
|
+
|
|
34
|
+
Internal: `lib/act` (CLI shell-out helper), `lib/exec.runExtensionCli` (capture),
|
|
35
|
+
`lib/cdp.getClosedShadowRoots`. Test infra aligned to the workspace vitest
|
|
36
|
+
catalog.
|
package/README.md
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# @extension.dev/mcp
|
|
2
|
+
|
|
3
|
+
MCP server for building, debugging, and publishing cross-browser extensions. Exposes 15 tools that let AI assistants scaffold, develop, build, inspect, and debug extensions using the [extension.dev](https://extension.dev) platform and template catalog.
|
|
4
|
+
|
|
5
|
+
## What's in this package
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
@extension.dev/mcp
|
|
9
|
+
src/ MCP server source (15 tools across 3 tiers)
|
|
10
|
+
claude/ Claude Code integration (CLAUDE.md, slash commands, rules)
|
|
11
|
+
bin/ CLI entrypoint
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
**MCP server** — programmatic bridge between AI assistants and the extension.dev platform. Imports from published npm packages:
|
|
15
|
+
|
|
16
|
+
- `extension-create` — project scaffolding
|
|
17
|
+
- `extension-develop` — build/dev/preview
|
|
18
|
+
- `extension-install` — managed browser binaries
|
|
19
|
+
|
|
20
|
+
**Claude Code integration** — drop-in instructions, slash commands, and rules for Claude Code:
|
|
21
|
+
|
|
22
|
+
- `claude/CLAUDE.md` — project-level instructions for any extension project
|
|
23
|
+
- `claude/commands/` — slash commands (`/extension`, `/extension-add`, `/extension-debug`, `/extension-publish`)
|
|
24
|
+
- `claude/rules/` — rules for extension development, cross-browser compat, and MCP tools
|
|
25
|
+
|
|
26
|
+
Browser-launching tools (`dev`, `start`, `preview`) shell out to the `extension` CLI since they require the full browser launcher infrastructure.
|
|
27
|
+
|
|
28
|
+
## Setup
|
|
29
|
+
|
|
30
|
+
### Claude Code
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
claude mcp add extension-dev npx @extension.dev/mcp
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Claude Desktop / .mcp.json
|
|
37
|
+
|
|
38
|
+
```json
|
|
39
|
+
{
|
|
40
|
+
"mcpServers": {
|
|
41
|
+
"extension-dev": {
|
|
42
|
+
"command": "npx",
|
|
43
|
+
"args": ["@extension.dev/mcp"]
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Claude Code integration (manual)
|
|
50
|
+
|
|
51
|
+
Copy the Claude Code rules and commands into any extension project:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
# Rules (how Claude understands your project)
|
|
55
|
+
cp node_modules/@extension.dev/mcp/claude/CLAUDE.md ~/my-extension/.claude/CLAUDE.md
|
|
56
|
+
|
|
57
|
+
# Slash commands
|
|
58
|
+
mkdir -p ~/my-extension/.claude/commands
|
|
59
|
+
cp node_modules/@extension.dev/mcp/claude/commands/*.md ~/my-extension/.claude/commands/
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Tools
|
|
63
|
+
|
|
64
|
+
| Tier | Tool | Integration | Description |
|
|
65
|
+
| ---- | ------------------------------- | ------------------------------- | --------------------------------- |
|
|
66
|
+
| 1 | `extension_create` | `extensionCreate()` | Scaffold from a template |
|
|
67
|
+
| 1 | `extension_list_templates` | native | Browse 60+ templates |
|
|
68
|
+
| 1 | `extension_build` | `extensionBuild()` | Build for production |
|
|
69
|
+
| 1 | `extension_dev` | CLI spawn | Dev server with HMR |
|
|
70
|
+
| 1 | `extension_start` | CLI spawn | Build + preview |
|
|
71
|
+
| 1 | `extension_preview` | CLI spawn | Preview production build |
|
|
72
|
+
| 2 | `extension_get_template_source` | native | Read template source files |
|
|
73
|
+
| 2 | `extension_manifest_validate` | native | Cross-browser manifest validation |
|
|
74
|
+
| 2 | `extension_inspect` | native | Build output analysis |
|
|
75
|
+
| 2 | `extension_source_inspect` | CDP WebSocket | Live DOM inspection |
|
|
76
|
+
| 2 | `extension_wait` | native | Poll ready.json contract |
|
|
77
|
+
| 2 | `extension_add_feature` | native | Add sidebar/popup/content script |
|
|
78
|
+
| 3 | `extension_install_browser` | `extensionInstall()` | Install managed browser |
|
|
79
|
+
| 3 | `extension_list_browsers` | `getManagedBrowsersCacheRoot()` | List managed browsers |
|
|
80
|
+
| 3 | `extension_detect_browsers` | native | System browser detection |
|
|
81
|
+
|
|
82
|
+
## Development
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
pnpm install
|
|
86
|
+
pnpm compile # Build with rslib
|
|
87
|
+
pnpm test # Run tests
|
|
88
|
+
pnpm start # Start MCP server
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### Publishing
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
NPM_TOKEN=<token> pnpm publish
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Uses `prepublishOnly` to run tests and compile before publishing.
|
|
98
|
+
|
|
99
|
+
## License
|
|
100
|
+
|
|
101
|
+
MIT
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
# How the pieces connect
|
|
2
|
+
|
|
3
|
+
This document explains how the three Claude integration layers — the template, the Claude Code rules, and the MCP tools — connect through the [examples](https://github.com/extension-js/examples) repo.
|
|
4
|
+
|
|
5
|
+
## The examples repo is the backbone
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
examples repo (GitHub)
|
|
9
|
+
│
|
|
10
|
+
├── examples/<slug>/ 60+ extension templates
|
|
11
|
+
│ ├── src/manifest.json Source of truth per template
|
|
12
|
+
│ ├── template.meta.json Curated metadata (tags, difficulty, useCases, AI fields)
|
|
13
|
+
│ └── ...
|
|
14
|
+
│
|
|
15
|
+
├── templates-meta.json Auto-generated registry (all templates, structured)
|
|
16
|
+
│ Generated by: scripts/generate-templates-meta.mjs
|
|
17
|
+
│ Published as: GitHub release asset (nightly tag)
|
|
18
|
+
│ Contains: slug, surfaces, framework, permissions, files, downloads, integrity
|
|
19
|
+
│
|
|
20
|
+
├── public/<slug>/ Staged sources + pre-built distributions
|
|
21
|
+
│ ├── src/ Committed source for website consumption
|
|
22
|
+
│ └── dist/<browser>/ Pre-built .zip and .xpi files
|
|
23
|
+
│
|
|
24
|
+
└── artifacts/ Build pipeline output
|
|
25
|
+
└── <slug>.<browser>.zip Distributable archives
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Three integration layers
|
|
29
|
+
|
|
30
|
+
### Layer 1: sidebar-claude template
|
|
31
|
+
|
|
32
|
+
**Location:** `examples/sidebar-claude/`
|
|
33
|
+
**Role in ecosystem:** An example in the examples repo, discoverable like any other template.
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
User: "Build me a Claude chatbot extension"
|
|
37
|
+
│
|
|
38
|
+
▼
|
|
39
|
+
npx extension create my-bot --template=sidebar-claude
|
|
40
|
+
│
|
|
41
|
+
▼
|
|
42
|
+
Resolves → https://github.com/extension-js/examples/tree/main/examples/sidebar-claude
|
|
43
|
+
│
|
|
44
|
+
▼
|
|
45
|
+
go-git-it clones → copies to ./my-bot/ → installs deps → done
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
**How it integrates with the examples pipeline:**
|
|
49
|
+
|
|
50
|
+
- `generate-templates-meta.mjs` auto-discovers it by scanning `examples/sidebar-claude/src/manifest.json`
|
|
51
|
+
- Auto-detects: `uiContext: ["sidebar", "background"]`, `uiFramework: "react"`, `surfaces: ["sidebar", "background"]`
|
|
52
|
+
- Curated `template.meta.json` adds: featured flag, tags (ai, claude), difficulty, useCases, firstSteps
|
|
53
|
+
- CI builds it for Chrome/Edge/Firefox, packages as `.zip`, publishes in nightly release
|
|
54
|
+
- `templates-meta.json` includes download URLs with SHA256 integrity
|
|
55
|
+
|
|
56
|
+
### Layer 2: Claude Code rules (CLAUDE.md)
|
|
57
|
+
|
|
58
|
+
**Location:** `claude/CLAUDE.md`
|
|
59
|
+
**Role in ecosystem:** Teaches Claude Code about the extension.dev platform and the template catalog.
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
Developer copies CLAUDE.md into their project
|
|
63
|
+
│
|
|
64
|
+
▼
|
|
65
|
+
Claude Code reads it at conversation start
|
|
66
|
+
│
|
|
67
|
+
▼
|
|
68
|
+
Claude now knows:
|
|
69
|
+
├── Template catalog exists at templates-meta.json
|
|
70
|
+
├── Template URL pattern: https://github.com/extension-js/examples/tree/main/examples/<slug>
|
|
71
|
+
├── How to recommend templates by surface/framework
|
|
72
|
+
├── manifest.json cross-browser format
|
|
73
|
+
├── extension.dev commands and gotchas
|
|
74
|
+
└── How to read example source to learn patterns
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
**How it integrates with the examples repo:**
|
|
78
|
+
|
|
79
|
+
- References `templates-meta.json` as the source of truth for template discovery
|
|
80
|
+
- Documents the GitHub URL resolution pattern that `extension create` uses
|
|
81
|
+
- Provides the `curl` command to fetch and query the catalog
|
|
82
|
+
- Documents the nightly release download URL pattern for pre-built distributions
|
|
83
|
+
- Teaches how to contribute new templates (template.meta.json format, generator script)
|
|
84
|
+
|
|
85
|
+
### Layer 3: MCP tools
|
|
86
|
+
|
|
87
|
+
**Location:** `claude/rules/mcp-tools.md` (design doc)
|
|
88
|
+
**Role in ecosystem:** Programmatic bridge between Claude and the extension.dev platform, sourced from the examples repo.
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
Claude (via MCP) calls extension_list_templates({ surface: "sidebar", tags: ["ai"] })
|
|
92
|
+
│
|
|
93
|
+
▼
|
|
94
|
+
MCP server fetches templates-meta.json (cached, 1hr TTL)
|
|
95
|
+
│
|
|
96
|
+
▼
|
|
97
|
+
Returns: [{ slug: "sidebar-claude", ... }, { slug: "sidebar-transformers-js", ... }]
|
|
98
|
+
│
|
|
99
|
+
▼
|
|
100
|
+
Claude calls extension_get_template_source({ slug: "sidebar-claude", files: ["src/manifest.json", "src/lib/claude.ts"] })
|
|
101
|
+
│
|
|
102
|
+
▼
|
|
103
|
+
MCP server fetches from https://raw.githubusercontent.com/extension-js/examples/main/examples/sidebar-claude/<file>
|
|
104
|
+
│
|
|
105
|
+
▼
|
|
106
|
+
Claude reads the source, understands the pattern, adapts it for the user
|
|
107
|
+
│
|
|
108
|
+
▼
|
|
109
|
+
Claude calls extension_create({ projectName: "my-bot", template: "sidebar-claude" })
|
|
110
|
+
│
|
|
111
|
+
▼
|
|
112
|
+
MCP server calls extensionCreate() → same go-git-it flow as CLI
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
**How it integrates with the examples repo:**
|
|
116
|
+
|
|
117
|
+
- `extension_list_templates` → reads `templates-meta.json` release asset
|
|
118
|
+
- `extension_get_template_source` → reads raw files from the examples repo
|
|
119
|
+
- `extension_create` → clones from the examples repo (same as CLI)
|
|
120
|
+
- `extension_add_feature` → sources codegen patterns from example templates
|
|
121
|
+
- `extension_manifest_validate` → cross-references against known-good manifests in the catalog
|
|
122
|
+
|
|
123
|
+
## Data flow
|
|
124
|
+
|
|
125
|
+
```
|
|
126
|
+
┌──────────────────────────────────────────────────────────┐
|
|
127
|
+
│ examples repo │
|
|
128
|
+
│ │
|
|
129
|
+
│ examples/<slug>/ ──── generate-templates-meta.mjs │
|
|
130
|
+
│ │ │ │
|
|
131
|
+
│ │ ▼ │
|
|
132
|
+
│ │ templates-meta.json │
|
|
133
|
+
│ │ │ │ │
|
|
134
|
+
│ │ │ │ │
|
|
135
|
+
└───────┼────────────────────┼─────────┼───────────────────┘
|
|
136
|
+
│ │ │
|
|
137
|
+
│ │ │
|
|
138
|
+
┌────▼────┐ ┌──────────▼───┐ ┌──▼──────────────┐
|
|
139
|
+
│ Layer 1 │ │ Layer 2 │ │ Layer 3 │
|
|
140
|
+
│ Template │ │ CLAUDE.md │ │ MCP Server │
|
|
141
|
+
│ │ │ │ │ │
|
|
142
|
+
│ sidebar- │ │ References │ │ list_templates │
|
|
143
|
+
│ claude │ │ catalog & │ │ get_source │
|
|
144
|
+
│ │ │ URL patterns │ │ create │
|
|
145
|
+
│ Lives in │ │ │ │ add_feature │
|
|
146
|
+
│ examples │ │ Teaches │ │ validate │
|
|
147
|
+
│ repo │ │ humans how │ │ │
|
|
148
|
+
│ │ │ to use it │ │ Reads from repo │
|
|
149
|
+
└──────────┘ └──────────────┘ │ programmatically │
|
|
150
|
+
└──────────────────┘
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Why this architecture works
|
|
154
|
+
|
|
155
|
+
1. **Single source of truth.** `templates-meta.json` is generated from the actual examples. No manual sync needed. Add a template to `examples/`, run `pnpm run generate`, and all three layers pick it up.
|
|
156
|
+
|
|
157
|
+
2. **The examples repo is the knowledge base.** The MCP server doesn't hard-code extension patterns — it reads them from examples. This means new patterns (like `sidebar-claude`) are immediately available to Claude without updating the MCP server.
|
|
158
|
+
|
|
159
|
+
3. **Graceful degradation.** Users who don't use MCP still benefit from CLAUDE.md. Users who don't use Claude Code still benefit from the template. Each layer works independently.
|
|
160
|
+
|
|
161
|
+
4. **No lock-in.** The CLAUDE.md works with any AI tool that reads project instructions. The MCP server follows the open MCP protocol. The template is a standard extension project.
|
package/claude/CLAUDE.md
ADDED
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
# extension.dev — Claude Code Instructions
|
|
2
|
+
|
|
3
|
+
You are working on a browser extension project built with the [extension.dev](https://extension.dev) platform, a zero-config cross-browser extension framework.
|
|
4
|
+
|
|
5
|
+
## Core concepts
|
|
6
|
+
|
|
7
|
+
- **Only `manifest.json` is required.** The framework auto-detects your project structure from it.
|
|
8
|
+
- **Cross-browser via prefixes.** Use `chromium:` and `firefox:` prefixes in manifest.json for browser-specific fields. The build system strips these at build time.
|
|
9
|
+
- **Framework agnostic.** Vanilla JS/TS, React, Vue, Svelte, and Preact are auto-detected and configured.
|
|
10
|
+
- **Rspack-powered.** Fast Rust-based bundler. You can customize via `extension.config.js`.
|
|
11
|
+
|
|
12
|
+
## Template catalog
|
|
13
|
+
|
|
14
|
+
The extension.dev platform ships 60+ templates in the [examples](https://github.com/extension-js/examples) repo. The canonical registry is `templates-meta.json` published as a GitHub release asset and committed to the repo.
|
|
15
|
+
|
|
16
|
+
**How templates work:**
|
|
17
|
+
|
|
18
|
+
- `npx extension@latest create my-ext --template=<slug>` fetches from `https://github.com/extension-js/examples/tree/main/examples/<slug>`
|
|
19
|
+
- Template names are directory names under `examples/` in the repo
|
|
20
|
+
- Each template has auto-detected metadata (framework, surfaces, permissions) + optional curated metadata in `template.meta.json`
|
|
21
|
+
|
|
22
|
+
**Key templates by surface:**
|
|
23
|
+
|
|
24
|
+
| Surface | Vanilla | React | Vue | Svelte | AI |
|
|
25
|
+
| -------------- | ------------ | ---------------- | ------------- | ---------------- | ---------------- |
|
|
26
|
+
| Content script | `content` | `content-react` | `content-vue` | `content-svelte` | — |
|
|
27
|
+
| Sidebar | `sidebar` | `sidebar-shadcn` | — | — | `sidebar-claude` |
|
|
28
|
+
| Action popup | `action` | — | — | — | `action-chatgpt` |
|
|
29
|
+
| New tab | `new` | `new-react` | `new-vue` | `new-svelte` | — |
|
|
30
|
+
| Full framework | `javascript` | `react` | `vue` | `svelte` | — |
|
|
31
|
+
|
|
32
|
+
**When recommending a template:**
|
|
33
|
+
|
|
34
|
+
1. Match the user's desired surface (sidebar, content script, popup, etc.)
|
|
35
|
+
2. Match their framework preference
|
|
36
|
+
3. Prefer `featured: true` templates for common use cases
|
|
37
|
+
4. For AI-powered extensions, start from `sidebar-claude` or `action-chatgpt`
|
|
38
|
+
|
|
39
|
+
**To browse all available templates:**
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
# The full catalog with metadata (framework, surfaces, permissions, etc.)
|
|
43
|
+
curl -sL https://github.com/extension-js/examples/releases/download/nightly/templates-meta.json | jq '.templates[] | {slug, description, uiFramework, surfaces}'
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
**Pre-built distributions** are available for every template:
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
https://github.com/extension-js/examples/releases/download/nightly/<slug>.<browser>.zip
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Project structure
|
|
53
|
+
|
|
54
|
+
A typical extension.dev project:
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
my-extension/
|
|
58
|
+
src/
|
|
59
|
+
manifest.json # Required — the source of truth
|
|
60
|
+
background.ts # Service worker (Chromium) / background script (Firefox)
|
|
61
|
+
content/ # Content scripts
|
|
62
|
+
scripts.tsx
|
|
63
|
+
styles.css
|
|
64
|
+
sidebar/ # Sidebar panel UI
|
|
65
|
+
index.html
|
|
66
|
+
scripts.tsx
|
|
67
|
+
styles.css
|
|
68
|
+
images/
|
|
69
|
+
icon.png
|
|
70
|
+
extension.config.js # Optional build config
|
|
71
|
+
extension-env.d.ts # Auto-generated types
|
|
72
|
+
package.json
|
|
73
|
+
tsconfig.json
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## manifest.json cross-browser format
|
|
77
|
+
|
|
78
|
+
The framework extends the standard manifest with browser prefixes:
|
|
79
|
+
|
|
80
|
+
```json
|
|
81
|
+
{
|
|
82
|
+
"chromium:manifest_version": 3,
|
|
83
|
+
"firefox:manifest_version": 2,
|
|
84
|
+
"name": "My Extension",
|
|
85
|
+
"chromium:action": { "default_title": "Click me" },
|
|
86
|
+
"firefox:browser_action": { "default_title": "Click me" },
|
|
87
|
+
"chromium:side_panel": { "default_path": "sidebar/index.html" },
|
|
88
|
+
"firefox:sidebar_action": { "default_panel": "sidebar/index.html" },
|
|
89
|
+
"background": {
|
|
90
|
+
"chromium:service_worker": "background.ts",
|
|
91
|
+
"firefox:scripts": ["background.ts"]
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
**Rules:**
|
|
97
|
+
|
|
98
|
+
- Fields without a prefix apply to all browsers
|
|
99
|
+
- `chromium:` fields apply to Chrome, Edge, and Chromium-based browsers
|
|
100
|
+
- `firefox:` fields apply to Firefox and Gecko-based browsers
|
|
101
|
+
- `chromium:permissions` and `firefox:permissions` can differ
|
|
102
|
+
|
|
103
|
+
## Commands
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
# Scaffold a new extension
|
|
107
|
+
npx extension@latest create my-extension --template=react
|
|
108
|
+
|
|
109
|
+
# Development with HMR
|
|
110
|
+
npm run dev
|
|
111
|
+
# or: npx extension dev
|
|
112
|
+
|
|
113
|
+
# Build for production
|
|
114
|
+
npm run build
|
|
115
|
+
# or: npx extension build
|
|
116
|
+
|
|
117
|
+
# Preview production build
|
|
118
|
+
npm run preview
|
|
119
|
+
# or: npx extension preview
|
|
120
|
+
|
|
121
|
+
# Target a specific browser
|
|
122
|
+
npm run dev -- --browser=firefox
|
|
123
|
+
npm run build -- --browser=chrome,firefox
|
|
124
|
+
|
|
125
|
+
# Zip for distribution
|
|
126
|
+
npm run build -- --zip
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## extension.config.js
|
|
130
|
+
|
|
131
|
+
```javascript
|
|
132
|
+
/** @type {import('extension').FileConfig} */
|
|
133
|
+
export default {
|
|
134
|
+
browser: {
|
|
135
|
+
chrome: {
|
|
136
|
+
profile: "./dist/profile-chrome", // Persist browser profile
|
|
137
|
+
startingUrl: "https://example.com",
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
config: (rspackConfig) => {
|
|
141
|
+
// Mutate Rspack config here
|
|
142
|
+
return rspackConfig;
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## Important gotchas
|
|
148
|
+
|
|
149
|
+
1. **world: "MAIN" is Chromium-only.** If your content script uses `"world": "MAIN"`, prefix it with `chromium:` and provide a Firefox fallback or skip.
|
|
150
|
+
2. **Side panels vs sidebar actions.** Chromium uses `side_panel` + `sidePanel` permission. Firefox uses `sidebar_action` (no permission needed).
|
|
151
|
+
3. **Service workers vs background scripts.** Chromium uses `service_worker` (single file). Firefox uses `scripts` (array).
|
|
152
|
+
4. **Environment variables.** Use `EXTENSION_PUBLIC_*` prefix for variables accessible in extension code. `import.meta.env.EXTENSION_PUBLIC_BROWSER` gives the current browser.
|
|
153
|
+
5. **Asset imports.** Import images/fonts directly in your code. The build system handles bundling.
|
|
154
|
+
6. **CSS Modules.** Use `*.module.css` / `*.module.scss`. Never use the `?url` suffix for CSS module imports — it breaks class name hashing.
|
|
155
|
+
|
|
156
|
+
## When creating new extensions
|
|
157
|
+
|
|
158
|
+
1. Check if an existing template matches the use case (see template catalog above)
|
|
159
|
+
2. If yes: `npx extension@latest create my-ext --template=<slug>`
|
|
160
|
+
3. If no: start from `manifest.json` — define what the extension needs
|
|
161
|
+
4. Add entry points referenced by the manifest (background, content scripts, UI pages)
|
|
162
|
+
5. Install framework deps if needed (React, Vue, etc.) — the framework auto-detects them
|
|
163
|
+
6. Run `npm run dev` — the dev server handles the rest
|
|
164
|
+
|
|
165
|
+
**Learning from examples:** When building a feature you haven't done before, read the source of a relevant template from the examples repo. The source for any template is at:
|
|
166
|
+
|
|
167
|
+
```
|
|
168
|
+
https://github.com/extension-js/examples/tree/main/examples/<slug>/src
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## When debugging
|
|
172
|
+
|
|
173
|
+
### Source inspection (`--source`)
|
|
174
|
+
|
|
175
|
+
The `--source` flag on `dev` gives live DOM inspection of a running extension:
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
# Basic: see injected HTML after content scripts run
|
|
179
|
+
npm run dev -- --source https://example.com
|
|
180
|
+
|
|
181
|
+
# Structured JSON output (best for programmatic use)
|
|
182
|
+
npm run dev -- --source https://example.com --source-format json
|
|
183
|
+
|
|
184
|
+
# Probe specific selectors
|
|
185
|
+
npm run dev -- --source https://example.com --source-probe "#my-root,.sidebar"
|
|
186
|
+
|
|
187
|
+
# Full inspection: DOM snapshots, console summary, diffs on rebuild
|
|
188
|
+
npm run dev -- --source https://example.com --source-dom --source-console --source-diff
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
**Available --source sub-flags:**
|
|
192
|
+
|
|
193
|
+
| Flag | Default | Purpose |
|
|
194
|
+
| ---------------------------- | --------- | ------------------------------------------------- |
|
|
195
|
+
| `--source [url]` | — | Open URL and print live HTML after injection |
|
|
196
|
+
| `--watch-source` | true | Re-print on rebuilds |
|
|
197
|
+
| `--source-format` | json | Output format: `pretty`, `json`, `ndjson` |
|
|
198
|
+
| `--source-summary` | auto | Compact stats instead of full HTML |
|
|
199
|
+
| `--source-meta` | auto | Page metadata: readyState, viewport, frames |
|
|
200
|
+
| `--source-probe <selectors>` | — | CSS selectors to query (comma-separated) |
|
|
201
|
+
| `--source-tree` | off | Extension root DOM tree: `off`, `root-only` |
|
|
202
|
+
| `--source-console` | auto | Console counts: error/warn/info/log/debug |
|
|
203
|
+
| `--source-dom` | auto | DOM snapshots and structural diffs |
|
|
204
|
+
| `--source-max-bytes` | 256KB | Truncate HTML output (0 = unlimited) |
|
|
205
|
+
| `--source-redact` | safe | Redact sensitive content: `off`, `safe`, `strict` |
|
|
206
|
+
| `--source-include-shadow` | open-only | Shadow DOM: `off`, `open-only`, `all` |
|
|
207
|
+
| `--source-diff` | auto | Include diff metadata on watch updates |
|
|
208
|
+
|
|
209
|
+
**Output event types** (in JSON/NDJSON format):
|
|
210
|
+
|
|
211
|
+
- `page_html` — full injected HTML
|
|
212
|
+
- `page_html_summary` — root/script/style/link counts
|
|
213
|
+
- `page_meta` — readyState, viewport, frame count
|
|
214
|
+
- `dom_snapshot` — structured tree (tag, id, classes, role, max 500 nodes)
|
|
215
|
+
- `dom_diff` — added/removed/changed between rebuilds
|
|
216
|
+
- `console_summary` — error/warn counts + top 5 unique messages
|
|
217
|
+
- `selector_probe` — per-selector element counts and samples
|
|
218
|
+
- `extension_root_tree` — extension root elements with reinject generations
|
|
219
|
+
|
|
220
|
+
### Unified logging (`--logs`)
|
|
221
|
+
|
|
222
|
+
Stream extension logs from all contexts to the terminal:
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
# All contexts at info level
|
|
226
|
+
npm run dev -- --logs info
|
|
227
|
+
|
|
228
|
+
# Only content scripts and background
|
|
229
|
+
npm run dev -- --logs debug --log-context content,background
|
|
230
|
+
|
|
231
|
+
# JSON format for programmatic consumption
|
|
232
|
+
npm run dev -- --logs info --log-format json
|
|
233
|
+
|
|
234
|
+
# Filter by URL pattern
|
|
235
|
+
npm run dev -- --logs info --log-url "example.com"
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### Other debugging tools
|
|
239
|
+
|
|
240
|
+
- Use `--browser=firefox` to test cross-browser compatibility
|
|
241
|
+
- Check `dist/<browser>/` for build output
|
|
242
|
+
- Use `--wait` flag to check if dev session is ready (outputs ready.json contract)
|
|
243
|
+
- Use `npm run start` to test production builds (builds first, then launches)
|
|
244
|
+
|
|
245
|
+
## Contributing templates to the examples repo
|
|
246
|
+
|
|
247
|
+
If you create a new extension pattern worth sharing:
|
|
248
|
+
|
|
249
|
+
1. Place the example in `examples/<slug>/` following the standard layout
|
|
250
|
+
2. Add `template.meta.json` with curated metadata:
|
|
251
|
+
```json
|
|
252
|
+
{
|
|
253
|
+
"title": "Human-readable title",
|
|
254
|
+
"featured": false,
|
|
255
|
+
"tags": ["relevant", "tags"],
|
|
256
|
+
"difficulty": "beginner",
|
|
257
|
+
"timeToFirstSuccessMinutes": 3,
|
|
258
|
+
"useCases": ["What users would build with this"],
|
|
259
|
+
"firstSteps": ["Step 1", "Step 2"]
|
|
260
|
+
}
|
|
261
|
+
```
|
|
262
|
+
3. The `generate-templates-meta.mjs` script auto-detects: framework, surfaces, permissions, entry points, CSS tech, config files
|
|
263
|
+
4. Run `pnpm run generate` to regenerate `templates-meta.json`
|
|
264
|
+
5. The CI pipeline handles: build, test (Playwright), package, and nightly release
|
package/claude/README.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# extension.dev — Claude Code Integration
|
|
2
|
+
|
|
3
|
+
Drop-in instructions, rules, and example prompts for building browser extensions with the [extension.dev](https://extension.dev) platform using Claude Code.
|
|
4
|
+
|
|
5
|
+
**Looking for the MCP server?** See the root [`README.md`](../README.md).
|
|
6
|
+
|
|
7
|
+
## What's here
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
claude/
|
|
11
|
+
CLAUDE.md Drop-in Claude Code instructions for any extension project
|
|
12
|
+
ARCHITECTURE.md How the template, CLAUDE.md, and MCP layers connect
|
|
13
|
+
commands/
|
|
14
|
+
extension.md /extension — create, dev, build, add features, debug
|
|
15
|
+
extension-add.md /extension-add — add sidebar, popup, content script, etc.
|
|
16
|
+
extension-debug.md /extension-debug — live DOM/console inspection
|
|
17
|
+
extension-publish.md /extension-publish — store submission prep
|
|
18
|
+
rules/
|
|
19
|
+
extension-dev.md Core rules: project structure, manifest, commands
|
|
20
|
+
cross-browser.md Cross-browser manifest field mapping
|
|
21
|
+
mcp-tools.md Full MCP tool specification and design doc
|
|
22
|
+
examples/
|
|
23
|
+
create-extension.md Example prompt: scaffold and customize an extension
|
|
24
|
+
add-sidebar.md Example prompt: add a sidebar panel to an existing extension
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Quick start
|
|
28
|
+
|
|
29
|
+
Copy `CLAUDE.md` and slash commands into any extension project:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
# Rules (how Claude understands your project)
|
|
33
|
+
cp node_modules/@extension.dev/mcp/claude/CLAUDE.md ~/my-extension/.claude/CLAUDE.md
|
|
34
|
+
|
|
35
|
+
# Slash commands (what you can type)
|
|
36
|
+
mkdir -p ~/my-extension/.claude/commands
|
|
37
|
+
cp node_modules/@extension.dev/mcp/claude/commands/*.md ~/my-extension/.claude/commands/
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Slash commands
|
|
41
|
+
|
|
42
|
+
| Command | What it does |
|
|
43
|
+
| ---------------------------------------- | ------------------------------------------------------ |
|
|
44
|
+
| `/extension create my-ext react sidebar` | Scaffold a new extension from templates |
|
|
45
|
+
| `/extension dev` | Start dev server with HMR |
|
|
46
|
+
| `/extension build` | Build for production |
|
|
47
|
+
| `/extension-add sidebar react` | Add a feature surface to existing project |
|
|
48
|
+
| `/extension-debug https://example.com` | Inspect live DOM, console, content scripts |
|
|
49
|
+
| `/extension-publish both` | Prepare zips and checklist for Chrome + Firefox stores |
|
|
50
|
+
|
|
51
|
+
Claude Code will automatically pick up the instructions and know how to:
|
|
52
|
+
|
|
53
|
+
- Browse the template catalog via `templates-meta.json`
|
|
54
|
+
- Scaffold extensions with `npx extension create --template=<slug>`
|
|
55
|
+
- Read example source from the catalog to learn patterns
|
|
56
|
+
- Work with the `manifest.json` cross-browser format
|
|
57
|
+
- Run dev/build/preview commands
|
|
58
|
+
- Handle Chromium vs Firefox differences
|
|
59
|
+
|
|
60
|
+
## How it connects to the examples repo
|
|
61
|
+
|
|
62
|
+
The [examples repo](https://github.com/extension-js/examples) publishes `templates-meta.json` as a nightly release asset. This file is the single source of truth for:
|
|
63
|
+
|
|
64
|
+
- **CLAUDE.md** — references it so Claude knows all available templates
|
|
65
|
+
- **MCP tools** — `extension_list_templates` fetches and queries it at runtime
|
|
66
|
+
- **`extension create`** — resolves template slugs to repo URLs via the same naming convention
|
|
67
|
+
|
|
68
|
+
When a new template is added to the examples repo, all three layers pick it up automatically.
|
|
69
|
+
|
|
70
|
+
## License
|
|
71
|
+
|
|
72
|
+
MIT
|