Introduction
This tip is for solution of web browser control hangs/freeze application issue. This is useful to those who used web browser control for scraping or visiting dynamic link, etc.
Background
When scraping website for visiting multiple links dynamically in a little time or in milliseconds/seconds, sometimes scripts of that page need more time to load content and in between you try to visit another page that hangs/freezes your application and crashes it. Most common error is "Out of memory".
Using the Code
Code for Visiting URL/ Navigation
WebBrowser1.ScriptErrorsSuppressed = True
WebBrowser1.Url = New Uri(URL)
WebBrowser1.AllowNavigation = True
Line 1: "ScriptErrorsSuppressed
" hides all its dialog boxes that originate from the underlying ActiveX control & script errors.
Line 2: Will visit/navigate to given URL.
Line 3: Will allow URL to navigate if denied.
Create Web Browser Navigating Event
Private Sub webBrowser1_Navigating(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.WebBrowserNavigatingEventArgs) Handles WebBrowser1.Navigating
If (e.Url.ToString().Contains("about:blank")) Then
WebBrowser1.Stop()
WebBrowser1.AllowNavigation = False
Return
End If
End Sub
Will stop browser while navigating the same URL multiple times for loading scripts and deny navigation.
Create WebBrowser Navigated Event
Private Sub webBrowser1_Navigated(ByVal sender As Object, _
ByVal e As WebBrowserNavigatedEventArgs) _
Handles WebBrowser1.Navigated
WebBrowser1.AllowNavigation = True
End Sub
Will allow navigation.