Problem
Need to inject code into the main world using chrome.scripting.registerContentScripts, but ES modules are not allowed. The current ?script loader uses chrome.runtime.getURL, which cannot run in the main world. Using ?iife fails with Error: IIFE content scripts are not implemented.
Impact
Developers cannot generate IIFE bundles for main-world content scripts via crxjs today.
Current workaround
Create a separate Vite config that builds an IIFE bundle and run another watch build. Example:
export default defineConfig({
build: {
emptyOutDir: false,
rollupOptions: {
input: path.resolve(__dirname, './content-main.ts'),
output: {
format: 'iife',
dir: path.resolve(__dirname, './dist/assets'),
entryFileNames: 'content-main.js',
},
},
},
})
Then run an additional build --watch --config for the IIFE bundle. HMR is not available for this IIFE output.
Problem
Need to inject code into the main world using
chrome.scripting.registerContentScripts, but ES modules are not allowed. The current?scriptloader useschrome.runtime.getURL, which cannot run in the main world. Using?iifefails withError: IIFE content scripts are not implemented.Impact
Developers cannot generate IIFE bundles for main-world content scripts via crxjs today.
Current workaround
Create a separate Vite config that builds an IIFE bundle and run another watch build. Example:
Then run an additional
build --watch --configfor the IIFE bundle. HMR is not available for this IIFE output.