The Chrome update broke the extension. Scripts cannot be injected dynamically as easily anymore.
There's (at least) 2 ways to work around this:
Use the new UserScripts API
Load the content script as a static asset and not dynamically
Use the new UserScripts API (not recommended)
You can use the userScripts API and mess with the content security policy with configureWorld. This, however, is overkill for this extension since that's more for scripts that need to load dynamically. You don't need to load it dynamically since you're shipping the content script with the extension. This also has the down side of requiring users to turn on Developer Mode but that's not an issue for your extension since it's not published to the store and users have to do that anyways to load the unpacked extension.
Load the content script as a static asset and not dynamically (recommended)
The plugin you're using to bundle the extension is dynamically loading the content script, which is not necessary. This causes the CSP error.
I did this change in the manifest and got the extension working again:
So either you can modify the manifest after the build (possibly the quickest option) or find another way to bundle the extension that doesn't use @crxjs/vite-plugin. I did just check their issues now and it looks like it's a known issue: https://github.com/crxjs/chrome-extension-tools/issues/918
So if you're not a developer and you'd like to fix this and you don't mind poking around in some code:
Open the manifest.json file in a text editor like Notepad or Visual Studio Code
Copy the value that starts with assets/index.jsx—the hash (in my case 48ed4cb1) will be different since I'm on the head of the develop branch. You'll need to copy the line in your manifest and not the one in the diff above.
Paste the path in place of the line that says content-script-loader line
The Chrome update broke the extension. Scripts cannot be injected dynamically as easily anymore.
There's (at least) 2 ways to work around this:
Use the new UserScripts API (not recommended)
You can use the userScripts API and mess with the content security policy with configureWorld. This, however, is overkill for this extension since that's more for scripts that need to load dynamically. You don't need to load it dynamically since you're shipping the content script with the extension. This also has the down side of requiring users to turn on Developer Mode but that's not an issue for your extension since it's not published to the store and users have to do that anyways to load the unpacked extension.
Load the content script as a static asset and not dynamically (recommended)
The plugin you're using to bundle the extension is dynamically loading the content script, which is not necessary. This causes the CSP error.
I did this change in the manifest and got the extension working again:
So either you can modify the manifest after the build (possibly the quickest option) or find another way to bundle the extension that doesn't use
@crxjs/vite-plugin
. I did just check their issues now and it looks like it's a known issue: https://github.com/crxjs/chrome-extension-tools/issues/918So if you're not a developer and you'd like to fix this and you don't mind poking around in some code:
manifest.json
file in a text editor like Notepad or Visual Studio Codeassets/index.jsx
—the hash (in my case48ed4cb1
) will be different since I'm on the head of the develop branch. You'll need to copy the line in your manifest and not the one in the diff above.content-script-loader
line