Issue 1:
Context:

Playwright Version: 1.10.0

Operating System: Linux OpenSUSE Leap 15.2

Node.js version: 14.16.0

Browser: Chromium

Code Snippet

Help us help you! Put down a short code snippet that illustrates your bug and

that we can run and debug locally. For example:

test('can we export it to PDF?', async () => {
const [popup] = await Promise.all([page?.waitForEvent('popup'), page.click('button:has-text("Export as PDF")')]);

await popup.waitForNavigation({
waitUntil: 'networkidle',
timeout: 5000,
});

expect(await popup.url().startsWith('blob')).toBeTruthy();
});

Describe the bug

Basically, this script clicks a button which opens a new tab with a blob:https://URL_EXAMPLE_OF_PDF of a PDF. When it's in non-headless mode, you can see it and it works. Tests pass. When it's in headless mode, the test fails like so:

TimeoutError: page.waitForNavigation: Timeout 5000ms exceeded.
=========================== logs ===========================
waiting for navigation until "networkidle"
============================================================
Note: use DEBUG=pw:api environment variable to capture Playwright logs.

at node_modules/playwright/lib/client/waiter.js:49:51
at Waiter.waitForPromise (node_modules/playwright/lib/client/waiter.js:57:28)
at node_modules/playwright/lib/client/frame.js:120:36
at Frame._wrapApiCall (node_modules/playwright/lib/client/channelOwner.js:77:28)

Issue 2:
Context:

Playwright Version: 1.10.0

Operating System: MacOS 11.3

Node.js version: 15.11.0

Browser: Chromium (works fine w/ Firefox)

Code Snippet

Create the following HTML file in your local webserver's DocumentRoot:

<a href="test.pdf" target="_blank">Link to PDF file</a>

Put a PDF file with the name "test.pdf" in the same directory.

Run the following PW code:

const { chromium } = require('playwright');

(async () => {
const browser = await chromium.launch({
headless: true,
});
const context = await browser.newContext();
const page = await context.newPage();
await page.setViewportSize({
width: 1200,
height: 1200,
});

await page.goto('localhost/a.html');

const [pagePDF] = await Promise.all([
context.waitForEvent('page'),
await page.click('text=Link to PDF file'),
]);

await pagePDF.waitForLoadState();
console.log('Load state reached.');
await browser.close();
})();

Describe the bug

After 30 seconds you will get the following error message:

/[...]/node_modules/playwright/lib/client/waiter.js:57
const result = await Promise.race([promise, ...this._failures]);
^
TimeoutError: page.waitForLoadState: Timeout 30000ms exceeded.
=========================== logs ===========================
"networkidle" event fired
============================================================
Note: use DEBUG=pw:api environment variable to capture Playwright logs.
at /[...]/node_modules/playwright/lib/client/waiter.js:49:51
at Waiter.waitForPromise (/[...]/node_modules/playwright/lib/client/waiter.js:57:28)
at /[...]/node_modules/playwright/lib/client/frame.js:150:13
at Frame._wrapApiCall (/[...]/node_modules/playwright/lib/client/channelOwner.js:77:28)

Process finished with exit code 1

The expected behavior is instead to get the following console log messages:

Load state reached.

Process finished with exit code 0

The above code works fine when run with Chromium in headful mode or when run with Firefox either in headless or headful mode.