首页 > 解决方案 > 暴露 JS 方法时 IE 崩溃

问题描述

我正在用 C# 为 IE 开发 BHO。我陷入的问题是IE崩溃了

“Internet Explorer 已停止工作”

然后

“网页出现问题导致 Internet Explorer 关闭并再次打开选项卡”

在 Windows 10 Pro 2016 和 IE 11 上观察到此行为。但是,相同的 BHO 在 Windows 8.1 - IE 11、Windows 10 2019、2020 - IE 11 等其他版本的 Windows 上运行良好。

这通常发生在导航到已打开选项卡中的链接或刷新页面时。

我已经检查了在此行上公开事件的方法时发生的JS日志BeforeScriptExecutep.SetValue(windowEx, this);

private void S2_BeforeScriptExecute(object pDispWindow)
{
    try
    {
        HTMLDocument doc = _webBrowser.Document as HTMLDocument;

        if (doc != null)
        {
            IHTMLWindow2 tmpWindow = doc.parentWindow;
            dynamic window = tmpWindow;
            IExpando windowEx = (IExpando)window;
            PropertyInfo p = windowEx.AddProperty("myExtension");
            p.SetValue(windowEx, this);
        }
    }
    catch (Exception ex)
    {
    }
}

完整的代码在问题中共享

标签: c#windowsinternet-explorerbho

解决方案


推荐阅读