question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

recommended way to disable request capture errors with puppeteer/node

See original GitHub issue

Hey there,

I’m trying to use pollyjs with puppeteer and I’m encountering a problem, some non-critical requests are erroring out when changing the page with puppeteer’s goto(). This is happening even in passthrough mode.

  console.group node_modules/@pollyjs/core/dist/cjs/pollyjs-core.js:2296
        Errored ➞ POST https://www.google-analytics.com/collect

  console.error node_modules/@pollyjs/core/dist/cjs/pollyjs-core.js:2297
        { errorText: 'net::ERR_ABORTED' }

I’m not sure exactly what this error is indicating either.

This causes the whole test to fail. I’m wondering if there is an easy way to have polly ignore requests for this url, or disable throwing errors selectively or entirely.

The test is fairly simple:

it('should do something', async () => {
  await page.setBypassCSP(true)
  await page.setRequestInterception(true)
  const polly = await new Polly(
    `should-do-something`,
    {
      mode: 'passthrough',
      adapters: ['puppeteer'],
      adapterOptions: {
        puppeteer: { page },
      },
      recordFailedRequests: true,
      logging: false,
    }
  )
  await page.goto('http://localhost:3000')
  await page.goto('http://localhost:3000')
})

Package versions:

"@pollyjs/adapter-puppeteer": "2.6.3",
"@pollyjs/core": "2.6.3",
"@pollyjs/persister-fs": "2.6.3",
"jest": "24.9.0",
"jest-puppeteer": "4.3.0",
"puppeteer": "1.20.0",

Trace:

    Evaluation failed: TypeError: Failed to fetch

      at ExecutionContext._evaluateInternal (../../node_modules/puppeteer/lib/ExecutionContext.js:122:13)
        -- ASYNC --
      at ExecutionContext.<anonymous> (../../node_modules/puppeteer/lib/helper.js:111:15)
      at DOMWorld.evaluate (../../node_modules/puppeteer/lib/DOMWorld.js:112:20)
        -- ASYNC --
      at Frame.<anonymous> (../../node_modules/puppeteer/lib/helper.js:111:15)
      at Page.evaluate (../../node_modules/puppeteer/lib/Page.js:833:43)
      at Page.<anonymous> (../../node_modules/puppeteer/lib/helper.js:112:23)
      at evaluate (../../node_modules/@pollyjs/adapter-puppeteer/src/index.js:171:14)
      at new F (../../node_modules/core-js/library/modules/_export.js:36:28)
      at PuppeteerAdapter.passthroughRequest (../../node_modules/@pollyjs/adapter-puppeteer/src/index.js:166:30)
      at PuppeteerAdapter.passthroughRequest [as onPassthrough] (../../node_modules/@pollyjs/adapter/src/index.js:269:33)
      at PuppeteerAdapter.onPassthrough [as passthrough] (../../node_modules/@pollyjs/adapter/src/index.js:129:17)
      at PuppeteerAdapter.passthrough (../../node_modules/@pollyjs/adapter/src/index.js:104:19)
        -- ASYNC --
      at Page.<anonymous> (../../node_modules/puppeteer/lib/helper.js:111:15)
      at evaluate (../../node_modules/@pollyjs/adapter-puppeteer/src/index.js:171:14)
      at new F (../../node_modules/core-js/library/modules/_export.js:36:28)
      at PuppeteerAdapter.passthroughRequest (../../node_modules/@pollyjs/adapter-puppeteer/src/index.js:166:30)
      at PuppeteerAdapter.passthroughRequest [as onPassthrough] (../../node_modules/@pollyjs/adapter/src/index.js:269:33)
      at PuppeteerAdapter.onPassthrough [as passthrough] (../../node_modules/@pollyjs/adapter/src/index.js:129:17)
      at PuppeteerAdapter.passthrough (../../node_modules/@pollyjs/adapter/src/index.js:104:19)
      at PuppeteerAdapter.handleRequest (../../node_modules/@pollyjs/adapter/src/index.js:78:13

If this is a non-trivial case I can make a repro.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11

github_iconTop GitHub Comments

1reaction
jasonmitcommented, Oct 21, 2019

I don’t believe it’s Polly that’s throwing, it’s the fact that the request hasn’t settled when transitioning away because of the same issue in #248 and so Chrome throws. I may not be correct about this but that’s what I believe is happening.

0reactions
jasonmitcommented, Feb 6, 2020

Closing in favor of tracking core issue in #248

Read more comments on GitHub >

github_iconTop Results From Across the Web

Basic Error Handling - Puppeteer NodeJS p.5 - YouTube
How to do basic error handling with Puppeteer. ... 7.1K views 2 years ago Browser Automation & Web Scraping with Puppeteer & NodeJS....
Read more >
How to avoid being detected as bot on Puppeteer and ...
I discovered that the problem doesn't happen when I tested on Postman using a header named Cookie and the value of it's cookie...
Read more >
Let It Crash: Best Practices for Handling Node.js Errors on ...
We recommend running more than one process and to use a load balancer to handle the scheduling. That way, if one of the...
Read more >
Getting to Know Puppeteer Using Practical Examples
An overview, concrete guide and kinda cheat sheet for the popular browser automation library, based on Node.js, which provides a high-level ...
Read more >
Puppeteer | Puppeteer
Puppeteer is a Node.js library which provides a high-level API to control ... Capture a timeline trace of your site to help diagnose...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found