Token导航 LogoToken导航TokenDH.com
前端设计操作浏览器github未标认证来源可访问许可证需确认审计提醒

build-chrome-extension构建 Chrome 扩展

Agent Skill

build-chrome-extension 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

416

周安装

17

GitHub Stars

5

下载量

133
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:build-chrome-extension(构建 Chrome 扩展)
来源仓库:https://github.com/yigitkonur/skills-by-yigitkonur
仓库路径:skills/build-chrome-extension
安装命令:
npx skills add https://github.com/yigitkonur/skills-by-yigitkonur --skill build-chrome-extension
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/yigitkonur/skills-by-yigitkonur --skill build-chrome-extension

简介

build-chrome-extension 用于构建 Manifest V3 标准的 Chrome 扩展,涵盖内容脚本、弹窗和后台逻辑。

  • 它支持调试服务 worker 终止、消息失败和权限错误等常见问题,并提供打包发布指导。
  • 使用时需明确扩展功能边界,避免用于非扩展相关的通用 web 开发任务。
  • 安装前请确认仓库权限、维护状态,以及是否会修改 manifest.json 或加载本地资源。
  • 适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

SKILL.md

Build Chrome Extension

Build production-grade Chrome extensions with Manifest V3.

Trigger boundary

Use this skill when the task involves:

  • Creating a new Chrome or browser extension from scratch
  • Adding features to an existing extension (content scripts, popups, sidepanels, background logic)
  • Debugging extension-specific issues (service worker termination, messaging failures, permission errors)
  • Migrating from Manifest V2 to V3
  • Packaging and publishing to Chrome Web Store
  • Choosing between extension frameworks (WXT, Plasmo, CRXJS, vanilla)

Do NOT use this skill for:

  • General web development without extension context
  • Browser automation or testing (use run-agent-browser or similar)
  • Chrome DevTools Protocol / CDP debugging of websites
  • PWA / service worker development outside extensions
  • React/Vue/Angular component development (use frontend-design)

The Persistence Paradox — read this first

Service workers in MV3 extensions terminate after 30 seconds of inactivity. This is the #1 source of bugs in AI-generated extensions.

Rules:

  • NEVER store state in global variables — use chrome.storage.local or chrome.storage.session
  • NEVER rely on setTimeout/setInterval for long-running tasks — use chrome.alarms
  • ALWAYS register event listeners at the top level (not inside async callbacks)
  • Use chrome.offscreen for tasks requiring DOM access from background
// WRONG — state lost on SW termination
let count = 0;
chrome.action.onClicked.addListener(() => { count++; });

// RIGHT — persisted across restarts
chrome.action.onClicked.addListener(async () => {
  const { count = 0 } = await chrome.storage.local.get('count');
  await chrome.storage.local.set({ count: count + 1 });
});

Decision tree

User request
├─ "Create / scaffold a new extension"
│   → Read references/manifest/manifest-v3.md
│   → Read references/frameworks/comparison.md
│   → Follow: New Extension Workflow (below)
│
├─ "Add feature to existing extension"
│   ├─ Content script work → Read references/patterns/content-scripts.md
│   ├─ Background / service worker → Read references/patterns/service-worker.md
│   ├─ UI (popup/options/sidepanel) → Read references/patterns/ui-surfaces.md
│   ├─ Messaging between contexts → Read references/apis/messaging.md
│   ├─ Storage / state management → Read references/apis/storage.md
│   └─ Permissions → Read references/manifest/permissions.md
│
├─ "Debug an extension issue"
│   ├─ Service worker dies/restarts → Read references/patterns/service-worker.md
│   ├─ Content script not injecting → Read references/patterns/content-scripts.md
│   ├─ Messaging failures → Read references/apis/messaging.md
│   ├─ Permission errors → Read references/manifest/permissions.md
│   └─ General → Read references/testing/debugging.md
│
├─ "Test the extension"
│   → Read references/testing/testing-guide.md
│
├─ "Publish to Chrome Web Store"
│   → Read references/publishing/web-store.md
│
└─ "Migrate MV2 → MV3"
    → Read references/manifest/mv2-to-mv3.md

New Extension Workflow

Phase 1: Requirements

  1. Identify the extension type: popup-only, content-script-driven, background-heavy, or full-featured
  2. List required Chrome APIs (storage, tabs, scripting, declarativeNetRequest, sidePanel, etc.)
  3. Determine minimum permissions using the principle of least privilege
  4. Choose a framework or vanilla approach (read references/frameworks/comparison.md)

Default framework rule

  • If the user gives no framework preference, start with WXT. It is the safest default for new MV3 extensions, including dead-simple popup-only tools.
  • Choose CRXJS when the user already has a Vite app and wants the smallest extension-specific change.
  • Choose vanilla + Vite only when the user explicitly wants manual control or needs to fit the extension into an existing custom build.

Quick selection heuristic

SituationDefault
New extension, unsure of needsWXT
Popup-only or small internal toolWXT
Existing Vite app gaining extension outputCRXJS
Existing custom build or explicit no-framework requirementVanilla + Vite

Phase 2: Scaffold

If the task is a new extension and no stronger signal exists, use the WXT fast path:

npm create wxt@latest my-extension
cd my-extension
npm install
npm run dev

After npm run dev, WXT writes the unpacked development build to .output/chrome-mv3-dev/. Load that directory manually if WXT does not launch the browser for you. Use .output/chrome-mv3/ after a production build.

If you intentionally choose vanilla + Vite, follow references/frameworks/comparison.md exactly:

  • Keep manifest.json and icons under public/
  • Put popup HTML/CSS/TS entry files under src/
  • Build with npm run build
  • Treat src/ + public/ as source only; Chrome should only ever load the built output
  • Load the built dist/ directory in chrome://extensions

If you are building the manual vanilla + Vite path, generate this exact source tree. Do not force WXT, Plasmo, or CRXJS into this layout:

my-extension/
├── public/
│   ├── manifest.json          # Hand-written manifest copied into dist/
│   ├── icons/
│   │   ├── icon-16.png
│   │   ├── icon-48.png
│   │   └── icon-128.png
│   └── _locales/              # i18n assets copied as-is (if needed)
│       └── en/
│           └── messages.json
├── src/
│   ├── background/
│   │   └── index.ts           # Builds to dist/background/index.js
│   ├── content/
│   │   └── index.ts           # Builds to dist/content/index.js (if needed)
│   ├── popup/
│   │   ├── index.html         # Builds to dist/popup/index.html
│   │   ├── main.ts
│   │   └── styles.css
│   ├── options/
│   │   ├── index.html         # Optional
│   │   └── main.ts
│   ├── sidepanel/
│   │   ├── index.html         # Optional
│   │   └── main.ts
│   └── lib/
│       ├── messaging.ts       # Type-safe message passing
│       └── storage.ts         # Type-safe storage helpers
├── tsconfig.json
├── package.json
└── vite.config.ts

Phase 3: Implement

Build each component following the patterns in the reference files. Key principles:

  • Service worker: Stateless, event-driven, all listeners registered at top level
  • Content scripts: Idempotent, isolated world by default, use MAIN world only when needed
  • Messaging: Type-safe with defined message types, always handle errors
  • Storage: Prefer chrome.storage.session for ephemeral data, local for persistent
  • Permissions: Request optional permissions at runtime when possible

Phase 4: Test

Read references/testing/testing-guide.md for the full testing approach:

  • Unit test business logic with Vitest
  • Integration test Chrome APIs with Puppeteer or Playwright
  • Manual load in chrome://extensions with Developer Mode

- WXT: load .output/chrome-mv3-dev/ during npm run dev, or .output/chrome-mv3/ after a production build - Plasmo: load build/chrome-mv3-dev/ for dev or build/chrome-mv3-prod/ for production - CRXJS / vanilla Vite: load dist/

  • Test service worker restart resilience

Phase 5: Package and Publish

Read references/publishing/web-store.md for store submission:

  • Prepare store assets (screenshots 1280x800, promo images, descriptions)
  • Review permission justifications
  • Build production bundle and create .zip
  • Submit via Chrome Web Store Developer Dashboard

Manifest V3 — minimal valid manifest

{
  "manifest_version": 3,
  "name": "My Extension",
  "version": "1.0.0",
  "description": "A brief description of the extension.",
  "permissions": [],
  "action": {
    "default_popup": "popup/index.html",
    "default_icon": {
      "16": "icons/icon-16.png",
      "48": "icons/icon-48.png",
      "128": "icons/icon-128.png"
    }
  },
  "icons": {
    "16": "icons/icon-16.png",
    "48": "icons/icon-48.png",
    "128": "icons/icon-128.png"
  }
}

For hand-written manifests, point every manifest entry at the built extension files, not at src/*.ts or other source-only paths. Frameworks like WXT and CRXJS generate or rewrite those manifest paths for you.

Add fields as needed:

FeatureManifest field
Background logic"background": {"service_worker": "background.js", "type": "module"}
Content scripts"content_scripts": [{"matches": [...], "js": [...]}]
Options page"options_page": "options.html" or "options_ui": {"page": "options.html", "open_in_tab": false}
Side panel"side_panel": {"default_path": "sidepanel.html"}
Context menusAdd "contextMenus" to permissions
Keyboard shortcuts"commands": {...}
Network rules"declarative_net_request": {"rule_resources": [...]}

Common pitfalls

PitfallFix
Global variables lost after SW terminatesUse chrome.storage.local / chrome.storage.session
Event listeners not firing after restartRegister listeners at the top level of SW, never inside async
Content script not injectingCheck matches patterns, verify host_permissions, check page CSP
chrome.tabs.sendMessage failsContent script must be loaded first; use chrome.scripting.executeScript as fallback
CORS errors from extensionUse host_permissions for the target domain
eval() blocked by CSPMV3 forbids eval; use chrome.scripting.executeScript with world: 'MAIN'
Storage sync quota exceededchrome.storage.sync has 100KB total limit; use local for large data
Extension not reloading changesUse chrome.runtime.reload() or enable auto-reload via framework
Side panel not showingRequires Chrome 114+; add "sidePanel" permission
chrome.scripting undefinedAdd "scripting" permission to manifest
Manifest points at src/*.ts or other source-only filesIn hand-written builds, point manifest entries at built files inside dist/ such as popup/index.html and background/index.js
Shared repo tsc errors block extension buildScope compilation to the extension package/entrypoints; do not typecheck unrelated UI code just to ship the extension

Type-safe messaging pattern

// shared/messages.ts — define once, import everywhere
type MessageMap = {
  'GET_TAB_DATA': { tabId: number };
  'TAB_DATA_RESULT': { title: string; url: string };
  'TOGGLE_FEATURE': { enabled: boolean };
};

type MessageType = keyof MessageMap;

interface TypedMessage<T extends MessageType> {
  type: T;
  payload: MessageMap[T];
}

function sendMessage<T extends MessageType>(
  msg: TypedMessage<T>
): Promise<any> {
  return chrome.runtime.sendMessage(msg);
}

function onMessage<T extends MessageType>(
  type: T,
  handler: (payload: MessageMap[T], sender: chrome.runtime.MessageSender) => void | Promise<any>
) {
  chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
    if (message.type === type) {
      const result = handler(message.payload, sender);
      if (result instanceof Promise) {
        result.then(sendResponse);
        return true; // Keep channel open for async response
      }
    }
  });
}

Type-safe storage pattern

// shared/storage.ts
interface StorageSchema {
  settings: { theme: 'light' | 'dark'; notifications: boolean };
  cache: { lastSync: number; data: unknown[] };
  count: number;
}

async function getStorage<K extends keyof StorageSchema>(
  key: K
): Promise<StorageSchema[K] | undefined> {
  const result = await chrome.storage.local.get(key);
  return result[key];
}

async function setStorage<K extends keyof StorageSchema>(
  key: K, value: StorageSchema[K]
): Promise<void> {
  await chrome.storage.local.set({ [key]: value });
}

function watchStorage<K extends keyof StorageSchema>(
  key: K,
  callback: (newValue: StorageSchema[K], oldValue: StorageSchema[K]) => void
): void {
  chrome.storage.onChanged.addListener((changes, areaName) => {
    if (areaName === 'local' && key in changes) {
      callback(changes[key].newValue, changes[key].oldValue);
    }
  });
}

Red flags — stop and fix immediately

Red flagWhy it's dangerous
Global let/var in service workerLost on every SW restart (every 30s idle)
setInterval in service workerCleared on termination; use chrome.alarms
Missing return true in async message handlerResponse channel closes before async completes
"permissions": ["<all_urls>"]Over-broad; triggers Web Store review flags
Inline scripts in HTMLBlocked by MV3 CSP; use separate .js files
document access in service workerNo DOM in SW; use chrome.offscreen if DOM needed
XMLHttpRequest in service workerUse fetch() instead; XHR unavailable in SW
Content script assumes DOM is readyUse "run_at": "document_idle" or wait for elements

Reference routing

Manifest and permissions

FileRead when
references/manifest/manifest-v3.mdSetting up or modifying manifest.json, understanding required vs optional fields
references/manifest/permissions.mdChoosing permissions, understanding risk levels, requesting optional permissions
references/manifest/mv2-to-mv3.mdMigrating an existing MV2 extension to MV3

Chrome APIs

FileRead when
references/apis/messaging.mdImplementing communication between popup, content script, service worker, or external pages
references/apis/storage.mdUsing chrome.storage (local, sync, session), understanding quotas and watching changes
references/apis/core-apis.mdUsing tabs, scripting, alarms, notifications, contextMenus, commands, declarativeNetRequest, sidePanel, offscreen

Extension patterns

FileRead when
references/patterns/service-worker.mdWriting background service workers, handling lifecycle, persistence, alarms, offscreen
references/patterns/content-scripts.mdInjecting into web pages, MAIN vs ISOLATED world, dynamic injection, shadow DOM isolation
references/patterns/ui-surfaces.mdBuilding popup, options page, side panel, or DevTools panel UI

Frameworks

FileRead when
references/frameworks/comparison.mdChoosing between WXT, Plasmo, CRXJS Vite, or vanilla; framework setup guides

Testing and publishing

FileRead when
references/testing/testing-guide.mdUnit testing, integration testing, manual testing, CI/CD for extensions
references/testing/debugging.mdDebugging service worker issues, content script problems, messaging failures
references/publishing/web-store.mdChrome Web Store submission, asset requirements, review process, update workflow

Guardrails

  • NEVER generate Manifest V2 extensions. Always use "manifest_version": 3.
  • NEVER use eval(), new Function(), or inline scripts in MV3 extensions.
  • NEVER store secrets (API keys, tokens) in extension code or storage without encryption.
  • NEVER use "permissions": ["<all_urls>"] without explicit justification.
  • NEVER use global variables for state in service workers.
  • ALWAYS register service worker event listeners synchronously at the top level.
  • ALWAYS handle the case where content scripts haven't loaded yet when sending messages.
  • ALWAYS use TypeScript for extensions with more than one file.
  • ALWAYS validate data at boundaries (messages received, storage reads, external API responses).
  • PREFER chrome.storage.session over chrome.storage.local for ephemeral data.
  • PREFER optional permissions requested at runtime over declared permissions.
  • PREFER declarativeNetRequest over webRequest for network modification.

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

37.67%
按下载量换算50

Claude

29.24%
按下载量换算39

Cursor

19.07%
按下载量换算25

Gemini CLI

9.33%
按下载量换算12

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

可疑

权限和风险

操作浏览器

该 Skill 可能涉及浏览器控制能力,使用时可能读取或操作网页内容,需要在受控环境中确认权限边界。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。来源安全扫描存在 warning/failed 结果,不能写成本站确认安全。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills