Disable JavaScript Alerts GeckoFX C#

2019-08-13 20: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 ?

2条回答
劫难
2楼-- · 2019-08-13 21:04

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.

查看更多
Ridiculous、
3楼-- · 2019-08-13 21:10
      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.

查看更多
登录 后发表回答