← 返回 Skills 市场
tenequm

Chrome Extension Development with WXT

作者 Misha Kolesnik · GitHub ↗ · v1.1.0 · MIT-0
cross-platform ✓ 安全检测通过
121
总下载
0
收藏
0
当前安装
1
版本数
在 OpenClaw 中安装
/install chrome-extension-wxt
功能描述
Build Chrome extensions using WXT framework with TypeScript, React, Vue, or Svelte. Use when creating browser extensions, developing cross-browser add-ons, o...
使用说明 (SKILL.md)

Chrome Extension Development with WXT

Build modern, cross-browser extensions using WXT - the next-generation framework that supports Chrome, Firefox, Edge, Safari, and all Chromium browsers with a single codebase.

When to Use This Skill

Use this skill when:

  • Creating a new Chrome/browser extension
  • Setting up WXT development environment
  • Building extension features (popup, content scripts, background scripts)
  • Implementing cross-browser compatibility
  • Working with Manifest V3 (mandatory standard as of 2025, V2 deprecated)
  • Integrating React 19, Vue, Svelte, or Solid with extensions

Quick Start Workflow

1. Initialize WXT Project

# Create new project with framework of choice
npm create wxt@latest

# Or with specific template
npm create wxt@latest -- --template react-ts
npm create wxt@latest -- --template vue-ts
npm create wxt@latest -- --template svelte-ts

2. Project Structure

WXT uses file-based conventions:

project/
├── entrypoints/              # Auto-discovered entry points
│   ├── background.ts         # Service worker
│   ├── content.ts           # Content script
│   ├── popup.html           # Popup UI
│   └── options.html         # Options page
├── components/              # Auto-imported UI components
├── utils/                   # Auto-imported utilities
├── public/                  # Static assets
│   └── icon/               # Extension icons
├── wxt.config.ts           # Configuration
└── package.json

3. Development Commands

npm run dev              # Start dev server with HMR
npm run build           # Production build
npm run zip             # Package for store submission

Core Entry Points

WXT recognizes entry points by filename in entrypoints/ directory:

Background Script (Service Worker)

// entrypoints/background.ts
export default defineBackground({
  type: 'module',
  persistent: false,

  main() {
    // Listen for extension events
    browser.action.onClicked.addListener((tab) => {
      console.log('Extension clicked', tab);
    });

    // Handle messages
    browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
      // Handle message
      sendResponse({ success: true });
      return true; // Keep channel open for async
    });
  },
});

Content Script

// entrypoints/content.ts
export default defineContentScript({
  matches: ['*://*.example.com/*'],
  runAt: 'document_end',

  main(ctx) {
    // Content script logic
    console.log('Content script loaded');

    // Create UI
    const ui = createShadowRootUi(ctx, {
      name: 'my-extension-ui',
      position: 'inline',
      anchor: 'body',

      onMount(container) {
        // Mount React/Vue component
        const root = ReactDOM.createRoot(container);
        root.render(\x3CApp />);
      },
    });

    ui.mount();
  },
});

Popup UI

// entrypoints/popup/main.tsx
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';

ReactDOM.createRoot(document.getElementById('root')!).render(
  \x3CReact.StrictMode>
    \x3CApp />
  \x3C/React.StrictMode>
);
\x3C!-- entrypoints/popup/index.html -->
\x3C!DOCTYPE html>
\x3Chtml>
\x3Chead>
  \x3Cmeta charset="UTF-8">
  \x3Ctitle>Extension Popup\x3C/title>
\x3C/head>
\x3Cbody>
  \x3Cdiv id="root">\x3C/div>
  \x3Cscript type="module" src="./main.tsx">\x3C/script>
\x3C/body>
\x3C/html>

Configuration

Basic wxt.config.ts

import { defineConfig } from 'wxt';

export default defineConfig({
  // Framework integration
  modules: ['@wxt-dev/module-react'],

  // Manifest configuration
  manifest: {
    name: 'My Extension',
    description: 'Extension description',
    permissions: ['storage', 'activeTab'],
    host_permissions: ['*://example.com/*'],
  },

  // Browser target
  browser: 'chrome', // or 'firefox', 'edge', 'safari'
});

Common Patterns

Type-Safe Storage

// utils/storage.ts
import { storage } from 'wxt/storage';

export const storageHelper = {
  async get\x3CT>(key: string): Promise\x3CT | null> {
    return await storage.getItem\x3CT>(`local:${key}`);
  },

  async set\x3CT>(key: string, value: T): Promise\x3Cvoid> {
    await storage.setItem(`local:${key}`, value);
  },

  watch\x3CT>(key: string, callback: (newValue: T | null) => void) {
    return storage.watch\x3CT>(`local:${key}`, callback);
  },
};

Type-Safe Messaging

// utils/messaging.ts
interface Messages {
  'get-data': {
    request: { key: string };
    response: { value: any };
  };
}

export async function sendMessage\x3CK extends keyof Messages>(
  type: K,
  payload: Messages[K]['request']
): Promise\x3CMessages[K]['response']> {
  return await browser.runtime.sendMessage({ type, payload });
}

Script Injection

// Inject script into page context
import { injectScript } from 'wxt/client';

await injectScript('/injected.js', {
  keepInDom: false,
});

Building & Deployment

Production Build

# Build for specific browser
npm run build -- --browser=chrome
npm run build -- --browser=firefox

# Create store-ready ZIP
npm run zip
npm run zip -- --browser=firefox

Multi-Browser Build

# Build for all browsers
npm run zip:all

Output: .output/my-extension-{version}-{browser}.zip

Modern Stacks (2025)

Popular technology combinations for building Chrome extensions:

WXT + React + Tailwind + shadcn/ui

Most popular stack in 2025. Combines utility-first styling with pre-built accessible components.

npm create wxt@latest -- --template react-ts
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
npx shadcn@latest init

Best for: Modern UIs with consistent design system Example: https://github.com/imtiger/wxt-react-shadcn-tailwindcss-chrome-extension

WXT + React + Mantine UI

Complete component library with 100+ components and built-in dark mode.

npm create wxt@latest -- --template react-ts
npm install @mantine/core @mantine/hooks

Best for: Feature-rich extensions needing complex components Example: https://github.com/ongkay/WXT-Mantine-Tailwind-Browser-Extension

WXT + React + TypeScript (Minimal)

Clean setup for custom designs without UI library dependencies.

npm create wxt@latest -- --template react-ts

Best for: Simple extensions or highly custom designs

Advanced Topics

For detailed information on advanced topics, see the reference files:

  • React Integration: See references/react-integration.md for complete React setup, hooks, state management, and popular UI libraries
  • Chrome APIs: See references/chrome-api.md for comprehensive Chrome Extension API reference with examples
  • Chrome 140+ Features: See references/chrome-140-features.md for latest Chrome Extension APIs (sidePanel.getLayout(), etc.)
  • WXT API: See references/wxt-api.md for complete WXT framework API documentation
  • Best Practices: See references/best-practices.md for security, performance, and architecture patterns

Troubleshooting

Common issues and solutions:

  1. Module not found errors: Ensure modules are installed and properly imported
  2. CSP violations: Update content_security_policy in manifest
  3. Hot reload not working: Check browser console for errors
  4. Storage not persisting: Use storage.local or storage.sync correctly

For detailed troubleshooting, see references/troubleshooting.md

Resources

Official Documentation

Bundled Resources

  • scripts/: Helper utilities for common extension tasks
  • references/: Detailed documentation for advanced features
  • assets/: Starter templates and example components

Use these resources as needed when building your extension.

安全使用建议
This skill is an instruction-only developer guide for WXT-based extensions and appears coherent with that purpose. It does not request credentials or install code on its own, but follow these precautions before using the workflow it describes: - Review package sources/templates before running npm create/npm install — npm packages bring third-party code into your project. Prefer official wxt templates or inspect the template repository. - Check manifest permissions generated for the extension. Avoid broad host_permissions or <all_urls> unless strictly needed; excessive permissions increase risk to users. - Be careful with defineWebExtConfig options like keepProfileChanges and chromiumProfile/firefoxProfile: pointing to your real browser profile or enabling persistent changes will expose cookies, logins, and stored data to the test extension. Use throwaway profiles or CI-specific profiles when testing. - Do not hardcode API keys or secrets in source; follow the references' advice to store secrets in browser.storage and protect them appropriately. - When packaging or publishing, inspect the final build (.zip) and manifest for unexpected permissions or network endpoints. - If you need higher assurance, run builds and template installs inside an isolated environment (container/VM) and audit node_modules or run dependency-scanning tools. Overall, the skill is internally consistent and useful for extension development; the main risks are the normal developer-side privacy and supply-chain concerns inherent to npm-based web development, not anything anomalous in the skill itself.
功能分析
Type: OpenClaw Skill Name: chrome-extension-wxt Version: 1.1.0 The skill bundle provides a comprehensive development environment and documentation for building Chrome extensions using the WXT framework. It includes detailed API references, React integration guides, and security best practices (e.g., CSP and input validation in best-practices.md). No evidence of data exfiltration, malicious execution, or prompt injection was found; all code snippets and instructions are consistent with legitimate extension development.
能力评估
Purpose & Capability
Name/description, examples, and runtime instructions all align: the skill documents how to scaffold, develop, build, and package WXT-based browser extensions. It does not request unrelated credentials, binaries, or system paths.
Instruction Scope
SKILL.md and reference docs stay within extension development scope. Notable caution: examples and defineWebExtConfig encourage using persistent browser profiles (keepProfileChanges, chromiumProfile/firefoxProfile) and custom browser binary paths, which — if used with real personal profiles — can expose cookies, sessions, and other sensitive data. The skill does not instruct reading unrelated system files, but developer actions it suggests can have privacy implications.
Install Mechanism
Instruction-only: no install spec and no code files executed by the platform. The workflow relies on npm tooling (npm create, npm install) which is expected for JavaScript/TypeScript extension projects; this is proportional to the stated purpose.
Credentials
The skill declares no required environment variables, credentials, or config paths. The only potentially sensitive items are developer-specified local paths (browser binaries, profile directories) and optional manifest permissions; these are typical for local extension development and are not requested by the skill itself.
Persistence & Privilege
The skill is not always-enabled and does not request persistent platform privileges. It does not modify other skills or global agent settings. Suggestions in docs to persist profile data are development options, not built-in privileges of the skill.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install chrome-extension-wxt
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /chrome-extension-wxt 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.1.0
Initial publish of chrome-extension-wxt 1.1.0. Changes: - bootstrap publish of current skill contents
元数据
Slug chrome-extension-wxt
版本 1.1.0
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 1
常见问题

Chrome Extension Development with WXT 是什么?

Build Chrome extensions using WXT framework with TypeScript, React, Vue, or Svelte. Use when creating browser extensions, developing cross-browser add-ons, o... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 121 次。

如何安装 Chrome Extension Development with WXT?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install chrome-extension-wxt」即可一键安装,无需额外配置。

Chrome Extension Development with WXT 是免费的吗?

是的,Chrome Extension Development with WXT 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

Chrome Extension Development with WXT 支持哪些平台?

Chrome Extension Development with WXT 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 Chrome Extension Development with WXT?

由 Misha Kolesnik(@tenequm)开发并维护,当前版本 v1.1.0。

💬 留言讨论