Javascript – Chrome: window.print() print dialogue opens only after page reload (javascript)

google-chromejavascriptprinting

I am facing a really weird problem. I am calling window.print() from a javascript file. This is working fine in Safari, IE, Firefox… and until two hours ago it worked in Chrome, too. (Version 29.0.1547.57)

I did not change anything essential in my javascript file (really – I just removed some comments…), but what now happens is really weird: In Chrome, the print dialogue does not open when window.print() is called. Nothing happens. But then, when I press reload, the print dialogue opens immediately.

The behaviour in the other browser did not change. And while debugging in Chrome I can see that window.print() is called as expected and the script goes on after that. Only the print dialogue is not shown until pressing reload.

Has anybody ever experienced something like that? I also tried to call window.print() in setTimeout(), but this did not change anything. When I debug the content of the page which shall be printed appears to be perfectly loaded.

I am sorry to ask, but I did not find anything while researching. Any help would be appreciated!

Thank you!

Best Answer

Wasiim is right, there is a Chrome bug where window.print() does not work when there is a <video> tag in the DOM. I solved it by calling this function:

function printPage() {
    window.print();

    //workaround for Chrome bug - https://code.google.com/p/chromium/issues/detail?id=141633
    if (window.stop) {
        location.reload(); //triggering unload (e.g. reloading the page) makes the print dialog appear
        window.stop(); //immediately stop reloading
    }
    return false;
}