How can I bypass the CSP in PlaywrightCrawler?

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'".",
5 Replies
rare-sapphire
rare-sapphire3y ago
Hi @Youcef, setting the --disable-web-security argument in launchContext args should do the trick.
const crawler = new PlaywrightCrawler({
launchContext: {
launchOptions: {
args: ['--disable-web-security']
},
},
...
});
const crawler = new PlaywrightCrawler({
launchContext: {
launchOptions: {
args: ['--disable-web-security']
},
},
...
});
genetic-orange
genetic-orangeOP3y ago
Hi @vojtechmaslan, I already tried that, and it's not working. I'm receiving the above error. Hi @Ondra Urban, can you help with this?
rare-sapphire
rare-sapphire3y ago
Can you please send a snippet of code where you create the crawler instance?
other-emerald
other-emerald3y ago
It's a bug in Playwright. Workaround in this issue: https://github.com/microsoft/playwright/issues/7395#issuecomment-1515521478
genetic-orange
genetic-orangeOP3y ago
Problem solved. Thank you!

Did you find this page helpful?