简体   繁体   中英

Disable JavaScript Alerts GeckoFX C#

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 ?

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.

      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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM