chrome-extension-tools
chrome-extension-tools copied to clipboard
Add explanation about Content Security Policy when adding a background script
What?
I noticed that loading a background script failed until I add the CSP for connect-src
because I think Vite server needs for connecting with the dev server websockets
Issue on Vite
Here one person suggest that solution. https://github.com/vitejs/vite/discussions/7590
And it worked in my case. At least now my extension background loads without error : )
⚠️ No Changeset found
Latest commit: 0ec9093471ed57141aeee702fd50b89c645fc4a1
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR
The latest updates on your projects. Learn more about Vercel for Git ↗︎
Name | Status | Preview | Comments | Updated (UTC) |
---|---|---|---|---|
vite-plugin-docs | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Jan 14, 2024 7:35pm |
This is interesting! I don't have this error in my projects, but I'm glad you found a solution that works for you 😸
@andresgutgon was wondering if you have an example repo working for Firefox (as I'm guessing the CSP value is because of Firefox).
I have the same value as you have, but I'm seeing all these errors:
Not sure where that 'self' 'wasm-unsafe-eval'
is coming from as I clearly have this (I'm even directly checking out the generated dist/manifest.json
):
{
// ... other things
"content_security_policy": {
"extension_pages": "default-src 'self'; connect-src ws://localhost:5173;"
},
// ... other things
}
I was wondering if you have an example repo working for Firefox
I never tried with Firefox. I thought Firefox extensions were not the same. But as I said I never did one.
Ah OK, cool, thank you for letting me know. Given that things work "as is" in Chrome (at least for me), and it's Firefox creating all the headaches with CSP, I thought your change is because of that as well