Main-world Content Script

Injects a small UI into every web page from both the extension and the page's own JavaScript world.

Runs on Chrome, Edge, Firefox · Manifest V3 · Surfaces: content script, background service worker · Styling: CSS · Level: intermediate

Create this project

npx extension@latest create my-content-main-world --template content-main-world
cd my-content-main-world
npm install
npm run dev

What it is for

  • Hook into page-level globals that isolated content scripts cannot reach
  • Bridge isolated and main-world execution contexts cleanly
  • Reference for multi-group content_scripts in MV3

First steps

  • Run npm run dev to launch the extension
  • Open any page and watch the main-world script run alongside isolated entries
  • Inspect window.postMessage bridges between isolated and main worlds

Permissions it asks for

  • activeTab
  • scripting
  • <all_urls>

extension.devDocumentation for extension.dev