views:

261

answers:

1

I'm trying to silence Javascript errors in the WPF webbrowser control. According to the "Getting to the native IWebBrowser2" comment on this page, one can access the IWebBrowser2 interface. From there I thought I could set the Silent property to true, like this:

    /// <summary>
    /// Handle navigation events
    /// </summary>
    protected virtual void OnNavigated(object sender, NavigationEventArgs e)
    {
        MakeComBrowserSilent();
    }

    private void MakeComBrowserSilent()
    {
        IServiceProvider serviceProvider = (IServiceProvider)_webViewer.Browser.Document;
        Guid serviceGuid = SID_SWebBrowserApp;
        Guid iid = typeof(SHDocVw.IWebBrowser2).GUID;
        SHDocVw.IWebBrowser2 comBrowser = (SHDocVw.IWebBrowser2)serviceProvider.QueryService(ref serviceGuid, ref iid);
        comBrowser.Silent = true;
        //comBrowser.PutProperty("Silent", true);
    }

I've tried the Silent=true, and also PutProperty. Neither works and I still get Javascript errors popping up.

Anyone know how to silence Javascript debug errors in the WPF WebBrowser control?

TIA.

A: 

The WPF browser class does not have the API to access the IWebBrowser interface directly, you must get it via the document, but by the time the document is ready for access, it is already too late. Interop windows forms or use ActiveX/ActiveX wrapper classes ilke csexwb.

Sheng Jiang 蒋晟