chrome-extension-tools icon indicating copy to clipboard operation
chrome-extension-tools copied to clipboard

Add explanation about Content Security Policy when adding a background script

Open andresgutgon opened this issue 1 year ago • 6 comments

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 : )

andresgutgon avatar Jul 16 '23 09:07 andresgutgon

⚠️ 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

changeset-bot[bot] avatar Jul 16 '23 09:07 changeset-bot[bot]

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

vercel[bot] avatar Jul 16 '23 09:07 vercel[bot]

This is interesting! I don't have this error in my projects, but I'm glad you found a solution that works for you 😸

jacksteamdev avatar Sep 24 '23 22:09 jacksteamdev

@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: image

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
}

farzadmf avatar May 03 '24 13:05 farzadmf

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.

andresgutgon avatar May 03 '24 13:05 andresgutgon

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

farzadmf avatar May 06 '24 16:05 farzadmf