Vibe Coding
Scene ConfigIntermediate92% · Ready

End-to-End Vibe Coding for Chrome Manifest V3 Extensions: Development and Minimal Permission Configuration

92% Complete: Covers Service Workers, Shadow DOM isolation, and Side Panel communication protocols, resulting in a store-ready extension

Est. time: 50 minUpdated: 2026-11-26
Cursor IDEChrome MV3Vite + CRXTypeScript
End-to-End Vibe Coding for Chrome Manifest V3 Extensions: Development and Minimal Permission Configuration

Completion Score

Overall completion is 92%. The AI excels in architecture design, communication protocol definition, and generating minimal permission manifests. Human intervention is primarily required for implementing specific business logic and final compliance verification before store review.

92%Ready

Dimension breakdown

MV3 Service Worker & Communication94%

Service Worker lifecycle and message routing logic are clear and compliant with MV3 specifications.

Shadow DOM Isolation & Page Injection90%

Shadow DOM encapsulation effectively prevents style conflicts, but complex DOM tree traversal requires manual optimization.

Minimal Permission Manifest & Store Review95%

Permission configuration is highly streamlined and fully compliant with the latest Chrome Web Store review guidelines.

Multi-Site Adaptation & Compatibility87%

Currently adapted only for the example domain; cross-origin communication requires additional `host_permissions` configuration.

Human checkpoint

Humans must review `host_permissions` in `manifest.json` to ensure they are not overly broad, and manually test the Side Panel's opening behavior and communication latency on target websites.

Upgrade / downgrade path

If the budget is tight, remove `side_panel` and use an `action` popup instead. If hardware is constrained, simplify `content_scripts` `run_at` to `document_idle` to reduce memory usage.

When to use & prerequisites

Ideal for development teams needing to rapidly build enterprise-grade browser extensions. The environment requires Node.js 18+ and Cursor IDE. Best suited for projects requiring deep interaction with specific websites (e.g., data scraping, UI enhancement) and high privacy compliance standards.

Ready-to-copy configs

.cursor/rules/chrome-mv3.mdcmarkdown

定义 Chrome MV3 插件开发的架构规则、通信协议及最小权限审查标准

# Chrome MV3 Vibe Coding Rules

## 1. Architecture & Service Worker
- **Manifest Version**: Must be 3.
- **Background**: Use `service_worker` with `type: module` and `script: src/background.ts`.
- **Lifecycle**: Implement `activate`, `message`, and `stop` handlers strictly.
- **Timeouts**: Set `service_worker` timeout to 10000ms to prevent hanging.

## 2. Content Script & Shadow DOM
- **Injection**: Use `content_scripts` with `matches` specific to target domains.
- **Isolation**: Wrap all DOM manipulations in `shadowRoot` to prevent style leakage.
- **Access**: Use `chrome.runtime.sendMessage` for cross-context communication, never direct DOM access.

## 3. Permissions & Audit
- **Minimalism**: Only request `activeTab` or specific `host_permissions` (e.g., `https://*.example.com/*`).
- **Wildcards**: Avoid `*://*/*` unless absolutely necessary; prefer specific origins.
- **Review**: Ensure no `storage` access is requested if not needed for user data.

## 4. Side Panel & UI
- **Panel**: Define `side_panel` with `default_path` and `open_panel_on_action`.
- **Communication**: Use `chrome.sidePanel` API for opening/closing.
- **Styling**: Use CSS variables for theming consistency across panels.

## 5. Build & Packaging
- **Tooling**: Use Vite with `@crxjs/vite-plugin` for CRX generation.
- **Types**: Enforce strict TypeScript (`strict: true`) for manifest types.
- **Output**: Generate `dist/chrome-mv3.crx` and `dist/chrome-mv3.zip`.
manifest.jsonjson

Chrome Manifest V3 配置文件,包含最小权限清单与服务端通信定义

{
  "manifest_version": 3,
  "name": "MV3 Vibe Coding Extension",
  "version": "1.0.0",
  "description": "A minimal MV3 extension demonstrating Service Worker, Shadow DOM, and Side Panel communication.",
  "permissions": [
    "activeTab",
    "sidePanel"
  ],
  "host_permissions": [
    "https://*.example.com/*"
  ],
  "background": {
    "service_worker": "src/background.ts",
    "type": "module"
  },
  "content_scripts": [
    {
      "matches": ["https://*.example.com/*"],
      "js": ["src/content.js"],
      "css": ["src/content.css"],
      "run_at": "document_start",
      "all_frames": false
    }
  ],
  "side_panel": {
    "default_path": "src/side-panel.html",
    "open_panel_on_action": true
  },
  "action": {
    "default_popup": false,
    "default_title": "Open Side Panel"
  },
  "icons": {
    "16": "icons/icon16.png",
    "48": "icons/icon48.png",
    "128": "icons/icon128.png"
  }
}

AI Vibe Coding in 4 steps

  1. 1

    Initialize Project Structure & Manifest Configuration

    Goal: Create a Vite project and generate a manifest.json compliant with MV3 specifications, along with the basic directory structure.

    Prompt
    Use Vite to create a TypeScript project and configure @crxjs/vite-plugin. Generate manifest.json, setting manifest_version to 3. Include only activeTab and sidePanel in permissions, and set host_permissions to https://*.example.com/*. Ensure background uses the service_worker type.

    Verify: Run `npm run build` to verify that `dist/chrome-mv3.crx` is generated and that manifest.json has no syntax errors.

  2. 2

    Implement Service Worker Communication Protocol

    Goal: Write background.ts to handle message routing and define communication interfaces with Content Scripts and the Side Panel.

    Prompt
    Implement a chrome.runtime.onMessage listener in src/background.ts. Define a message type enum (e.g., 'OPEN_PANEL', 'GET_DATA', 'UPDATE_UI') and write the corresponding handling logic, ensuring message payloads are validated.

    Verify: Send `chrome.runtime.sendMessage('test', {type: 'OPEN_PANEL'})` in the DevTools Console and confirm there are no errors and the Side Panel opens.

  3. 3

    Build Shadow DOM Isolated Content Script

    Goal: Develop content.js to inject UI components using Shadow DOM, avoiding pollution of the main page's styles.

    Prompt
    Create a shadowRoot on the root element in src/content.js. Inject a Shadow DOM component containing a button, listen for button click events, and send data to the background via chrome.runtime.sendMessage. Ensure you do not directly manipulate document.body styles.

    Verify: Open the extension on the target website, click the injected button, and verify that the main page's CSS is unaffected and the message was sent.

  4. 4

    Configure Side Panel & Final Packaging

    Goal: Complete side-panel.html development, configure the manifest to auto-open the panel, and package the final CRX file.

    Prompt
    Configure the side_panel property in manifest.json, setting default_path to src/side-panel.html and open_panel_on_action to true. Write a packaging script to bundle the build artifacts into .crx and .zip files and generate a version number.

    Verify: Click the browser extension icon to confirm the Side Panel opens automatically. Check the Chrome extension management page to ensure the version number is correctly updated.

Pitfalls & fixes

  • Excessive permissions: Avoid using `*://*/*`, as this will cause store review rejection; explicitly list required domains instead.
  • Communication blocking: Synchronous API calls in Service Workers cause blocking; use `chrome.runtime.sendMessage` for asynchronous communication.
  • Style leakage: Directly modifying DOM styles in Content Scripts may affect page layout; Shadow DOM isolation is mandatory.

FAQ

How to implement cross-tab communication in MV3?

Use `chrome.tabs.query` to get the target tab ID, then send messages to that tab's Content Script using `chrome.tabs.sendMessage`.

What is the default width of the Side Panel?

The default Chrome Side Panel width is approximately 300px. It can be customized via CSS in `side-panel.html`, but must remain responsive to fit different screens.

Why was my extension rejected during store review?

Common reasons include excessive permission requests, missing privacy policy, or malicious behavior (e.g., data theft). Ensure `manifest.json` strictly follows the principle of least privilege.

Related blueprints

End-to-End Vibe Coding for Chrome Manifest V3 Extensions: Development and Minimal Permission Configuration · CursorHome