Welcome Guest Search | Active Topics | Sign In | Register

WebBrowser: Crash on print Options
Jeppe HS
Posted: Wednesday, May 3, 2017 4:04:22 AM
Rank: Advanced Member
Groups: Member

Joined: 1/5/2015
Posts: 60
Hi,

I'm having some issues with printing from certain site.

Nothing happens when printing recipes from this site: https://www.maduniverset.dk.
Opening a recipe, e.g. https://www.maduniverset.dk/opskrift.php/10342/Andet-Fjerkrae-opskrifter/Andebryst-i-ovn-til-mange and clicking the print link on the page will open the print dialog, but nothing further happens when selecting print.

When I try to open a direct link to the print view and print it, the browser crashed without any exceptions or crash report.
E.g. https://www.maduniverset.dk/opskrift_print.phtml?uid=10342&c=1


It works fine in Chrome 57.0.2987.133.

I've been able to reproduce it in the Tabbed Browser sample version 17.1.30.0.


Hope you are able to help.
eo_support
Posted: Wednesday, May 3, 2017 11:44:41 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,229
Hi,

This is not a crash. The root of the problem is the following code in the page:

Code: HTML/ASPX
<body onLoad="window.print(), setTimeout('self.close()',0)" ...>


The code closes the window immediately after the print has started. EO.WebBrowser honors self.close faithfully thus immediately close the tab after the print has started, which in turn immediately cancels the printing.

Chrome on the other hand has various built-in logics to ignore self.close call. For example, if you load the page directly into a tab, then self.close will be ignored. You can duplicate such logic in your code as well. There are several ways to ignore self.close:

1. Set WebView.JSInitCode to overwrite window.close. For example, you can do something like this:

Code: JavaScript
window.close = function(){};


2. Handle WebView.Closing event and set e.Cancel to true in your event handler;

Note that the above code only shows you how to disable closing the window. In real scenarios you will want to do this conditionally. For example, if you chose option 2, then you may still want the window to close if user choose to close the window by clicking the "X" button on the tab title. In that case you can do something like this (based on TabbedBrowser source code):

Code: C#
private bool m_bUserClose;

private void mainTabs_PreviewItemClose(object sender, TabItemCloseEventArgs e)
{
    //Remember that this is user close
    m_bUserClose = true;

    .......
    item.Page.WebView.Close(false);
}

private void WebView_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
    //Only cancel closing if it is not from the user
    if (!m_bUserClose)
        e.Cancel = true;
}


Jeppe HS
Posted: Thursday, May 4, 2017 7:34:09 AM
Rank: Advanced Member
Groups: Member

Joined: 1/5/2015
Posts: 60
Handling WebView.Closing worked perfectly.

Thank you.
eo_support
Posted: Thursday, May 4, 2017 1:53:59 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,229
Glad to hear that. Please feel free to let us know if there is anything else.


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.