Xpersona
C

chrome-extension

CLAWHUB · Unverified

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.

62
Rank
84
Safety
1.2k
Downloads

About

What it does, and when to use it.

Capability contract not published. No trust telemetry is available yet. 1.2K downloads reported by the source. Last updated 10/10/2026.

Avoid when

  • Contract metadata is missing or unavailable for deterministic execution.

Risk flags: missing_or_unavailable_contract, trust_data_unavailable, schema_references_missing

Install and run

Setup complexity: low.

clawhub skill install s173arkhs3131fq5jf769qq75583hdgt:chrome-extension
  1. Install using `clawhub skill install s173arkhs3131fq5jf769qq75583hdgt:chrome-extension` in an isolated environment before connecting it to live workloads.
  2. No published capability contract is available yet, so validate auth and request/response behavior manually.
  3. Review the upstream CLAWHUB listing at https://clawhub.ai/samber/chrome-extension before using production credentials.

Contract: missing

curl -s "https://www.xpersona.co/api/v1/agents/clawhub-samber-chrome-extension/snapshot"

Run-check

$0.02 USD

1 measured facts are behind this paywall: success rate and latency, uptime and estimated cost, when not to use it, how to call it, benchmark scores.

Agents pay $0.02 in USDC. A card payment is $0.50, the smallest a card allows.

Documentation

CLAWHUB

144,338 characters of source documentation, loaded on request.

Extracted files

5 files captured from the source.

SKILL.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, Codex or similar harness. Requires git, node.
metadata:
  author: samber
  version: "1.1.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:*) AskUserQuestion
---

# 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/lim

_meta.json

{
  "ownerId": "kn72rhnkwjfeex9wr1n7y24qa983cjn3",
  "slug": "chrome-extension",
  "version": "1.1.0",
  "publishedAt": 1787232275555
}

references/content-scripts.md

# Content Scripts Reference

## Table of contents

1. Isolated world vs main world
2. Static declaration (manifest)
3. Dynamic/programmatic injection
4. Injection timing (run_at)
5. SPA navigation handling
6. Content script orphaning on extension update
7. CSS injection
8. Communication between worlds

## 1. Isolated world vs main world

Content scripts default to the **isolated world**: a separate JavaScript execution environment that shares the page's DOM but not its JavaScript objects.

| Capability                                | Isolated world | Main world |
| ----------------------------------------- | -------------- | ---------- |
| Read/modify DOM                           | Yes            | Yes        |
| Access page JS variables (`window.myApp`) | No             | Yes        |
| Intercept page `fetch`/`XMLHttpRequest`   | No             | Yes        |
| Access `chrome.runtime`                   | Yes            | No         |
| Access `chrome.storage`                   | Yes            | No         |
| Access `chrome.i18n`                      | Yes            | No         |
| Subject to page CSP (scripts)             | No             | Yes        |
| Subject to page CSP (network)             | Yes            | Yes        |
| Page can see script variables             | No             | Yes        |
| Can modify `window` prototypes            | No             | Yes        |

### When to use main world

- Intercepting/monkey-patching page functions (`fetch`, `XMLHttpRequest`, custom APIs)
- Reading page JavaScript state (SPA router state, React fiber tree)
- Setting `window` globals for page scripts to consume
- Overriding built-in APIs for instrumentation

### When to use isolated world (default)

- Everything else. It's safer: the page can't tamper with your code, and you retain chrome.\* API access.

## 2. Static declaration (manifest)

```json
{
  "content_scripts": [
    {
      "matches": ["https://*.example.com/*"],
      "exclude_matches": ["https://example.com/admin/*"],
      "js": ["content/main.js", "content/utils.js"],
      "css": ["content/styles.css"],
      "run_at": "document_idle",
      "all_frames": false,
      "match_about_blank": false,
      "world": "ISOLATED"
    }
  ]
}
```

Scripts in `js` array execute in order. CSS in `css` array is injected before any DOM.

## 3. Dynamic/programmatic injection

Use `chrome.scripting` (requires `"scripting"` permission) for on-demand injection. This is preferred over static when injection depends on user action or runtime conditions.

### Execute a function

```typescript
// Inject a function directly (serialized, no closure access)
chrome.scripting.executeScript({
  target: { tabId, allFrames: false },
  func: (color: string) => {
    document.body.style.backgroundColor = color;
  },
  args: ["yellow"],
  world: "ISOLATED", // or 'MAIN'
});
```

### Execute a file

```typescript
chrome.scripting.executeScript({
  target: { tabId },
  files: ["content/injected.js"],
});
```

references/debugging-mistakes.md

# Debugging and Common Mistakes Reference

## Table of contents

1. DevTools for each extension context
2. Testing service worker termination
3. Common error messages and fixes
4. The top 10 MV3 mistakes
5. Performance pitfalls
6. Testing strategies

## 1. DevTools for each extension context

Each extension context has its own DevTools instance:

| Context | How to open DevTools |
| --- | --- |
| Service worker | chrome://extensions → click "Inspect views: service worker" |
| Popup | Right-click extension icon → "Inspect popup" |
| Options page | Right-click in options page → "Inspect" |
| Side panel | Right-click in side panel → "Inspect" |
| Content script | Normal page DevTools (F12), check Sources → Content scripts |
| Offscreen document | chrome://extensions → "Inspect views: offscreen.html" |

### Content script debugging tips

Content script console logs appear in the PAGE's DevTools console, not the extension's. Filter by your extension name or use `console.log('[MyExt]', ...)` prefix.

In Sources panel: look under "Content scripts" folder to set breakpoints.

### Service worker debugging

The service worker console is separate. Use `chrome://extensions` → Inspect to open it. Warning: **keeping DevTools open on the SW prevents it from terminating**, masking lifecycle bugs.

## 2. Testing service worker termination

### Manual termination

1. Open chrome://extensions
2. Find your extension
3. Click the "service worker" link to open DevTools (optional)
4. Click the "Stop" button next to the service worker link
5. Trigger your extension's functionality
6. Verify it works after the SW restarts

### Programmatic self-termination for testing

```typescript
// Add a test-only handler
chrome.runtime.onMessage.addListener((msg) => {
  if (msg.type === "__TEST_TERMINATE_SW") {
    // Force terminate by not returning true and doing nothing
    // The SW will idle out in 30 seconds
    // OR: more aggressively, just stop doing anything
  }
});
```

### Chrome flag for testing

`chrome://flags/#enable-extension-service-worker-test-flag` (if available in your Chrome version) can help with automated testing of SW suspension.

### Automated test pattern

```typescript
// In a test (e.g., Puppeteer/Playwright)
// 1. Load extension
// 2. Interact with it (verify functionality)
// 3. Wait 35 seconds (or stop the SW via chrome://extensions)
// 4. Interact again (verify it recovers)
// 5. Check that all state was preserved
```

## 3. Common error messages and fixes

### "Extension context invalidated"

**Cause**: Content script trying to use chrome.runtime after extension was updated/reloaded. **Fix**: Check `chrome.runtime?.id` before any chrome.runtime call. Show refresh banner.

### "Could not establish connection. Receiving end does not exist."

**Causes**:

1. No content script in the target tab
2. Content script orphaned
3. Sending to chrome:// or other restricted page
4. Service worker terminated and listener not registered

**Fix**: Wrap in try/catch.

references/execution-contexts.md

# Execution Contexts, Communication Flows, and Limits

## Table of contents

1. Communication flow diagrams
2. Communication methods matrix
3. Per-context reference cards

## 1. Communication flow diagrams

### Full picture: all contexts and channels

```
                        Extension Process
 ┌──────────────────────────────────────────────────────────────────┐
 │                                                                  │
 │  ┌─────────────────────┐    chrome.runtime.sendMessage()        │
 │  │   Service Worker     │◄──────────────────────────────────┐   │
 │  │   (background)       │───────────────────────────────┐   │   │
 │  └──────────┬───────────┘                               │   │   │
 │        ▲    │                                           │   │   │
 │        │    │ chrome.tabs.sendMessage(tabId, ...)       │   │   │
 │        │    │                                           ▼   │   │
 │        │    │    ┌────────┐  ┌─────────┐  ┌──────────┐     │   │
 │        │    │    │ Popup  │  │ Options  │  │ Side     │     │   │
 │        │    │    │        │  │  Page    │  │ Panel    │     │   │
 │        │    │    └───┬────┘  └────┬────┘  └────┬─────┘     │   │
 │        │    │        │            │             │            │   │
 │        │    │        └────────────┴─────────────┘            │   │
 │        │    │          chrome.runtime.sendMessage()          │   │
 │        │    │          chrome.runtime.connect()              │   │
 │        │    │                                                │   │
 │  chrome.storage.onChanged  ◄──── fires across ALL contexts ─┘   │
 │                                                                  │
 └──────────────────────────────────────────────────────────────────┘
              │
              │ chrome.tabs.sendMessage(tabId, ...)
              ▼
 ┌──────────────────────────────────────────────────────────────────┐
 │  Web Page (per tab)                                              │
 │                                                                  │
 │  ┌──────────────────────┐     ┌──────────────────────┐          │
 │  │  Content Script       │     │  Main World Script    │          │
 │  │  (isolated world)     │     │  (page context)       │          │
 │  │                       │◄───►│                       │          │
 │  │  chrome.runtime ──────┼──►  │  No chrome.* APIs     │          │
 │  │  chrome.storage       │     │  Full page JS access  │          │
 │  └──────────────────────┘     └──────────────────────┘          │
 │         ▲        │                    ▲        │                 │
 │         │        │                    │        │                 │
 │         │  window.postMessage()       │  window.postMessage()   │
 │         │  Custom DOM events          │  Custom DOM events      │
 │         │        │                    │        │                 │
 │         └────────┘                    └────────┘                 │
 │              Shared DOM (read/write by

Sponsored

Ads related to chrome-extension and adjacent AI workflows.