c# - 暴露 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
日志BeforeScriptExecute
p.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 - C函数原型:\\char *strinv(const char *s);
- sql - BigQuery 上的 SQL:使用完全连接的双重选择时合并数据透视列
- java - ClassNotFoundException "android.net.wifi.WifiNetworkSpecifier$Builder"
- ruby-on-rails - 如何访问刚在 rails 中创建的对象中的值?
- javascript - 如何以 mat 形式将值设为小写
- python - Python 为什么我更改的数据类型在我将它们保存到 .csv 后会恢复到以前的数据类型?
- python - .resample('W') 仅选择一列,而子集包括两列
- python - Pandas.equals 的奇怪结果
- javascript - 使用节点 googleapis 将两个谷歌文档合并在一起
- python - 从BS4中的表行中提取多个数据