What this thread does
The problem
You build a Manifest V3 extension with an agent. On your test page it works, but on real sites your content script sometimes runs after the page's own scripts, so whatever you wanted to change has already happened. Asking the agent to "fix the timing bug" does not help.
What the post reported
A r/vibecoding post (June 2026) described a first MV3 extension built with Claude. The author's account of the timing problem:
- The core was two content scripts: one running in the page's own context (the MAIN world) at
document_start, before the page's scripts run, and one in the ISOLATED world for the safe parts. - They lost about three days to "why does my script run after the page script sometimes"; the answer was that
run_atandworldin the manifest were slightly wrong. - Network blocking used
declarativeNetRequestrule lists because MV3 replaces the old blockingwebRequestpath for extensions not installed by policy; the author says this part was easy to get an agent to produce by feeding it filter rules. - Lessons they listed: asking an agent to fix a timing bug fails if you do not understand what
document_startmeans; test early on the annoying real sites, not just your test page; keep permissions small (they keptdeclarativeNetRequestandstorage) so people can inspect them.
A third-party commenter (the top comment) agreed: the timing was likely what mattered, because the extension's logic ran early enough in the main world to act before the site's own code. Another commenter audited the repo afterwards and listed suggestions such as CI, tests and a versioning mechanism.
What Chrome's docs say
From the content scripts page (developer.chrome.com/docs/extensions/develop/concepts/content-scripts):
run_atvalues:document_startinjects after any CSS but before the DOM is built or other scripts run;document_endis after the DOM is complete;document_idleis the default, somewhere betweendocument_endand just after the load event.worldis optional and defaults toISOLATED. A MAIN-world script follows the page's CSP; isolated scripts use the extension's stricter CSP.- Declare scripts in
content_scriptsinmanifest.jsonfor known pages; usescripting.registerContentScripts()when match patterns are not known in advance. At the same document lifecycle stage, static manifest scripts are injected before scripts registered in other ways.
A minimal static example:
"content_scripts": [{
"matches": ["https://example.com/*"],
"run_at": "document_start",
"world": "MAIN",
"js": ["early.js"]
}]
(The docs page itself shows run_at but no dedicated MAIN example; as of November 2026, the ExecutionWorld reference marks the type used by manifest world as Chrome 111+.)
How to ask the agent
This extension must run before the page's scripts. Explain whatrun_at: document_startandworld: MAINchange, then split the code into an early MAIN-world script and an isolated script. Do not add permissions. Test on three real sites and tell me what each log shows about execution order.
Mistakes to check
- Leaving the default
document_idleand expecting early behaviour. - Putting extension APIs in a MAIN-world script: the page context lacks them except APIs explicitly exposed through
externally_connectable; message through the isolated script. - Testing only on a page you control.
Limits
I did not build or run an extension. The post is a self-report from an extension that is itself an ad blocker; I use it only for the timing lesson, which Chrome's docs and a commenter support.
Sources
- Content scripts (Chrome for Developers), read. Checked: the
run_atdefinitions quoted in the body match the page (document_startis after any CSS but before any other DOM is built or script runs;document_endis after the DOM is complete;document_idleis the default);worlddefaults toISOLATED; a content script injected into the main world is subject to the page's CSP while isolated worlds have the extension's own CSP; dynamic declarations were introduced in Chrome 96. - Content scripts in the manifest (Chrome for Developers), read. Checked:
worldtakesISOLATEDorMAIN, defaultISOLATED. As of November 2026, the ExecutionWorld reference marks the type Chrome 111+; the manifest page itself gives no minimum version. - The content scripts page confirms that static manifest scripts are injected before other registrations at the same lifecycle stage, and that dynamic declarations suit match patterns that are not well known. The Web Extensions execution-context draft describes the MAIN-world API limitation, including the
externally_connectableexception.
The r/vibecoding post and comments were opened on 2026-11-15; their two-script account, three lost days, timing comment, repository audit and declarativeNetRequest remarks were checked. I did not build or run an extension.
Started from a post by @TurbulentFail5486, packaged by the editor. Original post