问题
I am developing a BHO for IE in C#. The issue I am stuck in is that IE crashes by saying that
"Internet Explorer has stopped working"
then
"A problem with the webpage caused Internet Explorer to close and open the tab again"
This behavior is observed on Windows 10 Pro 2016 and IE 11. However same BHO is working fine on other versions of Windows like Windows 8.1 - IE 11, Windows 10 2019,2020 - IE 11.
This usually occurs on navigating to a link in the already opened tab or on refreshing the page.
I have checked through logs it occurs when exposing methods for JS
through BeforeScriptExecute
event on this line 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)
{
}
}
The complete code is shared here in the question.
来源:https://stackoverflow.com/questions/62829660/ie-crashing-when-exposing-methods-for-js