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

EvalError: Refused to evaluate a string as JavaScript #62

Open
lopuhin opened this issue Jan 17, 2017 · 5 comments
Open

EvalError: Refused to evaluate a string as JavaScript #62

lopuhin opened this issue Jan 17, 2017 · 5 comments

Comments

@lopuhin
Copy link
Contributor

lopuhin commented Jan 17, 2017

Requests may fail completely due to failure to execute javascript headless horsemen scripts:

[scrapy_splash.middleware] WARNING: Bad request to Splash: {'description': 'Error happened while executing Lua script', 'error': 400, 'info': {'line_number': 70, 'error': 'JavaScript error: EvalError: Refused to evaluate a string as JavaScript because \'unsafe-eval\' is not an allowed source of script in the following Content Security Policy directive: "script-src \'self\' https://*.twimg.com https://*.twitter.com https://static.ads-twitter.com".', 'message': 'Lua error: [string "function get_arg(arg, default)..."]:70: JavaScript error: EvalError: Refused to evaluate a string as JavaScript because \'unsafe-eval\' is not an allowed source of script in the following Content Security Policy directive: "script-src \'self\' https://*.twimg.com https://*.twitter.com https://static.ads-twitter.com".\n', 'source': '[string "function get_arg(arg, default)..."]', 'type': 'LUA_ERROR'}, 'type': 'ScriptError'}

Line 70 is this one:

It's possible to skip the error with pcall: https://www.lua.org/pil/8.4.html, but maybe there is a way to still execute js on the page?

@kmike
Copy link
Contributor

kmike commented Jan 17, 2017

AFAIK the only way is to strip CSP headers using a proxy in front of Splash. See scrapinghub/splash#313.

@lopuhin
Copy link
Contributor Author

lopuhin commented Jan 18, 2017

Thanks @kmike , it's good to know that this is a known issue :)

@nehakansal nehakansal mentioned this issue Dec 1, 2018
@nehakansal
Copy link

I was looking at the code and trying to figure out where would I add pcall, a bit confused there, could you point me towards that please. I would like to skip this error and continue with the rendering without the js script. Would it have to be in the Splash code (where the lua script is getting called)? Thanks.

@lopuhin
Copy link
Contributor Author

lopuhin commented Dec 3, 2018

@nehakansal I think pcall is a way to handle exceptions in Lua, similar to try/except in Python (
https://www.lua.org/pil/8.4.html), so it should be placed where the exception gets thrown - I didn't try doing it though. Using a proxy which strips CSP headers looks like a better solution, but it's probably more work to set it up.

@nehakansal
Copy link

Thanks. I tried that earlier but it didnt work. I will try further.
For now, I would prefer to make it work by handling the exception, than to strip the headers.

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