简体   繁体   English

如何使用WebBrowser控件获取JavaScript堆栈跟踪?

[英]How to get JavaScript stack trace with WebBrowser control?

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: 我在WinForms C#应用程序中使用OLECMDID_SHOWSCRIPTERROR 托管WebBrowser控件时,知道如何获得有关脚本错误的通知 ,我目前已通过这种方式成功完成了此操作:

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. 我目前无法解决的问题是获取JavaScript调用堆栈。

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. 所有这些都返回一个空/ NULL字符串。

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? 如何从托管Internet Explorer Web浏览器控件的应用程序中获取JavaScript错误的调用堆栈?

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 . 在IE7的日子里,我在C ++中为WebBrowser控件开发了一个自定义主机,并且仍然保留该控件通过IServiceProvider从我的OLE站点对象请求的服务GUID的列表。 One of those interfaces was IDebugApplication , which might open a door to access JavaScript stack frame via IDebugApplication::AddStackFrameSniffer . 这些接口之一就是IDebugApplication ,它可能为通过IDebugApplication::AddStackFrameSniffer访问JavaScript堆栈框架打开了一扇门。 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#. 如果您准备进行进一步的研究,则可以将该项目用作在C#中实现自定义WebBrowser主机的起点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM