I struggled with the fact that Chrome removes Websocket connections if print preview is open for more than a few seconds. I traced it to this ticket , and the reason is that window.print() is synchronous and thus stops any other script execution, which in turn cause the network timeout and drop.
Since the ticket was opened 2.5 years ago, and is currently WontFix, I am looking for a workaround.
What i tried
Use window.open
I originally used an iframe to render content and print. Then I tried to move it to open a new tab, load the contents and print it.
window.open("iframe.html");
You can find a minimal example here (code here ). If you open the console, you will see its count every second. After 2 seconds, a pop-up window will open (you may have to enable pop-ups), which loads the print in a new tab. Wait a few seconds, then close the preview. If you return to the original tab, you will see that the counter is stopped.
Use binding
Then I tried to use the anchor tag with target="_blank" , for example:
<a href="iframe.html" target="_blank">print</a>
(Example here , code here )
This opens a new tab, but the counter still stops. If I right-click on a link and use Open link in new tab , then the counter works.
Are there other ways to open a window that uses a different execution context? Or any ideas for another workaround?