Closed 2xAA closed 5 years ago
@2xAA if you can post the following:
We decided not to use Polly in our project in the end. Using Puppeteer by itself provides enough functionality for us.
I doubt this issue would have been too helpful anyway as I'm unable to share the website we were testing or much of the test code.
Using the same test code with other websites didn't produce this error.
Setting the requestResourceTypes
array to use only xhr
squished this error, but then Puppeteer was throwing a different eval error for XHR requests instead.
Setting requestResourceTypes
to a blank Array allowed this to run without errors, but no network requests were being captured by Puppeteer either.
These are my versions, just in case:
Closing for now since there isn't anything actionable. We'll keep an eye out for this in the future.
FYI this happens because of CSP errors and can be resolved with:
await page.setBypassCSP(true);
@scotthovestadt do you know in what scenario this happens?
Any chance you can PR a fail test for adapter-puppeteer/tests/integration/adapter-test.js
An easy way to reproduce it is to just open the console on github.com (this page works fine) and enter:
fetch('https://github.githubassets.com/favicon.ico')
This shows in the console as:
Evaluation failed: TypeError: Failed to fetch
at anonymous (__puppeteer_evaluation_script__:3:8)
at ExecutionContext.evaluateHandle (node_modules/puppeteer/lib/ExecutionContext.js:122:13)
...
It's triggered by the following header:
Content-Security-Policy: default-src 'none'; base-uri 'self'; block-all-mixed-content; connect-src 'self' uploads.github.com www.githubstatus.com collector.githubapp.com api.github.com www.google-analytics.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com wss://live.github.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com; frame-ancestors 'none'; frame-src render.githubusercontent.com; img-src 'self' data: github.githubassets.com identicons.github.com collector.githubapp.com github-cloud.s3.amazonaws.com *.githubusercontent.com; manifest-src 'self'; media-src 'none'; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com
I'll look into setting up a fail test, but regardless is probably a good idea to just recommend that the user turn this on in the documentation or even in the error message for fetch
failing. I'm not seeing an easier way to work around it (unless you want to turn it on for them).
Thoughts?
@scotthovestadt I agree with adding a warning the documentation.
However, I'm a bit confused. If the CSP rules do not account for a hostname you're trying to reach then I'd except the CSP violation with or without Polly being present. Is that not the case?
It's not trying to fetch
the resources by itself, that's done by Polly:
https://github.com/Netflix/pollyjs/blob/master/packages/%40pollyjs/adapter-puppeteer/src/index.js#L179
Ordinarily the favico would be loaded "normally" but it's proxied through fetch
and then fails because of CSP.
This sounds like a bug where non-xhr requests are being picked up via Polly. The expectation would be Polly wouldn't be proxying these sorts of resource requests. We'll need to investigate why that's happening.
@scotthovestadt yeah, exactly! Will be resolved by https://github.com/Netflix/pollyjs/pull/197
Thanks for bringing all this context to the discussion, super helpful.
Glad I could help!
I'm attempting to use Polly in an existing project to test a webform, however upon adding Polly with the Puppeteer adapter I'm running into this error from Puppeteer.
Evaluation failed: TypeError: Failed to fetch
This error isn't present without Polly and the Puppeteer adapter.
I can provide more details upon request, but I'm unsure on what I need to share to diagnose this issue right now.
Thanks.