IE Crashing when exposing Methods for JS

…衆ロ難τιáo~ 提交于 2021-02-11 15:34:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!