Print preview freezes Javascript in Chrome
<p>I've been struggling with Chrome dropping the Websocket connections if a print preview is open for more than a few seconds. I've traced it back to <a href="https://bugs.chromium.org/p/chromium/issues/detail?id=178931" rel="noreferrer">this ticket</a>, and the cause is that <code>window.print()</code> is synchronous and thus halts any other script execution, which in turn make the websocket timeout and drop. </p>

<p>Since the ticket was opened 2.5 years back and it's currently WontFix, I'm looking for a workaround.</p>

<h2>What I've tried</h2>

<h3>Use window.open</h3>

<p>Originally, I used an Iframe to render the content and print it. Then I've tried to move it to open a new tab, load the contents there and print it.</p>

<p><code>window.open("iframe.html");</code></p>

<p>You can find a minimal example <a href="https://cdn.rawgit.com/sashee/chrome-print-scripts/968bfa45d8dab781fb644303a29e5f777d3ad34c/windowOpen.html" rel="noreferrer">here</a> (code <a href="https://github.com/sashee/chrome-print-scripts/blob/968bfa45d8dab781fb644303a29e5f777d3ad34c/windowOpen.html" rel="noreferrer">here</a>). If you open the console, you see it's counting up every second. After 2 secs, a popup will open (you might need to enable popups) that loads the print in a new tab. Wait a few seconds, then close the print preview. If you switch back to the original tab, you can see that the counter was stopped.</p>

<h3>Use an anchor</h3>

<p>Then I've tried using an anchor tag, with <code>target="_blank"</code>, like this:</p>

<p><code>&lt;a href="iframe.html" target="_blank"&gt;print&lt;/a&gt;</code></p>

<p>(Example <a href="https://cdn.rawgit.com/sashee/chrome-print-scripts/968bfa45d8dab781fb644303a29e5f777d3ad34c/anchor.html" rel="noreferrer">here</a>, code <a href="https://github.com/sashee/chrome-print-scripts/blob/968bfa45d8dab781fb644303a29e5f777d3ad34c/anchor.html" rel="noreferrer">here</a>)</p>

<p>This opens a new tab, but the counter still stops. If I right click on the link and use <code>Open link in new tab</code>, then the counter works.</p>

<hr>

<p>Are there and other ways to open a window that uses a different execution context? Or any ideas for a different workaround?</p>