electron Print issue on Electron from v7 - Print only works once (window.print()) - Cplusplus

Preflight Checklist

  • [x] I have read the Contributing Guidelines for this project.
  • [x] I agree to follow the Code of Conduct that this project adheres to.
  • [x] I have searched the issue tracker for an issue that matches the one I want to file, without success.

Issue Details

  • Electron Version: Not working since v7.00.
    Tested on:
    • v8.0.0-beta.4
    • v7.0.0
  • Operating System:
    • macOS 10.14.5
  • Last Known Working Electron version:
    • v6.1.5

Expected Behavior

That the window.print() will work, even after the first time.
Like in versions prior to v7.0.0

Actual Behavior

The window.print() function only works one time.
After the first time, it's not working. The print dialog appears but the actual printing is not.

To Reproduce

Run window.print() twice.
On the Electron Fiddle app example, click on the Print Page and print. After that first time, click on the Print Page button again and try to print again. Link to the Gist

Screenshots

Link to video

Asked Oct 15 '21 13:10
avatar ChenAlon
ChenAlon

9 Answer:

@ChenAlon Running that exact gist on v8.0.0-beta.4 on macOS 10.14.5 works for me without incident as expected - are you sure that it's broken there?

1
Answered Dec 05 '19 at 21:40
avatar  of codebytere
codebytere

@codebytere, yes. Did you see the video? I just tried the same on a different machine, macOS 10.14.6 and I still see the same issue (v8.0.0-beta-4).

Here are some logs from the Console app logs:

This happen after I click the print button:

default 09:20:26.517943 +0200   Electron    failed to get application bundle
default 09:20:26.517986 +0200   Electron    Error in AHRegisterHelpBookWithURL: -50
default 09:20:26.546347 +0200   Electron    failed to get application bundle
default 09:20:26.546375 +0200   Electron    Error in AHRegisterHelpBookWithURL: -50
default 09:20:26.546978 +0200   Electron    failed to get application bundle
default 09:20:26.547006 +0200   Electron    Error in AHRegisterHelpBookWithURL: -50
default 09:20:26.551532 +0200   Electron    failed to get application bundle
default 09:20:26.551558 +0200   Electron    Error in AHRegisterHelpBookWithURL: -50

And this after I click Print on the Print dialog (Save to PDF):

error   09:20:44.808648 +0200   Electron    errors encountered while discovering extensions: Error Domain=PlugInKit Code=13 "query cancelled" UserInfo={NSLocalizedDescription=query cancelled}
default 09:20:44.808700 +0200   Electron    OSErr AERemoveEventHandler(AEEventClass, AEEventID, AEEventHandlerUPP, Boolean)(ficl,askM handler=0x7fff4f4e929b isSys=NO) err=0/noErr
default 09:20:44.902731 +0200   Electron    Adding presenter FB6315CE-2576-4C18-9CD3-6FD62B32F914 for URL: <private>
default 09:20:49.907229 +0200   Electron    Removing presenter FB6315CE-2576-4C18-9CD3-6FD62B32F914
default 09:20:51.715695 +0200   Electron    LSExceptions shared instance invalidated for timeout.
1
Answered Dec 08 '19 at 07:26
avatar  of ChenAlon
ChenAlon

I think this should block a stable release until fixed. Only being able to print once seems like a pretty severe issue. I know it's a show-stopper for us. We tried resolving by rolling back to v6.x, but then got hit with https://github.com/electron/electron/issues/19768 . In our case (site wrapper) the workarounds don't help, so we're pretty much stuck. IMO getting back to print stability in v8 would finally take this off the table.

1
Answered Jan 24 '20 at 15:02
avatar  of daveajones
daveajones

@barbalex yes, as you can see above i PR'd a fix into this yesterday. That means it will be fixed in the next released versions of 6, 7, and 8.

1
Answered Jan 28 '20 at 20:25
avatar  of codebytere
codebytere

@codebytere sorry, that printing works only once.

And yes, obviously your merge will only be in the next release so sorry for bugging.

And THANKS A LOT for solving the issue!

1
Answered Jan 28 '20 at 20:27
avatar  of barbalex
barbalex

@barbalex of course! printing is an ongoing struggle so apologies for the occasional failures, but it's something i care about to large extent so i'm always happy to tackle printing bugs when they come up :D

1
Answered Jan 28 '20 at 20:28
avatar  of codebytere
codebytere

Hi,

I am encountering the exact same problem in version 10.1.1 (latest version currently) on mac. Can anyone else please confirm if the issue has been reintroduced?

Btw, I have tried to approaches to printing:

  1. button onclick="window.print()"
  2. using ipc, window.webContents.print()

PS: I am new to electron. Thank you!

Update: I downgraded to 7.1.11 and it seems to be working. Looks like it has been reintroduced.

1
Answered Sep 11 '20 at 22:01
avatar  of dipunj
dipunj

I just tested with https://gist.github.com/0f0e776b138452d6815ef4efc16aa0d1 and had no issues running window.print multiple times on v10 with macOS. Additionally you absolutely do not want to use a version as old as 1.8 for any reason.

Edit: found an issue i think - it looks specific to 10 though as i cannot reproduce it on 11 and master. I'll try to suss it out.

1
Answered Sep 18 '20 at 14:17
avatar  of codebytere
codebytere

@codebytere thank you for that gist. I will compare your gist with my code and update you here.

1
Answered Sep 18 '20 at 14:24
avatar  of dipunj
dipunj