chrome-extension

GitHub 作者 LeoYeAI/openclaw-master-skills

安装 / 下载方式

TotalClaw CLI推荐
totalclaw skills install shop:github:LeoYeAI~openclaw-master-skills~chrome-extension
cURL直接下载,无需登录
curl -fsSL https://skills.taituai.com/api/skills/github%3ALeoYeAI~openclaw-master-skills~chrome-extension/file -o chrome-extension.md
---
name: chrome-extension
description: "Comprehensive guide for building Chrome extensions with Manifest V3. Use this skill whenever the user mentions Chrome extension, browser extension, manifest.json, content script, service worker (in extension context), popup, side panel, chrome.runtime, chrome.tabs, chrome.storage, chrome.scripting, background script, MV3, Manifest V3, or any Chrome extension API. Also trigger when the user wants to inject scripts into web pages, communicate between page and background, bypass CSP from a content script, build an RPC layer over chrome messaging, or publish to the Chrome Web Store. Covers both new extension projects and adding features to existing ones. Do NOT use for framework-specific questions.
user-invocable: true
license: MIT
compatibility: Designed for Claude Code or similar AI coding agents. Requires git, node.
metadata:
  author: samber
  version: "1.0.0"
  openclaw:
    emoji: "📝"
    homepage: https://github.com/samber/cc-skills
    requires:
      bins:
        - git
        - node
        - npm
allowed-tools: Read Edit Write Glob Grep Bash(git:*) Bash(gh:*) Bash(npm:*)
---

# Chrome Extension Development (Manifest V3)

This skill covers everything needed to build, debug, and publish Chrome extensions with MV3.
It is organized as a routing document: read this file first to understand the architecture and decision points, then load the relevant reference file for implementation details.

## Reference files

Read only the reference files relevant to the current task. Each file is self-contained.

| File                                     | When to read                                                                                      |
| ---------------------------------------- | ------------------------------------------------------------------------------------------------- |
| `references/manifest-v3.md`              | Setting up or modifying manifest.json, configuring icons, versioning                              |
| `references/service-worker.md`           | Background logic, lifecycle, state persistence, alarms, events                                    |
| `references/content-scripts.md`          | Injecting code into pages, isolated/main world, dynamic injection, SPA handling, orphaning        |
| `references/messaging-rpc.md`            | Communication between any contexts, typed protocols, RPC layer, async handler patterns            |
| `references/ui-surfaces.md`              | Popup, options page, side panel, context menus, commands, notifications, omnibox, devtools panel  |
| `references/storage.md`                  | chrome.storage (local/sync/session), quotas, reactive patterns, framework hooks                   |
| `references/network-csp.md`              | HTTP requests from content scripts, CSP bypass relay, declarativeNetRequest, offscreen docs, CORS |
| `references/permissions.md`              | Required/optional permissions, host permissions, activeTab, runtime request flow                  |
| `references/web-accessible-resources.md` | Exposing extension files to web pages, security implications                                      |
| `references/typescript-build.md`         | TypeScript setup, project structure, build tools comparison, bundling                             |
| `references/publishing.md`               | Chrome Web Store submission, review process, rejection reasons, updates, privacy policy           |
| `references/execution-contexts.md`       | Communication flow diagrams, per-context capabilities/limits, choosing the right messaging method |
| `references/debugging-mistakes.md`       | DevTools for extensions, testing SW termination, common gotchas, error patterns                   |

## Architecture overview

A Chrome extension has up to 5 execution contexts that communicate via message passing:

```
┌──────────────────────────────────────────────────────────┐
│ Extension Process                                        │
│  ┌─────────────────┐  ┌───────┐  ┌─────────┐  ┌──────┐ │
│  │ Service Worker   │  │ Popup │  │ Options │  │ Side │ │
│  │ (background)     │  │       │  │  Page   │  │Panel │ │
│  │ - No DOM         │  │ Full  │  │  Full   │  │ Full │ │
│  │ - Ephemeral      │  │ DOM   │  │  DOM    │  │ DOM  │ │
│  │ - All chrome.*   │  │ All   │  │  All    │  │ All  │ │
│  │   APIs           │  │ APIs  │  │  APIs   │  │ APIs │ │
│  └────────┬─────────┘  └───┬───┘  └────┬────┘  └──┬───┘ │
│           │ chrome.runtime.sendMessage / connect   │     │
└───────────┼────────────────┼───────────┼──────────┼──────┘
            │                │           │          │
    chrome.tabs.sendMessage  │           │          │
            │                │           │          │
┌───────────┼────────────────┼───────────┼──────────┼──────┐
│ Web Page  ▼                                              │
│  ┌──────────────────┐    ┌──────────────────┐            │
│  │ Content Script    │    │ Main World Script │            │
│  │ (isolated world)  │◄──►│ (page context)    │            │
│  │ - Shared DOM      │    │ - Shared DOM      │            │
│  │ - Own JS scope    │    │ - Page JS scope   │            │
│  │ - chrome.runtime  │    │ - No chrome.* API │            │
│  │ - chrome.storage  │    │ - Full page access│            │
│  │ - Subject to CSP  │    │ - Subject to CSP  │            │
│  │   (network only)  │    │   (fully)         │            │
│  └──────────────────┘    └──────────────────┘            │
│           ▲ window.postMessage                           │
│           │ (through shared DOM)                         │
└──────────────────────────────────────────────────────────┘
```

### Communication flows (labeled channels)

```
┌───────────────────────────────────────────────────────────────────────────┐
│ Extension Process                                                         │
│                                                                           │
│  ┌─────────────────┐  chrome.runtime   ┌───────┐  ┌─────────┐  ┌──────┐ │
│  │ Service Worker   │◄─.sendMessage()──│ Popup │  │ Options │  │ Side │ │
│  │ (background)     │◄─.connect()──────│       │  │  Page   │  │Panel │ │
│  │                  │                  └───────┘  └─────────┘  └──────┘ │
│  │ - No DOM         │  ┌────────────────────────────────────────────┐   │
│  │ - Ephemeral 30s  │  │ SW cannot push to these pages.             │   │
│  │ - All chrome.*   │  │ Use: ports (.connect) or storage.onChanged │   │
│  └────────┬─────────┘  └────────────────────────────────────────────┘   │
│           │                                                              │
│  chrome.storage.onChanged ◄── fires across ALL contexts simultaneously  │
│                                                                           │
└───────────┼──────────────────────────────────────────────────────────────┘
            │ chrome.tabs.sendMessage(tabId, ...) [SW must know tabId]
            │
┌───────────┼──────────────────────────────────────────────────────────────┐
│ Web Page  ▼                                                              │
│  ┌──────────────────┐  window.postMessage  ┌──────────────────┐         │
│  │ Content Script    │◄───────────────────►│ Main World Script │         │
│  │ (isolated world)  │  Custom DOM events  │ (page context)    │         │
│  │                   │                     │                   │         │
│  │ chrome.runtime ───┼── to/from SW        │ No chrome.* APIs  │         │
│  │ chrome.storage    │                     │ Full page JS      │         │
│  │ Shared DOM        │                     │ Shared DOM        │         │
│  │ Page CSP (network)│                     │ Page CSP (full)   │         │
│  └──────────────────┘                     └──────────────────┘         │
└──────────────────────────────────────────────────────────────────────────┘
```

For detailed flow diagrams (three-layer bridge, cross-extension, storage broadcast) and a per-context bre