Repository: puppeteer
Issue: [Bug]: networkidle2 (networkidle) event is not triggered and page navigation times out
Labels: bug,confirmed,P3

### Minimal, reproducible example

```TypeScript
const browser = await puppeteer.launch({
	headless: 'new',
	executablePath: 'google-chrome',
	args: [
		'--accept-lang=en-GB',
		'--no-sandbox',
		'--disable-setuid-sandbox',
		'--disable-dev-shm-usage',
	],
});

const url = `http://...`;

const page = await browser.newPage();

await page.goto(url, {
	timeout: 60 * 1000,
	waitUntil: ['domcontentloaded', 'networkidle2'],
});
```


### Error string

TimeoutError: Navigation timeout of 60000 ms exceeded

### Bug behavior

- [X] Flaky
- [ ] PDF

### Background

The navigation doesn't successfully happen because the `networkidle2` is not triggered within 60s:

```
TimeoutError: Navigation timeout of 60000 ms exceeded
    at new Deferred (/home/kawa/kawa-gui/scripts/node_modules/puppeteer-core/lib/cjs/puppeteer/util/Deferred.js:26:34)
    at Deferred.create (/home/kawa/kawa-gui/scripts/node_modules/puppeteer-core/lib/cjs/puppeteer/util/Deferred.js:68:16)
    at new LifecycleWatcher (/home/kawa/kawa-gui/scripts/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/LifecycleWatcher.js:75:60)
    at CdpFrame.goto (/home/kawa/kawa-gui/scripts/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/Frame.js:140:29)
    at CdpFrame.<anonymous> (/home/kawa/kawa-gui/scripts/node_modules/puppeteer-core/lib/cjs/puppeteer/util/decorators.js:108:27)
    at CdpPage.goto (/home/kawa/kawa-gui/scripts/node_modules/puppeteer-core/lib/cjs/puppeteer/api/Page.js:602:43)
    at takeScreenshots (/home/kawa/kawa-gui/scripts/chart-export.js:79:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
```

I inspected the [CDP](https://chromedevtools.github.io/devtools-protocol/) exchange between Chrome and Puppeteer and I can see both [networkAlmostIdle (networkidle2)](https://github.com/puppeteer/puppeteer/blob/b9ce89e460702ad85314685c600a4e5267f4db9b/packages/puppeteer-core/src/cdp/LifecycleWatcher.ts#L71) and networkIdle (networkidle0) triggered for the initial `about:blank` page, but not for the page I'm navigating to.

```
DEBUG="puppeteer:*" ./debug chart 2>&1 | grep lifecycleEvent

"method":"Page.lifecycleEvent","params":{"frameId":"EB64F846ACD2D5033A2CFEA54D03A429","loaderId":"1000663569D748F816FF216F5EA82E75","name":"commit","timestamp":257849.706331}
"method":"Page.lifecycleEvent","params":{"frameId":"EB64F846ACD2D5033A2CFEA54D03A429","loaderId":"1000663569D748F816FF216F5EA82E75","name":"DOMContentLoaded","timestamp":257849.706551}
"method":"Page.lifecycleEvent","params":{"frameId":"EB64F846ACD2D5033A2CFEA54D03A429","loaderId":"1000663569D748F816FF216F5EA82E75","name":"load","timestamp":257849.708667},"sessionId"
"method":"Page.lifecycleEvent","params":{"frameId":"EB64F846ACD2D5033A2CFEA54D03A429","loaderId":"1000663569D748F816FF216F5EA82E75","name":"networkAlmostIdle","timestamp":257849.708342}
"method":"Page.lifecycleEvent","params":{"frameId":"EB64F846ACD2D5033A2CFEA54D03A429","loaderId":"1000663569D748F816FF216F5EA82E75","name":"networkIdle","timestamp":257849.708342}

"method":"Page.lifecycleEvent","params":{"frameId":"EB64F846ACD2D5033A2CFEA54D03A429","loaderId":"DA2332BC98C0BF118ACDB95E6A04CF6E","name":"init","timestamp":257849.77887}
"method":"Page.lifecycleEvent","params":{"frameId":"EB64F846ACD2D5033A2CFEA54D03A429","loaderId":"DA2332BC98C0BF118ACDB95E6A04CF6E","name":"DOMContentLoaded","timestamp":257850.672159}
"method":"Page.lifecycleEvent","params":{"frameId":"EB64F846ACD2D5033A2CFEA54D03A429","loaderId":"DA2332BC98C0BF118ACDB95E6A04CF6E","name":"load","timestamp":257850.685038}
"method":"Page.lifecycleEvent","params":{"frameId":"EB64F846ACD2D5033A2CFEA54D03A429","loaderId":"DA2332BC98C0BF118ACDB95E6A04CF6E","name":"firstPaint","timestamp":257851.838795}
"method":"Page.lifecycleEvent","params":{"frameId":"EB64F846ACD2D5033A2CFEA54D03A429","loaderId":"DA2332BC98C0BF118ACDB95E6A04CF6E","name":"firstContentfulPaint","timestamp":257851.838798}
"method":"Page.lifecycleEvent","params":{"frameId":"EB64F846ACD2D5033A2CFEA54D03A429","loaderId":"DA2332BC98C0BF118ACDB95E6A04CF6E","name":"firstMeaningfulPaintCandidate","timestamp":257851.8388}
"method":"Page.lifecycleEvent","params":{"frameId":"EB64F846ACD2D5033A2CFEA54D03A429","loaderId":"DA2332BC98C0BF118ACDB95E6A04CF6E","name":"firstMeaningfulPaintCandidate","timestamp":257852.110374}
"method":"Page.lifecycleEvent","params":{"frameId":"EB64F846ACD2D5033A2CFEA54D03A429","loaderId":"DA2332BC98C0BF118ACDB95E6A04CF6E","name":"firstMeaningfulPaintCandidate","timestamp":257852.705155}
"method":"Page.lifecycleEvent","params":{"frameId":"EB64F846ACD2D5033A2CFEA54D03A429","loaderId":"DA2332BC98C0BF118ACDB95E6A04CF6E","name":"firstImagePaint","timestamp":257852.986711}
"method":"Page.lifecycleEvent","params":{"frameId":"EB64F846ACD2D5033A2CFEA54D03A429","loaderId":"DA2332BC98C0BF118ACDB95E6A04CF6E","name":"InteractiveTime","timestamp":257858.939075}
```

So I tried to figure out which request is hanging by implementing the functionality to track requests [described here](https://github.com/puppeteer/puppeteer/issues/1353#issuecomment-648299486). When I used this implementation instead of the puppeteer's `networkidle2` the navigation was successful:

```
await Promise.all([
	page.goto(url, { timeout: 60 * 1000, waitUntil: ['domcontentloaded'] }),
	waitForNetworkIdle(page, { maxInflightRequests: 0 }),
]);
```

so I can conclude that **there are no** outstanding/in-flight requests that blocks the event from emitting. In fact, when I generated a screenshot with `page.screenshot` while the `page.goto` request was hanging, I could see the page loaded/rendered.

So what could be the reason for the fact that Chrome doesn't report the event? How do I debug it?

I generated network log for Chrome [using these insturctions](https://www.chromium.org/for-testers/providing-network-details/). But I'm not sure what to look for there, maybe somebody could suggest ideas.

Versions:
```
Puppeteer 21.7.0
Node 20.10.0
Google Chrome 120.0.6099.71
```

### Expectation

When requests are finished, the `networkidle2`/`networkidle` is triggered and the `page.goto` successfully resolves.

### Reality

Navigation timeout of 60ms throws.

### Puppeteer configuration file (if used)

_No response_

### Puppeteer version

21.7.0

### Node version

20.10.0

### Package manager

npm

### Package manager version

10.2.3

### Operating system

Linux