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

Puppeteer adapter: "Evaluation failed: TypeError: Failed to fetch" #149

Closed
2xAA opened this issue Dec 14, 2018 · 12 comments · Fixed by #197
Closed

Puppeteer adapter: "Evaluation failed: TypeError: Failed to fetch" #149

2xAA opened this issue Dec 14, 2018 · 12 comments · Fixed by #197

Comments

@2xAA
Copy link

2xAA commented Dec 14, 2018

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.

@offirgolan
Copy link
Collaborator

@2xAA if you can post the following:

  • All your @pollyjs package versions
  • Puppeteer version
  • Polly config
  • Your test code (if possible)

@2xAA
Copy link
Author

2xAA commented Dec 17, 2018

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:

  • @pollyjs/adapter-puppeteer": "^1.4.1"
  • @pollyjs/core": "^1.4.1"
  • @pollyjs/persister-fs": "^1.4.1"
  • puppeteer: "^1.11.0"
  • jest: "^23.6.0"
  • setup-polly-jest: "^0.5.2"

@jasonmit
Copy link
Contributor

Closing for now since there isn't anything actionable. We'll keep an eye out for this in the future.

@scotthovestadt
Copy link

FYI this happens because of CSP errors and can be resolved with:

await page.setBypassCSP(true);

@jasonmit
Copy link
Contributor

jasonmit commented Apr 9, 2019

@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

@jasonmit jasonmit reopened this Apr 9, 2019
@scotthovestadt
Copy link

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')

Screen Shot 2019-04-09 at 12 41 02 AM

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?

@jasonmit
Copy link
Contributor

jasonmit commented Apr 9, 2019

@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?

@scotthovestadt
Copy link

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.

@jasonmit
Copy link
Contributor

jasonmit commented Apr 9, 2019

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.

@jasonmit
Copy link
Contributor

jasonmit commented Apr 9, 2019

@scotthovestadt yeah, exactly! Will be resolved by #197

Thanks for bringing all this context to the discussion, super helpful.

@scotthovestadt
Copy link

Glad I could help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants