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

App crashes when printing the content #25327

Closed
3 tasks done
Suroor-Ahmmad opened this issue Sep 4, 2020 · 12 comments
Closed
3 tasks done

App crashes when printing the content #25327

Suroor-Ahmmad opened this issue Sep 4, 2020 · 12 comments

Comments

@Suroor-Ahmmad
Copy link

Suroor-Ahmmad commented Sep 4, 2020

Preflight Checklist

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

Issue Details

  • Electron Version:
    • 10.1.0
  • Operating System:
    • Windows 7
  • Last Known Working Electron version:
    • Didn't tried with any previous versions

Expected Behavior

Main process shouldn't crash when printing any content in the render process.

Actual Behavior

Main process crashes when trying to print div content

To Reproduce

Angular application running over Electron, and triggering window.print() from new window (using window.open())

@Suroor-Ahmmad
Copy link
Author

I have came across many similar issues, and most of them tagged as Closed.

@hmt
Copy link

hmt commented Sep 6, 2020

same here on macos 10.15.6

@hmt
Copy link

hmt commented Sep 6, 2020

I created a fiddle with the code that makes electron crash. After testing a bit it seems the callback function causes the segfault:
https://gist.github.com/64b8970062113ce8db7d25722dcba46d

@Suroor-Ahmmad
Copy link
Author

Were you able to fix this issue? @hmt

@hmt
Copy link

hmt commented Sep 7, 2020

Yes, remove the callback and just print with options or without options. So, instead of:

    mainWindow.webContents.print(options, (success, errorType) => {
      console.log(success)
    })

do this:

    mainWindow.webContents.print(options)

or this:

    mainWindow.webContents.print()

@Suroor-Ahmmad
Copy link
Author

Yes, callback is causing issue, but my requirement slightly different, if you can suggest something here, I'll be grateful. I'm trying to print from angular app which is running over the electron, so I'm not calling webContents.print(options) from main process. Now app doesn't crash when I click Print but it crashes when I try to close the new window opened which has content to print.

printFees() {
    var prtContent = document.getElementById('print-section');
    var WinPrint = window.open('', '_blank', 'left=0,top=0,width=800,height=900,toolbar=0,scrollbars=0,status=0');
    WinPrint.document.open();
    WinPrint.document.write(prtContent.innerHTML);
    WinPrint.document.close();
    const browser = this.electronService.remote.BrowserWindow; 
    let win = browser.getFocusedWindow();
    win.webContents.print();
    WinPrint.close(); //app crashes here, if I remove this everything works fine but even if I close the window manually, main process also closes

    //WinPrint.setTimeout(function () {
    //    WinPrint.close();
    //}, 1000);
} 

@hmt
Copy link

hmt commented Sep 8, 2020

Not sure but I think the remote call makes it pretty much the same to electron. You could try to set up an ipc channel to let the main process handle the print?

@MaiconLeffa
Copy link

MaiconLeffa commented Sep 9, 2020

When I try to open a PDF in the integrated PDF viwer It Works Fine, but when I click to print, the preview window crashes. I am using reactjs. Some idea How to fix this issue?

Using windows 10

@Suroor-Ahmmad
Copy link
Author

Not sure but I think the remote call makes it pretty much the same to electron. You could try to set up an ipc channel to let the main process handle the print?

I tried this way, but there's catch here, I want to print the content of newly opened window and not main window, so to achieve this I can't create remote object in main.js or pass browser.getFocusedWindow() object as arg in ipcRenderer.send('print',window)

@hmt
Copy link

hmt commented Sep 12, 2020

Sorry, can't think of a solution

@codebytere
Copy link
Member

Closing in favor of #25397

@Suroor-Ahmmad
Copy link
Author

When I try to open a PDF in the integrated PDF viwer It Works Fine, but when I click to print, the preview window crashes. I am using reactjs. Some idea How to fix this issue?

Using windows 10

Were you able to fix this?

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

No branches or pull requests

5 participants