|
Rank: Newbie Groups: Member
Joined: 9/12/2016 Posts: 8
|
With the HtmlToPdf.ConvertUrl, Is there a way detect if there were any Javascript errors during rendering.
We have a website using angularjs that utilizes asynchronous calls that retrieves data from a web service which could potentially throw an exception. These errors are typically seen in the console, but the web page itself still renders.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
|
|
Rank: Newbie Groups: Member
Joined: 9/12/2016 Posts: 8
|
The Debug Console works in the scenario for debugging, but I need to be able to detect if there is issues in a production environment and then alert the caller of potential document generation issues.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Hi, In that case you will need to use this feature: http://www.essentialobjects.com/doc/eo.pdf.htmltopdfsession.runwebviewcallback.aspxThis allows you to access the underlying WebView used for the conversion directly. You would then handle the WebView's ConsoleMessage event: http://www.essentialobjects.com/doc/eo.webbrowser.webview.consolemessage.aspxInside your event handler you can check the event argument's Severity property. If Severity is Error, then that's a JavaScript error. Note that the internally multiple WebViews are being reused across multiple conversions. So make sure you do not hook up your event handler more than once for each WebView. One way to achieve this is to hook it before every conversion and unhook it immediately after the conversion. Hope this helps. Please let us know if this works for you. Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 9/12/2016 Posts: 8
|
Sounds good, I'll give that a shot. What version of Eo.Pdf do I need to be able to use the session.RunWebViewCallback function?
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Hi,
You will need to use the current version. This was added rather recently.
Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 9/12/2016 Posts: 8
|
I updated to the lastest version and I'm able to see the RunWebViewCallBack. I'm hooked to the ConsoleMessage event and i'm able to see the javascript error messages come through. I attempted to throw a new application exception when I found the Severity of Error and it opened a windows form (runtime exception has occurred), since this is a web service I'd need that not to occur. Additionally, after I clicked close it still continued with the execution of generating the document(I don't have an updated license for the new version so I'm not sure if it would have generated a document or bubbled up the error).
Also, using the webview object wants me to reference System.Windows.Forms. How do I suppress that window? How do I bubble up the error to stop document generation?
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Hi,
The error won't bubble up because it's in a different thread. The conversion will continue, you just have to set up a flag to discard the result.
It's fine to reference System.Windows.Forms even in a Web application. You can suppress the runtime exception dialog by handling EO.Base.Runtime.Exception event.
Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 9/12/2016 Posts: 8
|
This is what I'm looking at doing, but I want to be able to get the exception that occurred. right now it says that the conversion failed for a timeout exception.
Code: C#
// Convert the web page and save the document
using (HtmlToPdfSession session = HtmlToPdfSession.Create(HtmlToPdf.Options))
{
session.Options.TriggerMode = HtmlToPdfTriggerMode.Manual;
WebView internalView = (WebView)session.RunWebViewCallback((WebView webView, object args) =>
{
//Create a EO.WebBrowser.Request object
Request request = new Request(req.Url);
webView.ConsoleMessage += WebView_ConsoleMessage;
//Load the request
webView.LoadRequestAndWait(request);
return webView;
}, null);
session.RenderAsPDF(pdfStream);
internalView.ConsoleMessage -= WebView_ConsoleMessage;
}
private void WebView_ConsoleMessage(object sender, ConsoleMessageEventArgs e)
{
//interrogate the console messages
Debug.WriteLine($"LineNumber: {e.LineNumber} Message: {e.Message} Severity: {e.Severity} Source: {e.Source}");
if (e.Severity == ConsoleMessageSeverity.Error)
{
throw new ApplicationException(e.Message);
}
}
Code: JavaScript
if (typeof (eoapi) == "object") {
//Variable eopdf exists. So we are inside the converter
console.log("Called in EO PDF");
eoapi.convert();
}
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Hi,
As I have already mentioned in my previous reply --- you should not throw an exception when you see a JavaScript error. You should set a flag to remember that you did have an error and let the conversion to proceed. After the conversion you can discard the result if you see your flag set.
Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 9/12/2016 Posts: 8
|
I'm setting the flag now and it appears to be working correctly. I have two issues left that I'm trying to figure out.
First, Using the WebView directly like the previous code, and using a trigger mode manual, at what point should it timeout if the webpage doesn't supply the .convert method?
Second, some of the console messages that I see in a regular browser don't appear to be captured in the log. Specifically messages from the ngResource call that received 400/500 http errors.
Any insight you can provide is much appreciated thanks!
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Hi,
The actual time out value is a multiple of HtmlToPdf.Options.MaxLoadWaitTime.
As to the console message, I believe it only output script console output, it does not output other diagnostic information.
Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 9/12/2016 Posts: 8
|
if it is not set is there a default time?
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Hi,
The default MaxLoadWaitTime is 3 minutes. The actual time out is 3 times of this value, so that would put it at 9 minutes. However this can change from builds to builds. So you should not rely on the default behavior.
Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 9/12/2016 Posts: 8
|
So far this process appears to be working. We ran into a snag on deployments of the ui with a new set of javascript files it appears to throw errors until it is called with a triggermode auto. The javascript files are deployed with different auto generated names through the gulp build process.
Uncaught Error: [$injector:modulerr] Failed to instantiate module AppModuleName due to: Error: [$injector:nomod] Module 'AppModuleName' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
After the url has been called with auto the manual conversion works correctly. We validated that the website loads properly on deployments as well.
Any ideas?
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Hi,
This is a JavaScript error that you would need to work out on your end. The most logical reason for a manual conversion to time out is when you have a JavaScript error thus not calling the triggering code.
Thanks!
|
|