Knowing how to get notified about script errors when hosting a WebBrowser
control using OLECMDID_SHOWSCRIPTERROR
inside my WinForms C# application, I currently do it successfully this way:
private void handleError(mshtml.IHTMLDocument2 htmlDocument)
{
var htmlWindow = htmlDocument.parentWindow;
var htmlEventObject = htmlWindow.@event as mshtml.IHTMLEventObj2;
_lineNumber = (int)htmlEventObject.getAttribute(@"errorLine");
_characterNumber = (int)htmlEventObject.getAttribute(@"errorCharacter");
_errorCode = (int)htmlEventObject.getAttribute(@"errorCode");
_errorMessage = htmlEventObject.getAttribute(@"errorMessage") as string;
_url = htmlEventObject.getAttribute(@"errorUrl") as string;
}
This works as expected.
What I currently cannot solve is to get the JavaScript call stack.
I've tried several things in the example above:
_callStack = htmlEventObject.getAttribute(@"stack") as string;
_callStack = htmlEventObject.getAttribute(@"errorStack") as string;
_callStack = htmlEventObject.getAttribute(@"stackTrace") as string;
...
All those do return an empty/NULL string.
Whether I'm unsure if this information can be retrieved at all , still my question is :
How to get the call stack of a JavaScript error from within the application hosting an Internet Explorer web browser control?
I'm not entirely sure if that's possible at all either, but I might have some useful information related to your question. Back in IE7 days I worked on a custom host for WebBrowser control in C++, and I still keep the list of service GUIDs the control was requesting from my OLE site object through IServiceProvider . One of those interfaces was IDebugApplication , which might open a door to access JavaScript stack frame via IDebugApplication::AddStackFrameSniffer
. I had not tried it back then. If you're ready to do further research, you could use this project as a starting point to implement a custom WebBrowser host in C#.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.