-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[BUG] Error: Page.wait_for_function: EvalError due to Content Security Policy restrictions #370
Comments
@HamdiBarkous Thanks for the report. Yes, that's a bug, and I have already resolved it. I will push it in the next version 0.4.24. |
I also encountered the same problem, but it was a little special. I directly used the code in the file https://colab.research.google.com/drive/1REChY6fXQf-EaVYLv0eHEWvzlYxGm0pd?usp=sharing#scrollTo=qUBKGpn3yZQN to execute. The first time I used "headless=True", the execution was successful, and the second time I used "headless=False", the execution was also successful, but the third time and thereafter, regardless of whether the value of "headless=" was set, the execution failed.
Complete Error Trace:
|
@mozou When you use it on Colab, you can't set the headless mode to false because there is no graphical virtualization available. I think that error occurred in the memory of Colab. I checked Colab, updated some of the code because they were using the old syntax, and I tested everything. Everything works well now, so you can give it another try. |
Issue:
The scraper encounters an
EvalError
while attempting to crawl the page athttps://www.tradingview.com/broker/FOREXcom/
. The error is triggered due to the page's Content Security Policy (CSP)code snippet to Reproduce:
Observed Error:
Complete Error Trace:
[ERROR]... × https://www.tradingview.com/broker/FOREXcom/... | Error:
┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ × Unexpected error in _crawl_web at line 528 in wrap_api_call (.venv/lib/python3.10/site- │
│ packages/playwright/_impl/_connection.py): │
│ Error: Page.wait_for_function: 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 │
│ https://static.tradingview.com/static/ blob: https://*.ampproject.org/ https://*.paypal.com/ │
│ https://platform.twitter.com/ https://platform.x.com/ https://songbird.cardinalcommerce.com/edge/v1/ │
│ https://checkout.razorpay.com/ https://cdn.checkout.com/ 'nonce-v+WIeNdKFxEFsPPe9saCNA=='". │
│ │
│ at eval () │
│ at predicate (eval at evaluate (:234:30), :11:37) │
│ at next (eval at evaluate (:234:30), :32:31) │
│ │
│ Code context: │
│ 523 parsed_st = _extract_stack_trace_information_from_stack(st, is_internal) │
│ 524 self._api_zone.set(parsed_st) │
│ 525 try: │
│ 526 return await cb() │
│ 527 except Exception as error: │
│ 528 → raise rewrite_error(error, f"{parsed_st['apiName']}: {error}") from None │
│ 529 finally: │
│ 530 self._api_zone.set(None) │
│ 531 │
│ 532 def wrap_api_call_sync( │
│ 533 self, cb: Callable[[], Any], is_internal: bool = False
The text was updated successfully, but these errors were encountered: