Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add explanation about Content Security Policy when adding a background script #753

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

andresgutgon
Copy link

@andresgutgon andresgutgon commented Jul 16, 2023

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.
vitejs/vite#7590

And it worked in my case. At least now my extension background loads without error : )

…d (service worker)

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
@changeset-bot
Copy link

changeset-bot bot commented Jul 16, 2023

⚠️ No Changeset found

Latest commit: 0ec9093

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

@vercel
Copy link

vercel bot commented Jul 16, 2023

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

@jacksteamdev
Copy link
Contributor

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 jacksteamdev self-assigned this Jan 14, 2024
@farzadmf
Copy link

farzadmf commented May 3, 2024

@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
}

@andresgutgon
Copy link
Author

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.

@farzadmf
Copy link

farzadmf commented May 6, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation vite-plugin Related to Vite plugin
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants