install
source · Clone the upstream repo
git clone https://github.com/ComeOnOliver/skillshub
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ComeOnOliver/skillshub "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/pproenca/dot-skills/wxt-browser-extensions" ~/.claude/skills/comeonoliver-skillshub-wxt-browser-extensions && rm -rf "$T"
manifest:
skills/pproenca/dot-skills/wxt-browser-extensions/SKILL.mdsource content
Community WXT Browser Extensions Best Practices
Comprehensive performance optimization guide for WXT browser extension development. Contains 49 rules across 8 categories, prioritized by impact to guide automated refactoring and code generation. Updated for WXT v0.20+.
When to Apply
Reference these guidelines when:
- Writing new WXT browser extension code
- Implementing service worker background scripts
- Injecting content scripts into web pages
- Setting up messaging between extension contexts
- Configuring manifest permissions and resources
Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Service Worker Lifecycle | CRITICAL | |
| 2 | Content Script Injection | CRITICAL | |
| 3 | Messaging Architecture | HIGH | |
| 4 | Storage Patterns | HIGH | |
| 5 | Bundle Optimization | MEDIUM-HIGH | |
| 6 | Manifest Configuration | MEDIUM | |
| 7 | UI Performance | MEDIUM | |
| 8 | TypeScript Patterns | LOW-MEDIUM | |
Quick Reference
1. Service Worker Lifecycle (CRITICAL)
- Register listeners synchronously to prevent missed eventssvc-register-listeners-synchronously
- Use storage instead of in-memory statesvc-avoid-global-state
- Keep service worker alive for long operationssvc-keep-alive-patterns
- Handle install and update lifecycle eventssvc-handle-install-update
- Use offscreen documents for DOM operationssvc-offscreen-documents
- Use declarative rules for network blockingsvc-declarative-net-request
2. Content Script Injection (CRITICAL)
- Place runtime code inside main() functioninject-use-main-function
- Select ISOLATED or MAIN world appropriatelyinject-choose-correct-world
- Configure appropriate runAt timinginject-run-at-timing
- Handle context invalidation on updateinject-use-ctx-invalidated
- Use runtime registration for conditional injectioninject-dynamic-registration
- Configure allFrames for iframe handlinginject-all-frames
- Handle SPA navigation with wxt:locationchangeinject-spa-navigation
3. Messaging Architecture (HIGH)
- Use @webext-core/messaging for type-safe protocolsmsg-type-safe-messaging
- Return true for async message handlers (raw API)msg-return-true-for-async
- Use tabs.sendMessage for content scriptsmsg-use-tabs-sendmessage
- Use ports for streaming communicationmsg-use-ports-for-streams
- Handle missing message receiversmsg-handle-no-receiver
- Prevent circular message loopsmsg-avoid-circular-messages
4. Storage Patterns (HIGH)
- Use storage.defineItem for type-safe accessstore-use-define-item
- Select appropriate storage areastore-choose-storage-area
- Group related data into single defineItemstore-batch-operations
- Use watch() for reactive updatesstore-watch-for-changes
- Handle storage quota errorsstore-handle-quota-errors
- Use versioning for schema migrationsstore-versioned-migrations
5. Bundle Optimization (MEDIUM-HIGH)
- Split code by entrypointbundle-split-entrypoints
- Analyze and monitor bundle sizebundle-analyze-size
- Use direct imports for icon librariesbundle-tree-shake-icons
- Load WASM dynamicallybundle-externalize-wasm
- Minimize content script sizebundle-minify-content-scripts
6. Manifest Configuration (MEDIUM)
- Request minimal permissionsmanifest-minimal-permissions
- Use optional permissions progressivelymanifest-use-optional-permissions
- Scope web accessible resourcesmanifest-web-accessible-resources
- Configure CSP correctlymanifest-content-security-policy
- Support multiple browsersmanifest-cross-browser-compatibility
7. UI Performance (MEDIUM)
- Use Shadow DOM for injected UIui-use-shadow-dom
- Defer popup rendering until neededui-defer-rendering
- Clean up UI on unmountui-cleanup-on-unmount
- Preserve sidepanel stateui-sidepanel-persistence
- Use iframe for complex UIui-position-fixed-iframe
- Batch DOM reads and writesui-avoid-layout-thrashing
8. TypeScript Patterns (LOW-MEDIUM)
- Use #imports virtual module and auto-importsts-use-imports-module
- Use browser namespace over chromets-use-browser-not-chrome
- Type entrypoint options explicitlyts-type-entrypoint-options
- Augment types for missing APIsts-augment-browser-types
- Enable strict null checksts-strict-null-checks
- Use import.meta for build infots-import-meta-env
- Avoid any type in handlersts-avoid-any
- Use path aliases for importsts-path-aliases
How to Use
Read individual reference files for detailed explanations and code examples:
- Section definitions - Category structure and impact levels
- Rule template - Template for adding new rules
Reference Files
| File | Description |
|---|---|
| references/_sections.md | Category definitions and ordering |
| assets/templates/_template.md | Template for new rules |
| metadata.json | Version and reference information |