Window.print() Doesn't Work in Safari When Viewing PDFs

Using `window.print()` in Safari when viewing a PDF does not bring up the print dialog and it causes the browser tab to freeze.

The behaviour only seems to exist in specific versions of Safari.


Steps to Reproduce:

  1. Open any PDF in Safari (eg. https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf)
  2. Open console and enter window.print() or document.execCommand('print', false, null);
  3. No print dialog is displayed and the browser tab now seems to freeze (eg. PDF contents don't react to window resizing).


It feels like Safari thinks the print dialog is open and is blocking the thread, but nothing shows up visually.



Safari Version: 14.1.1 (16611.2.7.1.4)

macOS Version: Big Sur (11.4)


MacBook Pro 16″, macOS 11.4

Posted on May 31, 2021 12:18 PM

Reply

Similar questions

3 replies

Jun 1, 2021 8:00 AM in response to VikingOSX

The issue I'm having is specifically when viewing PDFs in Safari.


In the link you provided, I can enter `window.print()` in the console and it will bring up the print preview dialog. It doesn't have to be tied to a button click.


In the original link I provided, entering `window.print()` in the console causes the tab to become unresponsive.


The workflow that I was working on which uncovered this issue was:

  1. User clicks `Print` button
  2. We open a new tab with the PDF and trigger the print dialog to open using javascript


I believe this worked on older versions of macOS / Safari but I don't have access to an older environment now to confirm.

It also works in the other major browsers (Chrome / Firefox).

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Window.print() Doesn't Work in Safari When Viewing PDFs

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.