Issue metadata
Sign in to add a comment
|
Chrome for Android window.print() behavior no longer works after 68
Reported by
cory.ada...@gmail.com,
Dec 21
|
||||||||||||||||||||||||
Issue description
Steps to reproduce the problem:
1. var tmpwindow = Window.open();
2. tmpwindow.document.open();
3. tmpwindow.document.write('stuff here');
4. tmpwindow.print();
5. tmpwindow.document.close();
5. setTimeout(function(){tmpwindow.close();},10);
What is the expected behavior?
The print window opens, it shows the preview. changing printers behaves fine, cloud print behaves fine. You can then print and all is fine. The printed window closes automatically when canceling or printing.
What went wrong?
The print dialog window opens but I get no preview and printers are greyed out with an error "there was a problem printing the page. Please try again (retry)". If I adjust the timeout to say 1000 or longer, you do get a preview, but then when switching printers you may get the error again and printers grey out, or the printer constraints (like paper size) do not refresh and resize the document.
Did this work before? Yes 60.0.3112.116
Chrome version: 71.0.3578.99 Channel: stable
OS Version: 7.1.1
Flash Version:
This had worked before and we use this quite heavily at work. I've had to prevent any auto updates to chrome to prevent this from preventing label printing from the browser and cloud print. This does have something to do with the setTimeout() function specifically. If you remove that statement, it works. I have not been able to find a workaround like print event listeners don't work so well with android. Need to be able to close the printed window automatically. the fact that this doesnt work feels like a regression. Please help! :)
,
Dec 24
@ cory.adamson: Sample test URL or apk and screencast on reproducing would help in further triaging of the issue. Along with it please provide device details on which this issue is seen. Thanks!
,
Dec 28
,
Jan 16
(6 days ago)
I tried this and it works fine for me. - For the JS code, "Window.open()" should not have any capital letters. - The first time I tried loading a HTML file with this JS code, the popup blocker intervined. I had to tell the popup blocker to always allow this popup. ctzsm: Can you repro?
,
Jan 16
(6 days ago)
The device are SAMSUNG TAB E, duplicated behavior on a Samsung S7
I can reproduce with the window.open() not in capitals.
Please ensure that you are using Chrome in Android
Here is my exact code:
var divToPrint= document.getElementById('labels').innerHTML;
var newWin=window.open('','Print-Window');
newWin.document.open();
newWin.document.clear();
newWin.document.writeln('<html xmlns="http://www.w3.org/1999/xhtml"><head><title></title><style type="text/css" media="print"> @page { size: auto; margin: 0mm; }</style> </head> <body>');
newWin.document.write(divToPrint);
newWin.document.writeln("</body></html>");
newWin.print();
newWin.document.close();
setTimeout(function(){newWin.close();},10);
If you extend the window timeout to say 5 seconds, you get more printing options before it greys out. The printer selection may grey out while you get the message "There was a problem printing the page. Please try again."
Sometimes if you leave it be, it then recovers and you get the printer drop down again. If you select a printer, it then doesn't resize based on the medium and kind of freezes up. For this example, we print on a label maker, so the medium is quite small. This happens on every device this version of chrome is installed on. If you remove the .close() functions, it works as expected but then you have to deal with the temporary print windows.
So it has something to do with that.
expected.jpg is the expected behavior that comes up immediately without greyouts, or problem printing errors.
Please note, if I down-grade chrome, the behavior disappears and everything works as you would expect.
,
Jan 16
(6 days ago)
Thank you for providing more feedback. Adding the requester to the cc list. For more details visit https://www.chromium.org/issue-tracking/autotriage - Your friendly Sheriffbot
,
Jan 16
(6 days ago)
I could repro this issue. I also have the popup blocker. Other than that, I think the issue is due to my refactoring which caused window.print() from sometimes blocking to always non-blocking, so the content you are going to print is not available anymore due to setTimeout() now comes much earlier than before. On the other hand, I just realized that onafterprint event is not ideal for working around this issue due to issue 849495 on Android. I am sorry about the current situation and I'll find some time slot to fix issue 849495. I suggest you to use an invisible iframe instead of opening a new page to avoid the popup blocker and have easier controlling of the life cycle. With that, use onbeforeprint to inject the content and onafterprint to remove the content. One caveat is that you need to make sure the content you injected in onbeforeprint to be the same through out the printing session. I attached my demo, please have a look.
,
Jan 16
(6 days ago)
,
Jan 16
(6 days ago)
Actually I'll just dup this issue to issue 904447, since their root causes are the same.
,
Jan 16
(6 days ago)
Thanks for the response! Ill try the suggested iFrame suggestion until this has been fixed. :) |
|||||||||||||||||||||||||
►
Sign in to add a comment |
|||||||||||||||||||||||||
Comment 1 by chelamcherla@chromium.org
, Dec 24Labels: Needs-triage-Mobile