Skip to content

Bundle content scripts as IIFEs - #5

Merged
pascalbaljet merged 2 commits into
masterfrom
improve-vite-conf
Jul 30, 2026
Merged

Bundle content scripts as IIFEs#5
pascalbaljet merged 2 commits into
masterfrom
improve-vite-conf

Conversation

@pascalbaljet

@pascalbaljet pascalbaljet commented Jul 30, 2026

Copy link
Copy Markdown
Member

Vite emits the multi-entry build-in ES module format, but the manifest loads content-script.js and page-world.js as classic scripts. Top-level bindings in a classic script land in the scope it runs in, so every minified name in the bundle became a global (var e, var t, var n, etc.). For page-world, which runs in the MAIN world, that scope is the inspected page's own.

Any page whose scripts declare a colliding top-level let then fails to parse, not merely at runtime. On reddit.com, our global e broke their first inline script with "Identifier 'e' has already been declared", which took out the helper the rest of their inline scripts call, and infinite scroll stopped loading posts entirely.

Content scripts now build as separate single-entry IIFE bundles, the same way the service worker is already built, so nothing escapes into the page. The build fails if either bundle stops opening as an IIFE.

@pascalbaljet
pascalbaljet marked this pull request as ready for review July 30, 2026 07:50
@pascalbaljet
pascalbaljet merged commit d396210 into master Jul 30, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant