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

Refused to execute a script (CSP issues) #106

Closed
mjabdulm opened this issue Mar 12, 2021 · 5 comments
Closed

Refused to execute a script (CSP issues) #106

mjabdulm opened this issue Mar 12, 2021 · 5 comments

Comments

@mjabdulm
Copy link

System Information:

macOS version: 10.14.6
Userscripts version:3.0.2
Safari version: 14.0.3 (14610.4.3.1.7)

Hi,

I wanted to execute a JS script and I get the following error while trying to execute the script. Please guide on how to debug this.

[Error] Refused to execute a script because its hash, its nonce, or 'unsafe-inline' does not appear in the script-src directive of the Content Security Policy. (tto-dyni-oto, line 0)

Thanks,
Abdul

@quoid
Copy link
Owner

quoid commented Mar 12, 2021

@mjabdulm

TL;DR: try putting this into your scripts metadata: @inject-into content

That error most often occurs when trying to inject the script into the page context on a website with a strict content security policy.

Injecting into the content script context can usually circumvent this issue. You can do that by using the @inject-into key with the value content or auto. auto attempts to inject into the page context and if an error occurs it should automatically fallback to content. You can read more about available keys here.

Note, this error is due to the webpage's content security policy, which the user has no control over. While injecting into the content context will usually allow script execution, it is not always a perfect solution since there are some things you can not accomplish in the content script context. Unfortunately, it is the only alternative for strict security policies, currently.

@mjabdulm
Copy link
Author

mjabdulm commented Mar 12, 2021 via email

@quoid quoid pinned this issue Mar 12, 2021
@quoid quoid closed this as completed Mar 12, 2021
@TraderStf
Copy link
Contributor

TraderStf commented Apr 29, 2021

@quoid
May I add this explanation in the FAQ section?
Or add it to another new section: Common Errors/Problems/?? what title?

Common Errors

[Error] Refused to execute a script because its hash, its nonce, or 'unsafe-inline' does not appear in the script-src directive of the Content Security Policy...

It occurs when trying to inject the script into the page context which as script Content Security Policy (CSP).

Injecting into the content script context @inject-into content usually circumvent this issue.
Use @inject-into with the value content or auto (default).
auto attempts to inject into the page context and if an error occurs it automatically fallback to content.
Ref. Metadata

This error is due to the webpage's CSP, which the user has no control over.
While injecting into the content context will usually allow script execution, it is not always a perfect solution since there are some things you can not accomplish in the content script context.
Unfortunately, it is the only alternative for strict CSP, currently.

@TraderStf
Copy link
Contributor

If you have other previous error-solutions to add to the FAQ, just point me to them, I will do the blabla 💼
A good faq is less wasted time for you with rookies like me 😜

@quoid
Copy link
Owner

quoid commented Apr 29, 2021

@TraderStf I have already done this for next update, but thank you for offer.

quoid added a commit that referenced this issue May 11, 2021
@ACTCD ACTCD changed the title Refused to execute a script Refused to execute a script (CSP issues) Jan 21, 2024
@ACTCD ACTCD unpinned this issue Apr 23, 2024
Repository owner deleted a comment Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants