Print.js icon indicating copy to clipboard operation
Print.js copied to clipboard

Safari Big Sur first print attempt - blank page

Open dalia-s opened this issue 5 years ago • 26 comments

mackOS Big Sur 11.1 Safari 14.0.2

Reproducible on your own page:

  • load https://printjs.crabbly.com
  • click on the first available "print" button -> print dialog opens with blank page
  • cancel print and click "print" the second time -> "website trying to print dialog" -> print -> all good

image image

dalia-s avatar Jan 19 '21 15:01 dalia-s

I confirmed this issue when printing PDF documents in Safari on Big Sur. My guess is that the browser is flagging the document as cached before its actually finished, therefore the print job seems to be dispatched before the document is available, which results in a blank screen. More browser compatibility "fun" for us to play with :(

crabbly avatar Feb 18 '21 17:02 crabbly

I confirmed this issue when printing PDF documents in Safari on Big Sur. My guess is that the browser is flagging the document as cached before its actually finished, therefore the print job seems to be dispatched before the document is available, which results in a blank screen. More browser compatibility "fun" for us to play with :(

I'm having the same issue, I added a timestamp to my document to bypass the cache and my document is already loaded and shown on the page but nothing changes.

zakariamehbi avatar Mar 12 '21 09:03 zakariamehbi

We have the same issue. Has anybody already figured out from which version onwards this problem occurs?

cliffdeclerck avatar Mar 23 '21 14:03 cliffdeclerck

I'm facing the issue too. In my scenario i'm printing a live generated PDF, whose data is fetched via AJAX. I've tried to use the library in two different ways, in the hope that a different code path would have workaround-ed the Safari bug, but i had no luck

  1. First attempt: generating a local blob and submitting its url to the library printJs(blobUrl)
  2. Second attempt: submitting the raw base64 data
printJs({
    printable: base64Data,
    base64: true,
    type: 'pdf'
});

The bug still occours, while on the other browsers (Edge, FF, Chrome) it works perfectly

hinet2013 avatar Apr 21 '21 06:04 hinet2013

I had a hunch the contentWindow in safari wasn't quite ready so I've added a 1 second timeout before calling the print function in performPrint It seems to fix the problem, curious to know if this is also the case for others.

function performPrint (iframeElement, params) {
  try {
    iframeElement.focus()
    var 
    // If Edge or IE, try catch with execCommand
    if (Browser.isEdge() || Browser.isIE()) {
      try {
        iframeElement.contentWindow.document.execCommand('print', false, null)
      } catch (e) {
        iframeElement.contentWindow.print()
      }
    } else {
        setTimeout(function() {
             iframeElement.contentWindow.print();
             cleanUp(params)
         }, 1000);
    }
  } catch (error) {
    params.onError(error)
  } finally {
    if (Browser.isFirefox()) {
      // Move the iframe element off-screen and make it invisible
      iframeElement.style.visibility = 'hidden'
      iframeElement.style.left = '-1px'
    }
    if( Browser.isEdge() || Browser.isIE() ){
      cleanUp(params)
    }
    
  }
}```

egonvb avatar Apr 26 '21 13:04 egonvb

I'm facing this issue on Big Sur too. I haven't been able to get it to work first time with any combination of settings so I wondered if anyone had a workaround for the issue without altering the package?

jayhoogle avatar Apr 26 '21 14:04 jayhoogle

https://github.com/mstanowski/Print.js/blob/6502c73c7e1ba87346fe4913fa5de6220936095b/src/js/print.js#L16

Changed

16: if (Browser.isFirefox()) {

into

16: if (Browser.isFirefox() || Browser.isSafari()) {

and works for me now.

mstanowski avatar May 05 '21 12:05 mstanowski

Do you guys happen to get this popup when printing on safari?

image

EDIT: I found out you'll get this popup when you cancel the first print and then try to print again. This popup is also the reason why I always get a blank screen on safari.

chsami avatar May 12 '21 08:05 chsami

Safari 14.1.1 (macOS Big Sur): when I try to print an image, then cancel print prompt and try to open print dialog again, a dialog window appears saying "The webpage is trying to print. Do you want to print this webpage?". If I click "Print", the printing windows open up with the page to print being blank.

odragora avatar Jul 03 '21 12:07 odragora

Do you guys happen to get this popup when printing on safari?

image

EDIT: I found out you'll get this popup when you cancel the first print and then try to print again. This popup is also the reason why I always get a blank screen on safari.

Did you get a fix on this issue?

Ethaan avatar Jul 22 '21 17:07 Ethaan

Do you guys happen to get this popup when printing on safari?

image

EDIT: I found out you'll get this popup when you cancel the first print and then try to print again. This popup is also the reason why I always get a blank screen on safari.

Same issue here, Online etc, Thank u.

into-piece avatar Jul 29 '21 08:07 into-piece

Hey @crabbly this seems to have been fixed in this PR: https://github.com/crabbly/Print.js/pull/588 Do you think we can get it merged?

wmattei avatar Sep 13 '21 21:09 wmattei

Hi, For me the timeout did not help. I get the safari's alert message only if i trigger iframe.contentWindow.print(). So even the timeout is not helping in this case.

Is there any way i can disable the pop up ?

SivaramanJ avatar Sep 17 '21 04:09 SivaramanJ

Same here. I also experience the problem with the timeout hotfix.. any tips?

ftlno avatar Oct 12 '21 14:10 ftlno

any news here yet? Really need printing in safari and firefox..

ftlno avatar Oct 30 '21 08:10 ftlno

Seems to still be an issue.. any word?

Trimakas avatar Nov 11 '21 23:11 Trimakas

Any updates on this issue? I'm using safari 15.1 and still experiencing this, the timeout didn't work for me nor the fact that the entire print function is async and i wait longer then 1 second before the print dialogue opens and displays a blank page, in FF and Chrome it works perfectly, also before a certain update this has worked properly I'm not sure which one

greardrear avatar Nov 16 '21 10:11 greardrear

Any update? Thanks.

mstroming avatar Dec 15 '21 21:12 mstroming

I am also experiencing the same issue on safari 14 and 15.1, Any updates on this please? Thanks

ashutoshsinghjadon avatar Jan 25 '22 01:01 ashutoshsinghjadon

https://github.com/mstanowski/Print.js/blob/6502c73c7e1ba87346fe4913fa5de6220936095b/src/js/print.js#L16

Changed

16: if (Browser.isFirefox()) {

into

16: if (Browser.isFirefox() || Browser.isSafari()) {

and works for me now.

I forked this and it works for me as well. I've commented on the PR in hopes of getting a minor release. Though it might be safari, they already implement this logic for Firefox so why not include Safari?

spacejamjim avatar Feb 02 '22 13:02 spacejamjim

The timeout does not help for me and wont fix this for safari >= 14. I dont know the solution though

daphnesmit avatar Feb 10 '22 12:02 daphnesmit

Also I send this to Jen Simmons of Safari. curious to see Safari's reaction: https://twitter.com/daphnesmit/status/1491783519386828802

daphnesmit avatar Feb 10 '22 14:02 daphnesmit

Here is a simple reproduction aswell: https://codepen.io/erikdonohoo/pen/qxeNMe (I now use a very ugly hack where onPrintDialogClose I refresh the page only when isSafari and version is 14+)

daphnesmit avatar Feb 11 '22 08:02 daphnesmit

Hello, same here.

At first click, I have the safari print popup with a blank page : Screenshot 2022-03-04 at 12 04 38

After pressing cancel and retrying with a second click, it will invoke the "This web page is trying to print..." popup :

Screenshot 2022-03-04 at 12 05 36

And it works as expected : Screenshot 2022-03-04 at 12 09 30

To reproduce I refresh the window. But it's anoying for the user to cancel the first try everytime.

Safari : Version 14.0.2 (16610.3.7.1.9) / also tested with Safari 15, same bug. print-js : 1.6.0 (I'm aware that a Safari problem)

corneliugaina avatar Mar 04 '22 11:03 corneliugaina

@crabbly Not ideal, but how about a hack like this until Safari is fixed.

const print = () => {
  const popup = window.open("", "_blank", "width=1,height=1");
  popup.addEventListener("afterprint", (event) => {
    popup.close();
  });
  const content = document.getElementById("print-target");
  popup.document.head.innerHTML = document.head.innerHTML;
  popup.document.body.innerHTML = content.innerHTML;
  setTimeout(() => {
    popup.print();
    setTimeout(() => {
      popup.close();
    });
  });
};
document.querySelector("button").addEventListener("click", print);

https://codepen.io/gussietech/pen/GRQWYVM

GussieTech avatar May 18 '22 07:05 GussieTech

hi, problem still relevant today. Any idea ? regards

sc-mickael avatar Sep 21 '23 17:09 sc-mickael