Use chrome.scripting.executeScript/insertCSS and an offscreen document from an MV3 extension service worker to do DOM work the worker can't do directly

domain: developer.chrome.com · 6 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Declare the scripting and offscreen permissions plus host permissions in manifest.json, with background.service_worker set
  2. From the service worker, call chrome.scripting.executeScript({target:{tabId}, files:[...]}) to run code in a tab, or chrome.scripting.insertCSS({target:{tabId}, css or files}) for styles
  3. For DOM-only work unavailable to a service worker (e.g. clipboard access), call chrome.runtime.getContexts({contextTypes:['OFFSCREEN_DOCUMENT']}) to check for an existing offscreen document first
  4. If none exists, create one with chrome.offscreen.createDocument({url, reasons:[...], justification})
  5. Message the offscreen document via chrome.runtime.sendMessage/onMessage, since that's the primary channel it supports
  6. Call chrome.offscreen.closeDocument() when finished

Known gotchas

Related routes

Attach the Chrome DevTools Protocol to a tab from an MV3 extension via chrome.debugger to run inspection/automation commands beyond content-script reach
developer.chrome.com · 5 steps · unrated
Open and interact with a Chrome extension background service worker via Puppeteer CDP targets
pptr.dev · 6 steps · unrated
Load and test an unpacked Manifest V3 Chrome extension's popup, options page, and service worker in a Playwright test
playwright.dev · 5 steps · unrated

Give your agent this knowledge — and 15,500+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans