none
Webbrowsercontrol not loading URL in custom task pane - Word Plugin RRS feed

  • Question

  • I am trying to load a web-application URL in a word plugin custom task pane(VSTO) inside a WPF webbrowsercontrol. The problem is that it is working fine on development machine and some other machines but it do not work on some machines. Below is my machine specific finding(All Machines have IE11): 

    All machines have .net version greater than 4.6. It works on some machines with windows 10 and do not work on others with same windows version.

    (images can be found on Stackoverflow)

    ref: stackoverflow question /52197911/webbrowsercontrol-not-loading-url-in-custom-task-pane-word-plugin


    As per findings on some threads, i enabled window.error on web page and removed some errors that were coming in javascript script. But on some machines it gives unspecified errors in jquery files. I have also tried setting browser emulation from registry for WINWORD.EXE to use IE11.

    P.S. I have developed the vsto plugin on target framework 4.6. I have also tried using target framework 4.6.2 that is required for WEBVIEW control as mentioned in earlier links. Also, enabling .net version 4.7 on windows 10 machine do not work. Web page takes 3-4 seconds to load in IE. The web page uses jquery1.9 and angular framework 1.6. And the page also contains meta tag for IE=edge as suggested on some sites.

    Is there any other work around to make this work?

    Some suggestion are about recreating the view in WPF, i can't create the web page in WPF to display and edit all the data due to strict delivery timelines.


    • Edited by Sumit Pannu Thursday, September 13, 2018 8:28 AM
    Thursday, September 13, 2018 8:27 AM

All replies

  • Hi Sumit,


    If possible, could you please share some codes for us ?


    Best Regards,

    Bruce



    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.



    Friday, September 14, 2018 11:04 AM
    Moderator
  • Below is the code:

    public MetadataView(Dictionary<string, object> inputFields)
            {
                InitializeComponent();

                var vm = new ViewModel.MetadataViewModel();
                this.DataContext = vm;
                vm.Load(inputFields);
                if (inputFields.ContainsKey("Url"))
                {                
                    CommonUtility.SetAuthCookieValue(inputFields["Url"].ToString());
                    webBrowser.Navigate(new Uri(inputFields["Url"].ToString()));
                    webBrowser.Focusable = true;
                    webBrowser.Focus();
    }
    }

    private void webBrowser_Navigated(object sender, NavigationEventArgs e)
            {
                SetSilent(webBrowser, true);
            }

            public static void SetSilent(WebBrowser browser, bool silent)
            {
                if (browser == null)
                    throw new ArgumentNullException("browser");

                // get an IWebBrowser2 from the document
                IOleServiceProvider sp = browser.Document as IOleServiceProvider;
                if (sp != null)
                {
                    Guid IID_IWebBrowserApp = new Guid("0002DF05-0000-0000-C000-000000000046");
                    Guid IID_IWebBrowser2 = new Guid("D30C1661-CDAF-11d0-8A3E-00C04FC9E26E");

                    object webBrowser;
                    sp.QueryService(ref IID_IWebBrowserApp, ref IID_IWebBrowser2, out webBrowser);
                    if (webBrowser != null)
                    {
                        webBrowser.GetType().InvokeMember("Silent", BindingFlags.Instance | BindingFlags.Public | BindingFlags.PutDispProperty, null, webBrowser, new object[] { silent });
                    }
                }
            }


            [ComImport, Guid("6D5140C1-7436-11CE-8034-00AA006009FA"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
            private interface IOleServiceProvider
            {
                [PreserveSig]
                int QueryService([In] ref Guid guidService, [In] ref Guid riid, [MarshalAs(UnmanagedType.IDispatch)] out object ppvObject);
            }

    private void UserControl_Unloaded(object sender, RoutedEventArgs e)
            {            
                try
                {
                    webBrowser.Dispose();
                }
                catch (Exception)
                {
                    throw;
                }
            }



    UserControl WPF:
    <WebBrowser Panel.ZIndex="1" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2"  x:Name="webBrowser" HorizontalAlignment="Left" Margin="0,0,0,0"  VerticalAlignment="Top" Navigated="webBrowser_Navigated" LoadCompleted="webBrowser_LoadCompleted"/>

    Also, on the machine on which it is working fine, the Word stops working as soon as the URL is loaded for the 2nd time/1st time. I guess its something related to memory leak via webbrowser control, i am going through some threads to handle the memory leak problem. Please let me know if you need any information from my end.

                
    • Edited by Sumit Pannu Monday, September 17, 2018 12:03 PM
    Friday, September 14, 2018 1:38 PM