I’m doing an advanced browser and edited a lot on it to remove script errors and render the page better, but I’ll share some of my code to see if it can help you.
'Coloque isso no método iniciador da forma principal (Form1)
ServicePointManager.ServerCertificateValidationCallback = New RemoteCertificateValidationCallback(Function() True)
Ok, then it will ignore certificate errors, but it will not make sense now, put this line, has to be the first expression of the event Load
of your WebBrowser
:
'Ao carregar seu Webbrowser (WebBrowser1.Load):
WebBrowser1.ScriptErrorsSuppressed = True
Beauty, by default Webbrowser is rendered by the renderer of Internet Explorer 7 (unfortunately), but fortunately we can put to the higher version, in case the IE 11.
That part is what will make the most difference, put that code in the file Application.Designer.Vb
Located in the directory of your project, goes in the folder My Project and the file will be there.
Put this method Namespace My.MyApplication
:
Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup
CreateBrowserKey()
End Sub
Private Sub MyApplication_Shutdown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shutdown
' Se quiser que remova a propriedade:
' RemoveBrowerKey()
End Sub
Private Const BrowserKeyPath As String = "\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION"
Private Sub CreateBrowserKey(Optional ByVal IgnoreIDocDirective As Boolean = False)
Dim basekey As String = Microsoft.Win32.Registry.CurrentUser.ToString
Dim value As Int32
Dim thisAppsName As String = My.Application.Info.AssemblyName & ".exe"
' Value reference: http://msdn.microsoft.com/en-us/library/ee330730%28v=VS.85%29.aspx
' IDOC Reference: http://msdn.microsoft.com/en-us/library/ms535242%28v=vs.85%29.aspx
Select Case (New WebBrowser).Version.Major
Case 8 'Internet Explorer 8
If IgnoreIDocDirective Then
value = 8888
Else
value = 8000
End If
Case 9 'IE 9
If IgnoreIDocDirective Then
value = 9999
Else
value = 9000
End If
Case 10 'IE 10
If IgnoreIDocDirective Then
value = 10001
Else
value = 10000
End If
Case 11 'IE 11
If IgnoreIDocDirective Then
value = 11001
Else
value = 11000
End If
Case Else ' não achou o ie?!
Exit Sub
End Select
Microsoft.Win32.Registry.SetValue(Microsoft.Win32.Registry.CurrentUser.ToString & BrowserKeyPath,
Process.GetCurrentProcess.ProcessName & ".exe",
value,
Microsoft.Win32.RegistryValueKind.DWord)
End Sub
Private Sub RemoveBrowerKey()
Dim key As Microsoft.Win32.RegistryKey
key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(BrowserKeyPath.Substring(1), True)
key.DeleteValue(Process.GetCurrentProcess.ProcessName & ".exe", False)
End Sub
Try to do it, hugs!
Tip: If you can’t find the file, put these methods on Form1.
script error when trying to open the ? page http://i.stack.Imgur.com/Ueoq1.png
– Thiago Friedman
Wesley, I believe you’re adding a Webbrowser to a Desktop application, possibly Webforms or WPF. In any case, I advise you to use Cefsharp (https://github.com/cefsharp/CefSharp) to extend Webbrowser’s ability, so it will use
Chromium Embedded Framework
instead of an older embedded version of IE (which should not know what HTML5, CC3 or Ecmascript 5 is).– Tobias Mesquita
Yes, Thiago Falcão! Several script errors happen One photo: http://i.imgur.com/t2pI6QS.png
– Wesley Silva
Hello, Tobymosque! I took a look at Cefsharp here. I think this might be the solution... change the browser engine, but I wanted to know why the same error you know, if there is any way to solve because I really like the Webbrowser of Visual Studio.
– Wesley Silva