Skip to content

[BUG] PDF Viewer does not work in headless Chromium and leads to download the file instead #6342

@klhex

Description

@klhex

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

  1. Create the following HTML file in your local webserver's DocumentRoot:
<a href="test.pdf" target="_blank">Link to PDF file</a>
  1. Put a PDF file with the name "test.pdf" in the same directory.

  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions