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
Electron 4.0.0: webContents.print() must be called twice or with an empty object #16219
Comments
Notes: Electron version 4.0.0 has an issue regarding printing. See electron/electron#16219 The whole file "package.json" is marked as changed because of a change in .gitattributes (commit 1817420)
Confirmed. Additionally, I'm seeing that after the dialog opens once it won't open again until relaunching. |
Just tested on macOS (10.14.2) and |
Did some more testing on macOS. Printing works as expected in the 4-0 betas up through 4.0.0-beta.9. Doesn't work in 4.0.0-beta.10, 4.0.0-beta.11, or 4.0.0. #15976 was introduced in 4.0.0-beta.10 so the issue mostly likely lies somewhere in #15023 or #15143. |
Hey folks—just wanted to add, I had this problem as well but was able to work around it by using |
does anyone have another clear solution as calling |
Here's my current workaround: - contents.print()
+ contents.executeJavaScript("window.print()") |
@javan your current workaround works, but is there another way for printing silent. |
The |
Closing as this appears fixed in latest electron 5 beta. Feel free to reopen otherwise. |
Silent printing still fails in latest beta as mentioned in #16193 |
Silent printing still fails in Electron 5.0.3. I had to downgrade to electron@3.1.8 for use the silent print. |
Silent printing still fails in Electron 5.0.6. |
@Catlite91 The backport which fix the "silent printing" issue is here #19038 Follow this PR to get notified when it will be merged into 5.x.x. |
Notes: Electron version 4.0.0 has an issue regarding printing. See electron/electron#16219 The whole file "package.json" is marked as changed because of a change in .gitattributes (commit 1817420965a1e57bf27603eb9def9ba0ed41d029)
Notes: Electron version 4.0.0 has an issue regarding printing. See electron/electron#16219 The whole file "package.json" is marked as changed because of a change in .gitattributes (commit 1817420965a1e57bf27603eb9def9ba0ed41d029)
node_modules/.bin/electron --version
: v4.0.0node_modules/.bin/electron --version
on last known working Electron version (if applicable): v3.0.13Expected Behavior
If I call
webContents.print()
, the print dialog shall open. If I give a callback function, the callback shall be called.Actual behavior
I must call
webContents.print()
twice before the print dialog opens. There is a workaround: If I give an empty object as parameter, the behavior is as expected:webContents.print({})
Additionally, I observed that the callback, if given, gets not called. This works also as expected under Electron 3.0.13.
To Reproduce
I made a repository with multiple examples to the described behavior.
To clone the repository:
All examples should start after typing the following commands in their respective directories:
You can either click File -> Print in the main menu or press
Ctrl+P
- behavior is the same.Additional Information
Explanation to the examples:
01_expected_3.0.13
: This shows the expected behavior under Electron 3.0.13. I pressCtrl+P
and the printing dialog appears immediately.02_bug_4.0.0
: This shows the described bug under Electron 4.0.0. I must pressCtrl+P
twice before the dialog opens. The debugger (VS Code) shows that the function gets called every time.03_workaround_4.0.0
: This shows the described workaround under Electron 4.0.0 by giving an empty object as parameter.04_callback-called_3.0.13
: As expected, a given callback gets called and gives some output to the console.05_callback-not-called_4.0.0
: The given callback seems not to be called. There is no output in the console.The text was updated successfully, but these errors were encountered: