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

Event listener when printing in silent mode. #701

Open
jshawberry opened this issue Feb 14, 2024 · 1 comment
Open

Event listener when printing in silent mode. #701

jshawberry opened this issue Feb 14, 2024 · 1 comment

Comments

@jshawberry
Copy link

I have an application using printJS, and I have the following call:

    printJS({
        printable: printableContent,
        type: 'raw-html',
        onPrintDialogClose: myMethod,
        title: 'My Title'
    });

I need to print silently (ex. print.always_print_silent on Firefox). Which I have configured in my client browser successfully.

I have also added the following event listeners for "focus" and "afterprint"...

    window.addEventListener("afterprint", function(event)
    {
        myMethod();
    });

    window.addEventListener("focus", function(event)
    {
        myMethod();
    });

However, none of these event listeners get triggered when I'm in silent print mode. The onPrintDialogClose feature does not get triggered either.

How do I determine when the print job finishes if I'm in silent print mode?

@fabisb
Copy link

fabisb commented Oct 26, 2024

Hey, today I had this problem, and was fixed this way:

 window.onafterprint = () => {
      try {
        window.close();
        // change window.close for your code
        setTimeout(() => window.close(), 300);
      } catch (error) {
        console.error(
          "🚀 ~ file: index.html:37 ~ cerrarVentana ~ error:",
          error
        );
        setTimeout(() =>  window.close(), 300);
      }
    };

I don't know why, maybe when silent mode is on, there is no time for it to activate.

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

2 participants