Apify Discord Mirror

Updated 5 months ago

How can I bypass the CSP in PlaywrightCrawler?

At a glance

A community member is experiencing an issue with the PlaywrightCrawler, where they are receiving an error related to the Content Security Policy (CSP). They have tried setting the --disable-web-security argument in the launchContext of the crawler, but it did not work.

Other community members have provided suggestions, such as sharing the code snippet where the crawler instance is created. One community member has mentioned that this is a bug in Playwright and provided a workaround in a GitHub issue.

The issue has been resolved, and the community member has expressed their gratitude.

Useful resources
Bypass the CSP in PlaywrightCrawler is not working!

I'm receiving the following error:
"page.waitForFunction: 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 *.facebook.com *.fbcdn.net *.facebook.net *.google-analytics.com .google.com 127.0.0.1: 'unsafe-inline' blob: data: 'self' connect.facebook.net 'wasm-unsafe-eval'".",
v
Y
O
6 comments
Hi , setting the --disable-web-security argument in launchContext args should do the trick.
Plain Text
const crawler = new PlaywrightCrawler({
    launchContext: {
        launchOptions: {
            args: ['--disable-web-security']
        },
    },
    ...
});
Hi , I already tried that, and it's not working. I'm receiving the above error.
Hi , can you help with this?
Can you please send a snippet of code where you create the crawler instance?
Problem solved. Thank you!
Add a reply
Sign up and join the conversation on Discord