22

I keep getting a script error when trying to load the page using webBrowser.Navigate("https://home.nest.com/"). It will pull up fine from my normal internet browser but not in my program.

Can anyone point me in the right direction?

Script Error

Chris Fannin
  • 1,284
  • 1
  • 10
  • 16
imrdnck
  • 287
  • 2
  • 3
  • 9
  • 3
    Post the script that the error references on line 358. We aren't mind readers, we can't tell what's wrong without seeing the code. – DGibbs May 20 '16 at 15:58
  • [1]: http://i.stack.imgur.com/ayNI2.png – imrdnck May 20 '16 at 16:06
  • Do you already try `webBrowser.ScriptErrorsSuppressed = true;` ? – jomsk1e May 20 '16 at 16:10
  • yes and the page does not load. – imrdnck May 20 '16 at 16:11
  • 1
    i am new to all of this learning through trial and error so if I ask a question incorrectly please don't bite my head off.....Dgibbs. – imrdnck May 20 '16 at 16:12
  • @DGibbs That is a massive script created by Nest. If the line and character are not lying, it's happening on the "export" part of `m.export=function(){`. Unfortunately, I don't know what the problem is. Many of the websites that heavily rely on Javascript have this problem within the `WebBrowser` control. My only suggestion is to use something other than the IE `WebBrowser` control, such as Awesomium: http://www.awesomium.com/ – Chris Fannin May 20 '16 at 16:59
  • Note: There's no guarantee that any integrated browser control will function. People don't test their websites within them. It's hit and miss. – Chris Fannin May 20 '16 at 17:01
  • @imrdnck - I posted my information as an answer. – Chris Fannin May 20 '16 at 17:16

6 Answers6

20

as this link answer:

you must only add this line:

webBrowser.ScriptErrorsSuppressed = true;
Ali Rasouli
  • 1,705
  • 18
  • 25
  • This worked for me. I am using vs 2017 with .net framework 4.6.1 – SainathDK Oct 15 '19 at 13:40
  • SPA-based web pages simply won't render properly. – vter May 30 '20 at 20:11
  • Nop! The word "Script Error Suppression", expresses itself! It suppresses scripts! It's like you ignore a problem not resolve it. This actually helps to not see that annoying "Error Message" dialog boxes; however, it prevents scripts to be running, hence, the page won't be loading properly. – Saffa Seraj Mar 10 '21 at 21:44
14

The script errors happen all of the time in the integrated Internet Explorer WebBrowser control even when it's using version 11. Modern websites rely heavily on massive Javascript files and dynamic rendering. You can see that just by watching that page load in a regular browser. The control just can't cut it some of the times.

You might want to try some alternative browser controls. There are no guarantees that it will work with any of them, but at least it's something to try.

  • Awesomium : Originally based on Chromium. I don't know if they still integrate Chromium changes or if they've gone in their own direction. It's free for personal use as well as commercial making less than $100k.
  • DotNetBrowser : Embed a Chromium-based WPF / WinForms component into your .NET application to display modern web pages built with HTML5, CSS3, JavaScript, Silverlight etc.
  • geckofx : An open-source component for embedding Mozilla Gecko (Firefox) in .NET applications.
  • Xilium.CefGlue : A .NET/Mono binding for The Chromium Embedded Framework (CEF) by Marshall A. Greenblatt.
  • BrowseEmAll : BrowseEmAll.Cef (Chrome), BrowseEmAll.Gecko (Firefox), BrowseEmAll Core API (Chrome,Firefox,IE - COMMERCIAL)

There are probably others, but this should give you a start with some of the more popular active projects if you want to pursue this route.

Chris Fannin
  • 1,284
  • 1
  • 10
  • 16
  • @imrdnck You're welcome. It's unfortunate that the framework browser doesn't work even though it uses IE11, but there's nothing we can really do except go to people dedicated to making a functional replacement. :-) – Chris Fannin May 20 '16 at 17:23
7

The WebBrowser control is capable of rendering most web pages, but by default it attempts to render pages in compatibility mode (pretty much IE7, hence the issues). If you are building your own page, it's simple, just add the following tag to the header and it should render fine...

<meta http-equiv="X-UA-Compatible" content="IE=Edge" />

However, if you are trying to render a third party site you cannot add tags to, things get more difficult. As mentioned above, you can use a registry key (HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION) if it's just on your own machine.

If neither of these options are a possible solution, using a different browser control (again, great suggestions above) is pretty much your only option.

There's a great blog on controlling the browser control compatibility mode at https://learn.microsoft.com/en-gb/archive/blogs/patricka/controlling-webbrowser-control-compatibility

Nick
  • 141
  • 1
  • 7
0

You should add your program name to the register HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION for using the latest feature as same as your normal internet browser.

as for me, value 8000 (0x1F40) - IE8 mode can solve many script error problem.

Ref:

Use latest version of Internet Explorer in the webbrowser control

SDJSK
  • 1,292
  • 17
  • 24
0
  private void Form1_Load(object sender, EventArgs e)
  {
            var appName = Process.GetCurrentProcess().ProcessName + ".exe";
            SetIE8KeyforWebBrowserControl(appName);

            webBrowser1.ScriptErrorsSuppressed = true;
  }



private void SetIE8KeyforWebBrowserControl(string appName)
{
     RegistryKey Regkey = null;
     try
     {
         // For 64 bit machine
         if (Environment.Is64BitOperatingSystem)
              Regkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\\Wow6432Node\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EMULATION", true);
         else  //For 32 bit machine
               Regkey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EMULATION", true);

          // If the path is not correct or
          // if the user haven't priviledges to access the registry
          if (Regkey == null)
          {
              MessageBox.Show("Application Settings Failed - Address Not found");
              return;
          }

          string FindAppkey = Convert.ToString(Regkey.GetValue(appName));

          // Check if key is already present
          if (FindAppkey == "8000")
          {
              MessageBox.Show("Required Application Settings Present");
              Regkey.Close();
              return;
          }

          // If a key is not present add the key, Key value 8000 (decimal)
          if (string.IsNullOrEmpty(FindAppkey))
              Regkey.SetValue(appName, unchecked((int)0x1F40), RegistryValueKind.DWord);

           // Check for the key after adding
           FindAppkey = Convert.ToString(Regkey.GetValue(appName));

           if (FindAppkey == "8000")
               MessageBox.Show("Application Settings Applied Successfully");
           else
               MessageBox.Show("Application Settings Failed, Ref: " + FindAppkey);
       }
       catch (Exception ex)
       {
           MessageBox.Show("Application Settings Failed");
           MessageBox.Show(ex.Message);
       }
       finally
       {
           // Close the Registry
           if (Regkey != null)
               Regkey.Close();
       }
   }
önder çalbay
  • 143
  • 1
  • 3
0

You may even set the registry value to 11000 to have the latest version of IE!!