You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

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
Question marked as Top-ranking reply

Posted on Jun 1, 2021 3:30 PM

There are posts on the net going all the way back to Safari 5 timeframe where problems were encountered with window.print() and document.execCommand('print', false, null). I don't know how to solve your current issue with an opened PDF.

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

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.