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.

Request interceptions cause web workers network requests to hang

See original GitHub issue

When setting a request interception to a page, the page’s workers can no longer make network request, because otherwise they will stop responding. both importScripts and fetch.

It is critical to mention that this behavior does work on native CDP

Steps to reproduce

I’ve created a repo with a script that does the following, and also shows that a “native” implementation using CDP alone does work:

  • Serve a static site with worker.js that makes a network call of some sort
  • Create a new browser page with interceptions:
    await page.setRequestInterception(true);
    await page.on('request', request => request.continue);
    
  • See how it causes the worker to stop responding!

Tell us about your environment:

  • Puppeteer version: 1.13.0
  • Platform / OS version: OSX
  • URLs (if applicable):
  • Node.js version: v10.15.3

What steps will reproduce the problem?

Please include code that reproduces the issue.

  1. Clone https://github.com/Schniz/puppeteer-workers-bug
  2. npm i
  3. node puppeteer.js

What is the expected result?

The following works:
--------------------
1
{
  "userId": 1,
  "id": 1,
  "title": "delectus aut autem",
  "completed": false
}
finished

But when intercepted, it doesn't!
--------------------------
1

Although it does work with CDP directly:
----------------------------------------
http://localhost:5000/
http://localhost:5000/worker.js
https://jsonplaceholder.typicode.com/todos/1
1
{
  "userId": 1,
  "id": 2,
  "title": "quis ut nam facilis et officia qui",
  "completed": false
}
finished

What happens instead?

The following works:
--------------------
1
{
  "userId": 1,
  "id": 1,
  "title": "delectus aut autem",
  "completed": false
}
finished

But when intercepted, it doesn't!
--------------------------
1

Although it does work with CDP directly:
----------------------------------------
1
{
  "userId": 1,
  "id": 2,
  "title": "quis ut nam facilis et officia qui",
  "completed": false
}
finished

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:5
  • Comments:16 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
felixfbeckercommented, Jul 14, 2020

Having the same issue, importScript() is just handling and not triggering the request interceptor. The workaround in https://github.com/puppeteer/puppeteer/issues/4208#issuecomment-563178898 doesn’t solve the problem if you need to intercept the requests that happen inside the worker.

2reactions
stale[bot]commented, Oct 23, 2022

We’re marking this issue as unconfirmed because it has not had recent activity and we weren’t able to confirm it yet. It will be closed if no further activity occurs within the next 30 days.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Chapter 4. Intercepting network requests - Progressive Web ...
A Service Worker's ability to intercept any outgoing HTTP requests is what makes it so powerful. Every HTTP request that falls within this...
Read more >
Can a service worker intercept http requests coming from a ...
I would like to know whether the service worker can intercept http request coming from the Worker Threads (web worker). The reason for...
Read more >
Cypress cy.intercept Problems - Gleb Bahmutov
To learn how to effectively spy and stub network requests in your ... at the if-none-match request header sent by the web application....
Read more >
Mock Service Worker adopts a brand-new request interception ...
There's simply no intermediate network layer like Service Workers in Node.js. Once requests happen, they happen, and nothing can intercept them ...
Read more >
Understanding Service Workers and Caching Strategies
Some of these features are proxying network requests, ... where the request is intercepted by the service worker and the request is made...
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