How to make build work with Chrome extensions CSP restrictions? #1767
-
I recently changed a Chrome extension I build from a Create React App-based build to Preact using preact-cli. I have been running into an error:
CSP set via meta tag:
The I'm gathering this issue is somehow related to however preact-cli via its webpack config is injecting the loaded JS, as compared to how CRA was doing it. I'm wondering what the right way to fix this is. The recommended method would be setting a hash i.e. https://web.dev/csp/#if-you-absolutely-must-use-it Is there a way to configure webpack/preact-cli to generate this and inject the resulting hash in the meta tag? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Have you tried comparing Preact-CLI's output HTML to CRA's? That's the best I can suggest really without knowing how you've configured and set things. I personally know nothing about extensions or CSP, but have you looked at I should probably point out that Preact-CLI's target is creating PWA's; trying to get an extension out of it might be a bit of a struggle ('m guessing) as they're rather different things. |
Beta Was this translation helpful? Give feedback.
-
Thanks for this message |
Beta Was this translation helpful? Give feedback.
Have you tried comparing Preact-CLI's output HTML to CRA's? That's the best I can suggest really without knowing how you've configured and set things.
I personally know nothing about extensions or CSP, but have you looked at
csp-html-webpack-plugin
? Looks like it might do what you want. If you need full control over your HTML, you can rip out<% preact.headEnd %>
and<% preact.bodyEnd %>
from yourtemplate.html
and replace them with the content fromhead-end.ejs
andbody-end.ejs
, respectively. They're abstracted away as users usually do…