@extension.dev/skill 0.5.0 → 1.0.0

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.
@@ -0,0 +1,72 @@
1
+ # Migrating an Existing Extension
2
+
3
+ Most real projects start here, not from a template: a webpack, Vite, gulp or
4
+ pug build that already ships. The engine's own guide is
5
+ https://extension.js.org/docs/migrate/from-webpack-or-vite (CRXJS, Plasmo and
6
+ WXT have their own pages beside it). This is the checklist nine open-source
7
+ extensions needed in practice, in the order the problems appear.
8
+
9
+ ## 1. Point the manifest at sources and merge per-browser manifests
10
+
11
+ - Keep one `manifest.json`; make every entry point name a **source** file
12
+ (`background.ts`, `content/scripts.tsx`, `popup/index.html`). The build
13
+ compiles them and rewrites the dist manifest.
14
+ - Projects that kept `manifest.chrome.json` and `manifest.firefox.json`
15
+ merge them into one file with `chromium:` and `firefox:` prefixes on the
16
+ fields that differ (`chromium:service_worker` / `firefox:scripts`,
17
+ `chromium:action` / `firefox:browser_action`, `chromium:permissions` /
18
+ `firefox:permissions`). See [cross-browser.md](cross-browser.md).
19
+ - Add a Firefox id: `firefox:browser_specific_settings.gecko.id`. Without it
20
+ Firefox mints a new internal id on every launch and storage does not
21
+ survive a relaunch. Add `data_collection_permissions` in the same block
22
+ (required for new AMO add-ons).
23
+
24
+ ## 2. Move runtime-only files where the engine finds them
25
+
26
+ - HTML pages the manifest does not name (an injected panel, a welcome page)
27
+ go to the root `pages/` special folder; scripts loaded at runtime with
28
+ `chrome.scripting.executeScript` go to root `scripts/`; images, fonts and
29
+ anything served verbatim go to root `public/`. None of these live under
30
+ `src/`. Mind the `scripts/` name clash with repository tooling, see
31
+ [project-structure.md](project-structure.md).
32
+ - `_locales/` moves to the project root (not `src/`, not `public/`).
33
+ - Web-accessible resources keep their manifest entries; check that each
34
+ file resolves after the move (`extension_manifest_validate` warns on a
35
+ missing one).
36
+
37
+ ## 3. Fix CommonJS-era imports
38
+
39
+ - `require()` of JSON and raw assets becomes `import data from "./x.json"`;
40
+ a raw text or binary asset is imported with the `?url` suffix and fetched,
41
+ not inlined by a loader the project configured for webpack.
42
+ - CSS modules on engines up to 4.1.30 export named classes only; see the
43
+ CSS note in [project-structure.md](project-structure.md).
44
+ - Drop webpack-only loaders and plugins from the dependency list; the engine
45
+ configures React, Vue, Svelte, Preact and TypeScript from the imports.
46
+
47
+ ## 4. Monorepos and sibling packages
48
+
49
+ - A panel that imports `.vue` or `.ts` sources from a workspace sibling
50
+ needs those paths compiled: on engines up to 4.1.30 the loaders include
51
+ only the project root, so either move the shared sources under the
52
+ project or alias them to a built package. The `config` hook in
53
+ `extension.config.js` is not the escape hatch here; it runs before the
54
+ framework rules exist.
55
+
56
+ ## 5. Install next to an older toolchain
57
+
58
+ - `npm i -D extension` can refuse with `ERESOLVE` beside `css-loader@6`,
59
+ which pins `@rspack/core` 0.x or 1.x while the engine brings rspack 2.
60
+ Upgrade `css-loader` to 7, or install with `legacy-peer-deps=true` in
61
+ `.npmrc` for that one step.
62
+
63
+ ## 6. Verify like a release
64
+
65
+ - `extension_manifest_validate` per target, then `extension_build` per
66
+ browser; a failed build reports the compiler errors under `value.errors`.
67
+ - Run the artifact that ships, not the dev build: `extension_start` with
68
+ `outputPath` launches any unpacked directory, including one the old
69
+ toolchain produced, so the two can be compared side by side.
70
+ - Read it with `extension_logs` and `extension_dom_snapshot`; on Firefox,
71
+ an extension page with a strict CSP cannot be evaluated through the
72
+ bridge, so read rather than eval there.
@@ -21,8 +21,8 @@ my-extension/
21
21
  styles.css
22
22
  images/
23
23
  icon.png
24
- pages/ Special folder: HTML pages not in the manifest
25
- scripts/ Special folder: scripts not in the manifest
24
+ pages/ Special folder: HTML pages not in the manifest
25
+ scripts/ Special folder: scripts not in the manifest
26
26
  public/ Special folder: static files copied verbatim
27
27
  _locales/ i18n messages at project root, NOT src/ (see below)
28
28
  extension.config.js Optional build config
@@ -53,15 +53,28 @@ Two more bundling facts that surprise people:
53
53
 
54
54
  ### Special folders
55
55
 
56
- Three folders get build treatment without manifest references:
56
+ Three folders get build treatment without manifest references. All three
57
+ live at the **project root**, next to `package.json`, never under `src/`:
58
+ the engine discovers them at the root and ignores `src/pages/` and
59
+ `src/scripts/` without a word, so pages placed there are not emitted.
57
60
 
58
61
  - `pages/`: HTML pages bundled and served like manifest pages (open them via
59
62
  `chrome.runtime.getURL`).
60
63
  - `scripts/`: script files compiled as standalone entries (for
61
- `chrome.scripting.executeScript` targets and similar).
64
+ `chrome.scripting.executeScript` targets and similar). The name collides
65
+ with the `scripts/` folder many repositories keep for tooling: every file
66
+ in it becomes a build entry, and the first build writes outputs for them.
67
+ If the repository already has a tooling `scripts/`, move the tooling or do
68
+ not adopt the special folder; there is no opt-out key yet.
62
69
  - `public/`: copied to the output root verbatim, no bundling or hashing. The
63
70
  build refuses files in `public/` that would overwrite generated assets, and
64
- a manifest.json inside `public/` is an error.
71
+ a manifest.json inside `public/` is an error. On Extension.js 4.1.30 and
72
+ earlier, manifest icons and pages are resolved next to the **manifest**,
73
+ so the layout above (`src/manifest.json`, root `public/`) cannot name an
74
+ icon kept in `public/`: the build reports it NOT FOUND under `src/`. Until
75
+ the project runs a newer engine, keep icons the manifest names under
76
+ `src/` (or the manifest at the root); newer engines resolve `public/` at
77
+ the project root for icons, pages and web-accessible resources alike.
65
78
 
66
79
  ## i18n and `_locales`
67
80
 
@@ -172,7 +185,30 @@ debugging stateful features far less painful.
172
185
 
173
186
  - Import images and fonts directly from code; the bundler handles emission.
174
187
  - CSS Modules: `*.module.css` / `*.module.scss`. Never add the `?url` suffix
175
- to a CSS module import; it silently breaks class-name hashing.
188
+ to a CSS module import; it silently breaks class-name hashing. On
189
+ Extension.js 4.1.30 and earlier a CSS module has **named exports only**:
190
+ write `import * as styles from "./x.module.scss"` or
191
+ `import { button } from "./x.module.scss"`; the common
192
+ `import styles from "./x.module.scss"` fails with one
193
+ "export 'default' was not found" linking error per class. To keep the
194
+ default import on those engines, set the parser option in
195
+ `extension.config.js`:
196
+
197
+ ```js
198
+ export default {
199
+ config: (config) => {
200
+ config.module.parser ??= {};
201
+ config.module.parser["css/module"] = {
202
+ ...config.module.parser["css/module"],
203
+ namedExports: false,
204
+ };
205
+ return config;
206
+ },
207
+ };
208
+ ```
209
+
210
+ Newer engines export a default again, so the switch can go once the
211
+ project upgrades.
176
212
  - Tailwind works out of the box in templates that ship it; check the template
177
213
  source rather than wiring it by hand.
178
214
 
@@ -11,11 +11,13 @@ npm run build -- --browser=chrome --zip
11
11
  npm run build -- --browser=firefox --zip --zip-source
12
12
  ```
13
13
 
14
- Verify the production build behaves before shipping: `npm run start` builds
15
- and launches without HMR, which catches dev-only assumptions (HMR globals,
16
- unhashed asset paths, dev CSP relaxations).
14
+ Verify the artifact you ship before shipping: `npm run build`, then
15
+ `npm run preview`, which opens the built directory without rebuilding and
16
+ catches dev-only assumptions (HMR globals, unhashed asset paths, dev CSP
17
+ relaxations). `start` rebuilds with the polyfill on, so it tests a different
18
+ artifact (core rule 5).
17
19
 
18
- MCP: `extension_build`, `extension_start`, `extension_preview`.
20
+ MCP: `extension_build`, `extension_start`.
19
21
 
20
22
  ## Zip hygiene
21
23
 
@@ -53,11 +55,68 @@ store, so resubmissions do not reinvent them. The full convention, template,
53
55
  and maintenance rules live in [store-md.md](store-md.md). Exclude the file
54
56
  from the zip.
55
57
 
56
- `extension-deploy` reads `STORE.md` automatically and submits the fields the
57
- store APIs accept: Firefox reviewer and release notes, and Edge certification
58
+ A submission reads `STORE.md` automatically and sends the fields the store
59
+ APIs accept: Firefox reviewer and release notes, and Edge certification
58
60
  notes. Chrome listing fields are dashboard-only by store policy and stay
59
61
  copy-paste.
60
62
 
63
+ ## Store accounts and credentials
64
+
65
+ Full walkthroughs with portal paths live on the docs site under
66
+ "Publish to the stores" (extension.js.org/docs/publishing). The load-bearing
67
+ facts:
68
+
69
+ Account prerequisites (none of the store APIs can create the first listing
70
+ where noted; the first upload is manual):
71
+
72
+ - Chrome: register at the CWS Developer Dashboard (one-time $5 fee). The API
73
+ cannot create a new item; upload the first zip by hand in the dashboard.
74
+ The 32-character extension ID only exists after that upload.
75
+ - Firefox: AMO developer account plus acceptance of the Firefox Add-on
76
+ Distribution Agreement; the API key page stays locked until accepted.
77
+ - Edge: Partner Center enrollment in the Microsoft Edge program (free).
78
+ There is no create-product API and the Product ID is always required, so
79
+ the product must be created with a first manual Partner Center submission.
80
+
81
+ Credential shapes and portals:
82
+
83
+ - Chrome: publisher UUID (from chrome.google.com/webstore/devconsole/<UUID>)
84
+ plus either a GCP service account JSON (grant its email under dev console >
85
+ Account; preferred, no expiry, and nothing has to be minted) or the OAuth
86
+ trio: Desktop-app client ID (`123.apps.googleusercontent.com`), client
87
+ secret (`GOCSPX-...`), refresh token (`1//...`). The refresh token comes
88
+ from a local loopback consent flow against that Desktop-app client. Never
89
+ recommend the Google OAuth Playground for this: it needs a Web-application
90
+ redirect URI and fails a Desktop-app client with redirect_uri_mismatch. If
91
+ the OAuth consent screen is in Testing status, Google revokes the refresh
92
+ token after 7 days. Prefer the service account and skip the trio.
93
+ - Firefox: JWT issuer (`user:12345678:987`) and JWT secret (64 hex, shown
94
+ once) from addons.mozilla.org/developers/addon/api/key/. Listed channel
95
+ requires an existing add-on GUID. Unlisted with an empty GUID creates a
96
+ NEW add-on; copy the assigned GUID back into the store settings after the
97
+ first submission, or every later empty-GUID submission creates another
98
+ add-on. Set the channel explicitly; an unset channel defaults to listed at
99
+ submit time.
100
+ - Edge: Client ID (GUID) and API key from the Partner Center Publish API
101
+ page (partner.microsoft.com/dashboard/microsoftedge/publishapi, "Turn on
102
+ API" / "+ New API key"). This is the current ApiKey model, not an Azure AD
103
+ client secret. Keys expire about every 72 days; rotate before then. The
104
+ Product ID is the lowercase GUID from the product's Extension Identity
105
+ section, not the uppercase public Store ID.
106
+
107
+ Blast radius: all three stores' API credentials are account-wide, not
108
+ per-extension. For multi-client work, keep each client's listings under that
109
+ client's own store accounts.
110
+
111
+ Where they live: per project, never per workspace. Credentials are entered
112
+ once in the extension.dev console under the project's store settings, and the
113
+ platform writes them as write-only GitHub Actions secrets on that project's
114
+ managed mirror repo (STORE_CHROME_*, STORE_FIREFOX_API_KEY/API_SECRET,
115
+ STORE_EDGE_CLIENT_ID/CLIENT_SECRET; the Edge CLIENT_SECRET holds the API
116
+ key). Identifiers go to the mirror's _extension-dev/settings.json. Rotation
117
+ always means re-entering values. Credentials are never tool arguments and
118
+ never leave the console, so no submission command takes one.
119
+
61
120
  ## Firefox specifics
62
121
 
63
122
  - New add-ons (first submission, no existing GUID) must declare
@@ -78,17 +137,72 @@ copy-paste.
78
137
  The platform has its own publish flow for hosting and distribution:
79
138
 
80
139
  ```bash
81
- # One-time device-code login (GitHub)
82
- extension login # MCP: extension_login
83
- extension whoami # MCP: extension_whoami
140
+ # One-time device login: approve the printed code at extension.dev/device
141
+ npx @extension.dev/mcp login --project <workspace>/<project> # MCP: extension_auth action:login
142
+ npx @extension.dev/mcp whoami # MCP: extension_auth action:status
84
143
 
85
144
  # Publish the built extension (shareable preview URL)
86
- extension publish # MCP: extension_publish
145
+ EXTENSION_DEV_TOKEN=<token> extension publish # MCP: extension_publish
87
146
  ```
88
147
 
89
- `extension_logout` signs the session out again. Publishing requires a prior
148
+ Login is a two-phase RFC 8628 device flow hosted by extension.dev itself: the
149
+ first call returns a user code plus `extension.dev/device`, the user approves
150
+ it there in a browser signed in to extension.dev, and the second call stores a
151
+ project-scoped token that lives at most 7 days. GitHub is federated
152
+ server-side, so no GitHub token ever lands on the developer's machine, and
153
+ there is no github.com step to send the user to. `extension_auth` with
154
+ `action: "logout"` signs the session out again. Publishing requires a prior
90
155
  successful build for the target browser.
91
156
 
157
+ Token pickup is the same on both surfaces: the MCP tool `extension_publish`
158
+ reads `EXTENSION_DEV_TOKEN` first and falls back to the stored device login,
159
+ and the `extension publish` CLI reads `--token`, then `EXTENSION_DEV_TOKEN`,
160
+ then the same stored device login that `extension_auth` wrote, so neither
161
+ needs anything after login. There is no `extension login`; device login
162
+ lives in the MCP package only.
163
+
164
+ `extension_auth` can only sign in to a project that already exists. If the
165
+ extension has no extension.dev project yet, push the source to GitHub first,
166
+ then call `extension_project_create`, then `extension_auth`. In that order,
167
+ and never the reverse: logging in first just fails against a project that is
168
+ not there. Project creation can only target an existing workspace, so when
169
+ the workspace itself is not there yet, call `extension_workspace_create`
170
+ before `extension_project_create`: it is two-phase like login (a code and a
171
+ URL a signed-in GitHub user approves, then a second call with the returned
172
+ `deviceCode`), and whoever approves the code owns the workspace.
173
+
174
+ ## Sharing a build before it ships
175
+
176
+ `extension_preview_web` with `share: true` uploads the build and returns a
177
+ link that opens the extension in a web emulator: no install, no sign-in, no
178
+ dev server on the other end. It is the way to show a build to a reviewer, a
179
+ client, or a teammate, and it is the only lane of that tool that works from
180
+ an npm install of the MCP server. Without `share: true` the tool returns a
181
+ `preview://build` deep link that resolves only against a local
182
+ preview.extension.dev dev server, which is for people developing
183
+ extension.dev itself.
184
+
185
+ Say what a share does before making one: it also serves the build as a zip,
186
+ so the recipient gets the built code, not just a rendering of it. Read the
187
+ `share` property of the response back to the user.
188
+
189
+ `extension_shares` is the other half, and the reason a share is not a
190
+ one-way door:
191
+
192
+ - `action: "list"` returns every share the token owns, live and dead, with
193
+ its `artifactId`, `previewUrl`, `zipUrl`, `revokeUrl` and expiry, so a link
194
+ whose response was lost is findable again.
195
+ - `action: "revoke"` kills one permanently, by `artifactId` or by any URL of
196
+ the share. The link you sent someone is enough to pull it back.
197
+ - `attribution.ownership` says who may revoke: `project` means any workspace
198
+ member can, `personal` means one person holds it alone, `unknown` means no
199
+ owner was disclosed. Read `attribution.credit` as credit only, never as
200
+ access.
201
+
202
+ Never share a build and leave the session without recording the link. If it
203
+ is already lost, `extension_shares` with `action: "list"` is the recovery
204
+ path, not a support ticket.
205
+
92
206
  ## Promoting releases headlessly
93
207
 
94
208
  Projects released through extension.dev promote tested builds to channels
@@ -105,3 +219,78 @@ caller passes only the build sha and target channel.
105
219
 
106
220
  Cutting a release (the version-bump PR) stays interactive by design: it
107
221
  writes to the source repo.
222
+
223
+ ## Submitting to the stores through extension.dev
224
+
225
+ `extension_submit` is the tool for store review. It is the most consequential
226
+ call in this document and the least reversible, so read this section before
227
+ using it.
228
+
229
+ What it does: submits a built commit for review at the Chrome Web Store,
230
+ Firefox AMO, Edge Add-ons and the App Store (Safari). The platform holds the
231
+ store credentials and dispatches from the project's mirror CI, so no
232
+ credential is ever an argument and no local file is uploaded. There is no
233
+ `extension` CLI equivalent.
234
+
235
+ What it is not: it does not push a build to the extension.dev platform and it
236
+ does not make a shareable link. Those are `extension_publish` and
237
+ `extension_preview_web`. When a user says "deploy", "ship" or "release", they
238
+ almost always mean publish. Reach for `extension_submit` only when the ask is
239
+ explicitly a store submission.
240
+
241
+ ```text
242
+ extension_submit
243
+ browsers: ["chrome", "firefox"] required
244
+ buildSha: <built commit sha> required; from extension_release_status
245
+ channel: stable default
246
+ dryRun: true DEFAULT. false dispatches, irreversibly.
247
+ ```
248
+
249
+ How to use it safely:
250
+
251
+ 1. **Dry run first, always.** `dryRun` defaults to `true` and dispatches
252
+ nothing. The platform checks auth, project, build and store workflow, and
253
+ the tool adds a per-store credential-health verdict on top. Trust the
254
+ per-store rows over the platform's bare preflight line, which does not
255
+ check store health.
256
+ 2. **Read every row before passing `dryRun: false`.** A row reading NOT
257
+ actionable means that store would fail. A row reading cannot be verified
258
+ means the check could not read the project's store configuration, not that
259
+ the store is fine.
260
+ 3. **`dryRun: false` is a one-way door.** It enters store review. Confirm
261
+ with the user in the same breath as calling it; never pass it because a
262
+ dry run looked good.
263
+ 4. **The build sha must already exist.** An unknown sha is rejected. Get one
264
+ from `extension_release_status`, never from `git rev-parse` and hope.
265
+ 5. **Store publish mode is invisible from here.** Whether a store is set to
266
+ draft, skip-publish or live is not readable with a CLI token, so the tool
267
+ says so instead of guessing. Check it in the console.
268
+ 6. **Safari is a paid lane.** A free workspace is refused for the App Store;
269
+ the other three stores are unaffected by that refusal.
270
+
271
+ The tool also reads the project's `STORE.md` and warns when Firefox reviewer
272
+ notes or Edge certification notes are missing. Trust that advisory: the
273
+ parser is a pinned port of the one the real submission uses, held to it by a
274
+ test that replays both over the same corpus, so a warning here means a
275
+ missing field there. One caveat it states itself: the submission reads
276
+ `STORE.md` from the project's source repository at the built commit, so an
277
+ uncommitted or unpushed edit does not travel with it.
278
+
279
+ ## Reading where a project stands
280
+
281
+ `extension_release_status` reads the project's state from the public registry
282
+ and is read-only: it dispatches nothing and promotes nothing, so it is always
283
+ safe to call.
284
+
285
+ - `include: ["releases"]` returns the release channels (channel to promoted
286
+ build sha), recent builds, and a public build-page URL for each. **This is
287
+ where a valid sha for `extension_release_promote`, `extension_submit` or
288
+ `extension_publish` comes from.**
289
+ - `include: ["stores"]` returns the per-store picture after a submission:
290
+ configured or not, the last credential health check, the last recorded
291
+ submission, and the latest review status. This is how "was it approved?"
292
+ gets answered without opening the console.
293
+
294
+ Both are included by default. It reads the logged-in project unless you pass
295
+ `workspace` and `project`. Registry state can lag the store dashboards by up
296
+ to a polling interval, so a status that has not moved yet is not a failure.
@@ -6,9 +6,9 @@ justifications, privacy disclosures, version history, and per-store notes.
6
6
  Cross-browser extensions submit to several stores; this file is the one place
7
7
  where that paperwork lives, so resubmissions never reinvent it.
8
8
 
9
- It has a second job: `extension-deploy` (and platform releases through
10
- extension.dev) read it automatically and attach the fields the store APIs
11
- accept. Everything else stays a copy-paste reference for the dashboard forms.
9
+ It has a second job: a store submission through extension.dev reads it
10
+ automatically and attaches the fields the store APIs accept. Everything else
11
+ stays a copy-paste reference for the dashboard forms.
12
12
 
13
13
  ## When to create it
14
14
 
@@ -82,8 +82,8 @@ Anything the certification team needs to test the extension.
82
82
 
83
83
  ## What gets submitted automatically
84
84
 
85
- At deploy time these fields are read from the file and sent with the
86
- submission; explicit CLI flags or config values win over the file:
85
+ At submission time these fields are read from the file and sent with the
86
+ submission; explicit flags or config values win over the file:
87
87
 
88
88
  | Store section | `###` field | Sent as |
89
89
  | --- | --- | --- |
@@ -96,6 +96,20 @@ Chrome section is dashboard-only. Its shape mirrors the `CHROMEWEBSTORE.md`
96
96
  convention other agent tooling expects, so an agent looking for that file's
97
97
  sections finds them here.
98
98
 
99
+ Two facts about where the file is read from, both of which have bitten people:
100
+
101
+ - **The submission reads `STORE.md` from the project's source repository at
102
+ the built commit**, not from the working directory. An uncommitted or
103
+ unpushed edit does not travel with the submission. Commit and push the
104
+ file, then rebuild, then submit.
105
+ - **`extension_submit` checks the local copy and warns**, and the warning is
106
+ worth acting on. Its parser is a pinned port of the one the real submission
107
+ runs, held to the original by a test that replays both implementations over
108
+ the same corpus, so "no Firefox reviewer notes" here means no Firefox
109
+ reviewer notes there. Section headings are matched the same way in both:
110
+ `## Firefox Add-ons`, `## firefox-amo` and `## AMO` all resolve to Firefox,
111
+ and the `###` field heading is matched by prefix.
112
+
99
113
  ## Maintenance rules
100
114
 
101
115
  Update `STORE.md` in the same change that makes it stale:
@@ -0,0 +1,54 @@
1
+ # Surface: content script
2
+
3
+ A content script runs inside web pages the manifest matches, in an isolated
4
+ world with the page's DOM and none of the page's JavaScript. Read this when
5
+ the extension changes or reads pages.
6
+
7
+ ## Manifest
8
+
9
+ ```json
10
+ "content_scripts": [
11
+ { "matches": ["<all_urls>"], "js": ["content/scripts.js"] }
12
+ ],
13
+ "host_permissions": ["<all_urls>"]
14
+ ```
15
+
16
+ `matches` decides where it runs; `host_permissions` is what lets it fetch
17
+ cross-origin and lets the worker reach those tabs. Narrow both to the sites
18
+ the extension is for.
19
+
20
+ ## Files the starter lays out
21
+
22
+ - `content/scripts.js`: the entry. It exports a default `initial()` that the
23
+ framework calls on injection and whose returned function it calls on
24
+ teardown and hot reload; do not call it yourself.
25
+ - `content/ContentApp.js`, `content/styles.css`: the injected UI and its
26
+ stylesheet. The starter mounts the UI inside a shadow root on a host
27
+ element marked `data-extension-root` with `all: initial`, so page CSS
28
+ cannot restyle it and its CSS cannot leak out.
29
+ - `background.js`: the worker. A content script cannot open extension pages
30
+ or call most `chrome.*` APIs; it sends a message and the worker does it.
31
+
32
+ ## What bites
33
+
34
+ - Styles imported by the script are inlined into its bundle; a stylesheet
35
+ the script fetches with `new URL("./styles.css", import.meta.url)` is the
36
+ pattern the starter uses to put CSS inside the shadow root.
37
+ - Injection happens at `document_idle` by default and once per page load.
38
+ A page that renders after load (a feed, a search result) needs a
39
+ `MutationObserver`, not a longer delay.
40
+ - Batch DOM writes with `requestAnimationFrame`. A synchronous loop over
41
+ thousands of nodes freezes the page and the site gets blamed.
42
+ - The script's memory is per page and per frame. Share state through
43
+ `chrome.storage` (declare the `storage` permission) or the worker, never
44
+ through a module variable.
45
+ - The worker may be asleep; a message wakes it, its caches are gone.
46
+
47
+ ## What proves it works
48
+
49
+ - On a matching page the host element is in the DOM and the injected UI is
50
+ visible over the page's own styles.
51
+ - The count or change the script makes agrees with the page (for links,
52
+ `document.querySelectorAll("a").length`).
53
+ - The worker's log shows the relay when the injected UI asks it for
54
+ something.
@@ -0,0 +1,49 @@
1
+ # Surface: DevTools panel
2
+
3
+ A DevTools extension adds a panel to the browser's developer tools. Read
4
+ this when the extension's main surface is a `devtools_page`.
5
+
6
+ ## Manifest
7
+
8
+ ```json
9
+ "devtools_page": "devtools/index.html"
10
+ ```
11
+
12
+ No permission is needed for the panel itself. Reading network traffic or
13
+ evaluating in the page is granted by being a DevTools page.
14
+
15
+ ## Files the starter lays out
16
+
17
+ - `devtools/index.html`, `devtools/scripts.js`: the DevTools page. It shows
18
+ nothing; its script calls
19
+ `chrome.devtools.panels.create(title, icon, "panel/index.html")`.
20
+ - `panel/index.html`, `panel/scripts.js`, `panel/styles.css`: the panel that
21
+ the person sees, created once per DevTools window.
22
+
23
+ ## What bites
24
+
25
+ - The panel exists only while DevTools is open on a tab, and it is torn down
26
+ when DevTools closes. Persist anything worth keeping in `chrome.storage`,
27
+ which needs the `storage` permission.
28
+ - DevTools pages get `chrome.devtools.*`, `chrome.runtime.*` and
29
+ `chrome.extension.*`. For anything else (tabs, windows, storage areas
30
+ beyond the basics) message the worker and let it do the call.
31
+ - `chrome.devtools.inspectedWindow.eval(code)` runs `code` in the inspected
32
+ page's own world, not the extension's, and hands back a JSON-serialisable
33
+ result plus an error object; check the error every time.
34
+ - `chrome.devtools.inspectedWindow.tabId` names the tab being inspected;
35
+ `chrome.devtools.network.onRequestFinished` streams its requests.
36
+ - A DevTools window does not count as a browser tab for `tabs.query`;
37
+ handle an empty result.
38
+
39
+ ## What proves it works
40
+
41
+ - Opening DevTools on a page shows the panel by its title, and switching to
42
+ it paints without errors. From an agent, `extension_open` with
43
+ `surface: "devtools"` (Chromium, headed or headless) opens DevTools on a
44
+ tab, shows the panel (`panel` picks a title) and returns the panel
45
+ document's url; `extension_eval` with `context: "page"` and that url
46
+ reads the panel with `chrome.devtools` available. Firefox has no protocol
47
+ command that opens its developer tools, so there the check is by hand.
48
+ - What the panel reports about the page (a title, a request, a value from
49
+ `eval`) agrees with the page it inspects.
@@ -0,0 +1,44 @@
1
+ # Surface: new tab page
2
+
3
+ A new tab override replaces the page every new tab opens on. Read this when
4
+ the extension's main surface is `chrome_url_overrides.newtab`.
5
+
6
+ ## Manifest
7
+
8
+ ```json
9
+ "chrome_url_overrides": { "newtab": "newtab/index.html" }
10
+ ```
11
+
12
+ The key is the same on Firefox. An extension may override one of `newtab`,
13
+ `history` or `bookmarks`, and only one installed extension can hold each
14
+ page.
15
+
16
+ ## Files the starter lays out
17
+
18
+ - `newtab/index.html`, `newtab/scripts.js`, `newtab/styles.css`: the page,
19
+ its script and styles.
20
+ - `background.js`: the worker, for work that should not restart on every new
21
+ tab.
22
+
23
+ ## What bites
24
+
25
+ - The page is an extension page: it has every `chrome.*` API the manifest's
26
+ permissions allow and needs no host permission to exist.
27
+ - It loads on every new tab, so it has to be fast. Remote scripts are
28
+ forbidden by Manifest V3 anyway; keep fonts and images local too, because
29
+ a remote asset that stalls is a blank new tab.
30
+ - `chrome.topSites` needs the `topSites` permission, `chrome.search.query`
31
+ needs `search`, and a plain form that navigates to a search URL needs
32
+ neither.
33
+ - Persist preferences (the clock format, the last query) in
34
+ `chrome.storage.local`, which needs the `storage` permission, and read
35
+ them before first paint to avoid a flash of defaults.
36
+ - On first run real Chrome asks whether to keep the override; that prompt
37
+ is the browser's and cannot be suppressed.
38
+
39
+ ## What proves it works
40
+
41
+ - Opening a new tab shows the page instead of the browser's own, and it
42
+ paints without errors.
43
+ - The clock or content it draws is right for the moment, and a preference
44
+ set on one new tab is honoured on the next.
@@ -0,0 +1,41 @@
1
+ # Surface: options page
2
+
3
+ The options page is where a person configures the extension. Read this when
4
+ the extension declares `options_ui`, on its own or beside another surface.
5
+
6
+ ## Manifest
7
+
8
+ ```json
9
+ "options_ui": { "page": "options/index.html", "open_in_tab": false }
10
+ ```
11
+
12
+ `open_in_tab: false` embeds the page inside the browser's extensions
13
+ management page; `true` opens it as a full tab. Firefox honours the same key.
14
+
15
+ ## Files the starter lays out
16
+
17
+ - `options/index.html`, `options/scripts.js`, `options/styles.css`: the
18
+ page, its script and styles.
19
+ - `background.js`: the worker. A content script cannot open the options
20
+ page; it sends `open-options` and the worker calls
21
+ `chrome.runtime.openOptionsPage()`.
22
+
23
+ ## What bites
24
+
25
+ - Embedded options render in an iframe with a constrained height. Set
26
+ explicit sizes on the page or the browser clips it.
27
+ - Both areas need the `storage` permission in the manifest. Save settings
28
+ to `chrome.storage.sync` when they should follow the person across
29
+ devices and to `local` otherwise; `sync` has small quotas and
30
+ per-minute write limits, so never write on every keystroke.
31
+ - Other contexts learn about a change through `chrome.storage.onChanged`,
32
+ never by re-reading on a timer.
33
+ - `chrome.runtime.openOptionsPage()` works from the worker and from
34
+ extension pages, not from a content script.
35
+
36
+ ## What proves it works
37
+
38
+ - The page opens from the extensions list, or from the worker on request,
39
+ and paints without errors.
40
+ - A setting changed here is visible to the surface that reads it, on the
41
+ next event, without a reload.