Christopher Schultz
Christopher Schultz

Reputation: 20837

How to show print dialog from javascript without getting "Page Unresponsive" warnings?

I've got a page with a simple "print" image/link that executes a simple javascript onclick handler. I'm finding that Chrome will complain about the page with a "Page Unresponsive" warning when I take too long to inspect the print dialog. I do not see this behavior in other browsers.

The HTML looks like this:

<a onclick="if(window.print) window.print(); return false;">
  <img src="print-button.png" alt="[Print]" />
</a>

There are no other active scripts on the page, so I'm guessing that this onclick handler is the problem. My guess is that Chrome does something like this behind the scenes:

  1. Accept click event from OS
  2. See onclick handler exists
  3. Start stopwatch
  4. Invoke onclick handler
  5. onclick handler calls window.print() (which blocks, waiting for user input)
  6. [time passes]
  7. Stopwatch indicates that too much time has passed
  8. Chrome issues a warning to the user

I would consider this a bug in Chrome, if true, since the window.print call shouldn't be "timed". That is, it's a blocking user-interactive action and the user is allowed to take as much time as they need.

I've tried cheating by doing this:

<a onclick="if(window.print) setTimeout(function() { window.print(); }, 0); return false;">
  <img src="print-button.png" alt="[Print]" />
</a>

... but it does not change anything -- Chrome still complains about the long-running script.

Am I using the wrong technique to trigger the print dialog? Or is this a bug in Chrome?

I am running v72.0.3626.119 on 64-bit Mac and I cannot reproduce this while I have a client running the same version in 64-bit Windows and she is reporting this issue.

Upvotes: 5

Views: 647

Answers (1)

ascott18
ascott18

Reputation: 800

This appears to be a known bug in Chrome since Feb 27 2018 / Chrome 64

There is a fix slated for Chrome 73

https://bugs.chromium.org/p/chromium/issues/detail?id=816869

Upvotes: 2

Related Questions