mycurelabs / vue-html-to-paper

Vue mixin for paper printing html elements.
MIT License
298 stars 102 forks source link

Cannot print on Chrome #126

Open williamyuaus opened 1 year ago

williamyuaus commented 1 year ago

The popup window will be closed immediately once we clicked the button to print. I tested on the demo website on Chrome: https://mycurelabs.github.io/vue-html-to-paper/#

The Chrome version is Version 115.0.5790.171 (Official Build) (64-bit).

kiohoviera commented 11 months ago

I'm having the same issue as well. Any update on this?

Everything is working properly in firefox but not on chrome.

zejefferson commented 10 months ago

Same here.

lennaht commented 1 month ago

Still having the same issue on Chrome 127.0.6533.90 (Official Build) (64-Bit) on Windows. It's working in Firefox.

The popup opens correctly but opening the print dialogue doesn't seem to work. When disabling autoClose the popup indefinitely shows a loading animation until you press ESC but I couldn't yet figure out why. image

I quickly rebuilt the printing logic and with this document it works flawlessly in Chrome:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>Test</h1>
    <button id="btn">Print something</button>
    <script>
        'use strict';

        const options = {
            name: '_blank',
            specs: ['fullscreen=yes','titlebar=yes', 'scrollbars=yes'],
            replace: true,
            styles: []
        }

        function printSomething() {
            console.log('print');
            let win;

            win = window.open('', options.name, options.specs.join(','));
            if (!win.opener) {
                win.opener = window;
            }
            win.focus();
            win.document.write(`
                <h1>Print this</h1>
            `);
            setTimeout(() => {
                win.document.close();
                win.focus();
                win.print();
                setTimeout(function () {win.close();}, 100);
            }, 1000);
        }
        document.getElementById('btn').addEventListener('click', printSomething);
    </script>
</body>
</html>