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
Declare the scripting and offscreen permissions plus host permissions in manifest.json, with background.service_worker set
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
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
If none exists, create one with chrome.offscreen.createDocument({url, reasons:[...], justification})
Message the offscreen document via chrome.runtime.sendMessage/onMessage, since that's the primary channel it supports
Call chrome.offscreen.closeDocument() when finished
Known gotchas
Only one offscreen document may be open per extension (two if split incognito is active); creating a second throws
Offscreen documents cannot be focused and have limited extension API access compared to a full extension page
executeScript/insertCSS cannot run on restricted pages (chrome://, the Chrome Web Store) and require host permission for the target origin
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?