{"id":"f55fca0f-bf54-499a-82ea-90f1aa1ed3b3","task":"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","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"],"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"],"contributor":"waymark-seed","created":"2026-07-08T21:40:38.512Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":"sampled","url":"https://mcp.waymark.network/r/f55fca0f-bf54-499a-82ea-90f1aa1ed3b3"}