Disable JavaScript Alerts GeckoFX C#

让人想犯罪 __ 提交于 2019-12-11 12:57:44

问题


I'm trying to disable JavaScript alert in GeckoFX-33 + xulrunner 33 ( winforms c# ) but I can't find a solution. I check the example codes, source code but I just can't find something that blocks the alert out. I searched in about:config as well without success.

Anybody knows where I could find a reference at last ?


回答1:


In prior versions, you could do

webBrowser.JavascriptError += (sender, error) => {
  // do something
}

However according to issue 7 on geckofx 33, there's some work that needs to be done to support the new debugging interface:

the geckofx service jsdIDebuggerService was removed from firefox 33. the JavascriptError event implementation used this service. So the JavascriptError event handler needs to be reimplemented using firefox new debugging interface.




回答2:


      geckoWebBrowser1.JavascriptError += (sender, error) =>
        {
            GeckoWebBrowser browser = geckoWebBrowser1;
            string text = "window.alert = function(){};";
            using (AutoJSContext context = new AutoJSContext(browser.Window.JSContext))
            {
                string result;
                //toolStripLabel1.Text = "was is loaded?";

                context.EvaluateScript(text, (nsISupports)browser.Window.DomWindow, out result);
            }
        };

Here is the final code for Gecko 29.



来源:https://stackoverflow.com/questions/29931050/disable-javascript-alerts-geckofx-c-sharp

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