Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot print on Chrome #126

Open
williamyuaus opened this issue Aug 10, 2023 · 4 comments
Open

Cannot print on Chrome #126

williamyuaus opened this issue Aug 10, 2023 · 4 comments

Comments

@williamyuaus
Copy link

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
Copy link

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

Everything is working properly in firefox but not on chrome.

@zejefferson
Copy link

Same here.

@lennaht
Copy link

lennaht commented Aug 9, 2024

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>

@stepanex
Copy link

@lennaht thanks, that works for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants