@extension.dev/skill 1.3.0 → 1.4.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.
- package/.claude-plugin/marketplace.json +23 -9
- package/CHANGELOG.md +258 -0
- package/README.md +51 -32
- package/package.json +8 -6
- package/skills/{extension-dev → browser-extension}/SKILL.md +132 -79
- package/skills/browser-extension/references/api-gotchas.md +213 -0
- package/skills/{extension-dev → browser-extension}/references/cross-browser.md +75 -21
- package/skills/{extension-dev → browser-extension}/references/debugging.md +60 -4
- package/skills/{extension-dev → browser-extension}/references/migrating-from-frameworks.md +1 -1
- package/skills/{extension-dev → browser-extension}/references/migrating.md +10 -4
- package/skills/{extension-dev → browser-extension}/references/project-structure.md +25 -3
- package/skills/{extension-dev → browser-extension}/references/publishing.md +16 -3
- package/skills/{extension-dev → browser-extension}/references/store-md.md +51 -5
- package/skills/{extension-dev → browser-extension}/references/surface-content.md +6 -0
- package/skills/{extension-dev → browser-extension}/references/surface-options.md +4 -0
- package/.claude-plugin/plugin.json +0 -24
- package/skills/extension-dev/references/api-gotchas.md +0 -107
- /package/skills/{extension-dev → browser-extension}/references/surface-devtools.md +0 -0
- /package/skills/{extension-dev → browser-extension}/references/surface-newtab.md +0 -0
- /package/skills/{extension-dev → browser-extension}/references/surface-popup.md +0 -0
- /package/skills/{extension-dev → browser-extension}/references/surface-sidepanel.md +0 -0
- /package/skills/{extension-dev → browser-extension}/references/templates.md +0 -0
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
# Runtime API Gotchas
|
|
2
|
-
|
|
3
|
-
The WebExtension APIs fail silently in specific, repeatable ways. This file
|
|
4
|
-
collects the ones that cost the most debugging time, with the reason behind
|
|
5
|
-
each so the fix generalizes.
|
|
6
|
-
|
|
7
|
-
## Service worker lifecycle (Chromium MV3)
|
|
8
|
-
|
|
9
|
-
The background service worker is killed after roughly 30 seconds of
|
|
10
|
-
inactivity and restarted on the next event. Consequences:
|
|
11
|
-
|
|
12
|
-
- Module-level variables are wiped between events. Persist every piece of
|
|
13
|
-
state to `chrome.storage.local` (or `session`) and re-read it on wake.
|
|
14
|
-
- Register all event listeners synchronously at the top level of the worker.
|
|
15
|
-
A listener registered inside an async callback may not exist when the
|
|
16
|
-
worker restarts, so the event is dropped.
|
|
17
|
-
- Long-lived connections (WebSocket, ports) die with the worker. Use alarms
|
|
18
|
-
(`chrome.alarms`) to re-establish, or an offscreen document when a DOM or
|
|
19
|
-
long-lived context is genuinely required.
|
|
20
|
-
- Firefox MV2 background scripts are persistent, which can mask these bugs
|
|
21
|
-
during cross-browser testing. Test state loss on Chromium specifically.
|
|
22
|
-
- `ReferenceError: browser is not defined` in a **production** Chrome build
|
|
23
|
-
(but not in dev) means the build ran without the polyfill: it defaults on
|
|
24
|
-
for `dev`/`start` but off for `build`. Rebuild with
|
|
25
|
-
`npm run build -- --polyfill` or switch the code to `chrome.*`.
|
|
26
|
-
|
|
27
|
-
## Storage
|
|
28
|
-
|
|
29
|
-
- `chrome.storage.local` is the default for persistent data and works
|
|
30
|
-
cross-browser (Firefox supports the `chrome.*` namespace natively).
|
|
31
|
-
- `chrome.storage.session` survives worker restarts but not browser restarts;
|
|
32
|
-
good for ephemeral, session-scoped state you would not persist to disk.
|
|
33
|
-
- `chrome.storage.sync` has small quotas and per-minute write limits; never
|
|
34
|
-
put high-frequency writes there.
|
|
35
|
-
- Storage APIs are async. Reading "right after" a write in another context is
|
|
36
|
-
a race; listen to `chrome.storage.onChanged` instead.
|
|
37
|
-
|
|
38
|
-
## Permissions and gestures
|
|
39
|
-
|
|
40
|
-
- `activeTab` is granted only by a genuine user gesture: toolbar click,
|
|
41
|
-
context menu item, keyboard command, or omnibox entry. A button inside a
|
|
42
|
-
side panel or popup page is not a gesture for this purpose, and programmatic
|
|
43
|
-
event replay never is. If a flow needs host access without a gesture,
|
|
44
|
-
request explicit host permissions instead.
|
|
45
|
-
- `tab.url`, `tab.title`, and `tab.favIconUrl` are silently `undefined`
|
|
46
|
-
without the `tabs` permission (or an applicable host permission). No error
|
|
47
|
-
fires; the data is just missing.
|
|
48
|
-
- `scripting.executeScript` needs `scripting` plus host access for the target
|
|
49
|
-
origin (or an active `activeTab` grant).
|
|
50
|
-
|
|
51
|
-
## Action, windows, tabs
|
|
52
|
-
|
|
53
|
-
- `chrome.action` is undefined unless the manifest has an `"action"` key,
|
|
54
|
-
even an empty `{}`.
|
|
55
|
-
- `chrome.windows` has no `query()` method. Use `getAll()`, `getCurrent()`,
|
|
56
|
-
or `getLastFocused()`. (`chrome.tabs.query()` exists; the asymmetry trips
|
|
57
|
-
people up.)
|
|
58
|
-
- `chrome.tabs.query({ active: true, currentWindow: true })` returns an array;
|
|
59
|
-
destructure the first element and handle the empty case (DevTools windows,
|
|
60
|
-
for instance).
|
|
61
|
-
|
|
62
|
-
## Messaging
|
|
63
|
-
|
|
64
|
-
- Use `async`/`await` end to end. In an `onMessage` listener, return `true`
|
|
65
|
-
only if you really will call `sendResponse` later; returning `true` and
|
|
66
|
-
never responding leaves the sender hanging.
|
|
67
|
-
- A rejected promise or thrown error inside a listener surfaces on the sender
|
|
68
|
-
as "message port closed before a response was received". Wrap handlers in
|
|
69
|
-
try/catch and always respond.
|
|
70
|
-
- Content script to background messaging works when the worker is asleep (the
|
|
71
|
-
message wakes it), but the worker's in-memory caches are gone; see the
|
|
72
|
-
lifecycle section.
|
|
73
|
-
|
|
74
|
-
## Content scripts
|
|
75
|
-
|
|
76
|
-
- Batch DOM updates with `requestAnimationFrame`. Synchronous loops that
|
|
77
|
-
mutate the DOM wedge the host page's main thread, and on heavy pages that
|
|
78
|
-
shows up as the page freezing, which gets blamed on the site, not the
|
|
79
|
-
extension.
|
|
80
|
-
- Mark injected roots (`data-extension-root` or similar) so probes and
|
|
81
|
-
debugging tools can verify injection deterministically.
|
|
82
|
-
- CSS injected by content scripts leaks both ways. Scope aggressively or use
|
|
83
|
-
Shadow DOM for nontrivial UI.
|
|
84
|
-
|
|
85
|
-
## UI surfaces
|
|
86
|
-
|
|
87
|
-
- Side panel (Chromium): requires `sidePanel` permission and an explicit open
|
|
88
|
-
trigger. See the cross-browser reference for the working pattern.
|
|
89
|
-
- DevTools pages: panel URLs are resolved relative to the extension root, not
|
|
90
|
-
the devtools HTML file's directory.
|
|
91
|
-
- Offscreen documents (Chromium): only `chrome.runtime` messaging plus
|
|
92
|
-
standard Web APIs are available. No `chrome.tabs`, `chrome.downloads`,
|
|
93
|
-
`chrome.action`, etc. Route privileged calls through the worker.
|
|
94
|
-
- Notifications: `iconUrl` must point at a bundled file or a data URL built at
|
|
95
|
-
runtime. A typo'd path fails silently on some platforms.
|
|
96
|
-
|
|
97
|
-
## Code execution and CSP
|
|
98
|
-
|
|
99
|
-
- MV3 forbids remote code and `eval()` in extension pages, and the
|
|
100
|
-
extension-pages CSP (`script-src 'self'`) also blocks `blob:` script URLs
|
|
101
|
-
and inline scripts. `srcdoc` iframes inherit the embedding page's CSP, so
|
|
102
|
-
they are not an escape hatch either. The supported path for dynamic code
|
|
103
|
-
is a sandboxed page (`"sandbox"` manifest key), which may use `eval()`;
|
|
104
|
-
embed it as an iframe and message results across the boundary.
|
|
105
|
-
- User-visible feedback matters for background actions: after a context menu
|
|
106
|
-
click or command, confirm with a badge, notification, or toast. Silent
|
|
107
|
-
success is indistinguishable from silent failure, for users and for tests.
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|