Get the WebView2 ResponseCode Description - vb.net

I am changing my WebBrowser to a WebView2 so that it works with Edge in my WinForm application.
I would like to be able to get the description of the WebView2 Status. Previously I used WebBrowser.StatusText.
So far I have tried:
Private Sub WebView21_NavigationCompleted(sender As Object, e As CoreWebView2NavigationCompletedEventArgs) Handles WebView21.NavigationCompleted
MsgBox(e.HttpStatusCode)
End Sub
But I would like to return the description of the code (e.g. 200 = OK, 404 == Not Found etc)
Please could you help?
Thanks

Related

Cannot navigate to facebook.com from WebBrowser Tool in VB.NET

I tried to navigate to www.google.com and it worked, I even tried to navigate to www.yahoo.com and it still worked!
But when I tried to navigate to www.facebook.com it doesn't show anything.
Here's the code:
Public Class Simple
Private Sub Simple_Load(sender As Object, e As EventArgs) Handles MyBase.Load
WebBrowser1.Navigate("https:\\www.facebook.com")
End Sub
End Class
The above code worked well but when I changed the parameter with "https:\www.facebook.com" it didn't work.
I don't know what is causing this?
Maybe it can't load javascript or something (just a guess)
Output when WebBrowser1.Navigate("https:\www.google.com")
Output when WebBrowser1.Navigate("https:\www.google.com")
WebBrowser is outdated which can cause issue with javascript and other newer libraries. I have just started to used GeckoFx which uses Firefox and not dependent on IE. Use Nuget Console "Install-Package Geckofx45 -Version 45.0.34"
Here's an example how to browse Facebook via GeckoFX
Private geckoWebBrowser As Gecko.GeckoWebBrowser
Private Sub WebView_Load(sender As Object, e As EventArgs) Handles MyBase.Load
InitializeBrowser()
End Sub
Private Sub InitializeBrowser()
Gecko.Xpcom.Initialize("Firefox")
geckoWebBrowser = New Gecko.GeckoWebBrowser()
geckoWebBrowser.Dock = DockStyle.Fill
Me.Controls.Add(geckoWebBrowser)
geckoWebBrowser.Navigate("https://www.facebook.com")
End Sub

Manipulate text in a loaded html-page of the Webbrowser control in the DocumentCompleted event (vb.net)

I already tried some solutions provided here, but I cannot get it to work. On my winform I have a webbrowser control which should load a webpage (aspx). In case the webpage isn't found, I want to let the user know that this page isn't found. To get this to work I use the following code:
Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
If (WebBrowser1.Document.Url.ToString().StartsWith("res:")) Then
Dim curDir As String = Directory.GetCurrentDirectory()
Dim Url As Uri = New Uri(String.Format("file:///{0}/Html/PageNotFound.html", curDir))
WebBrowser1.Navigate(Url)
End If
End Sub
This is working fine. The page PageNotFound.html is shown. However, I would like to provide the user with some additional information which I want to insert into the PageNotFound.html at realtime (i.e. using document.getElementById to manipulate a Label-tag). I just don't know how I can do this, or if it is even possible. Maybe I use the wrong event. something I also tried is:
With WebBrowser1
.Navigate("about:blank")
.Document.OpenNew(False)
.Document.Write(HtmlString)
.Refresh()
End With
Where the HtmlString contains a complete webform.(like: "")
Maybe someone put me the right direction? TIA

VB.NET Gecko WebBrowser Link Click to get URL

So I am trying to get the URL of a link that I click while using the Gecko WebBrowser. So if I were to click on a .DLL file in my directory (URL = File://C:/File.DLL) it would then give me the URL of what I clicked. I can right click on it and get the URL but I would like to just be able to click on it and get the URL. Thank you very much!
I just asked how the handle a click on html element in Gecko and maybe this can help you:
Private Sub browser_DomClick(ByVal sender As Object, ByVal e As Gecko.DomMouseEventArgs) Handles browser.DomClick
Dim element As Gecko.GeckoHtmlElement = e.Target.CastToGeckoElement
Dim url as String = element.GetAttribute("href")
End Sub
Declare
Friend WithEvents browser As Gecko.GeckoWebBrowser
if needed
Not tested!

VB.NET 2008 - Input to data to website controls and download results

this is my first Q on this website so let me know if I have missed any important details, and thanks in advance.
I have been asked to access a website and download the results from a user-inputted form. The website asks for a username/password and once accepted, several questions which are used to generate several answers.
Since I am unfamiliar with this area I have set up a simple windows form to tinker around with websites and try to pick things up. I have used a webbrowser control and a button to use it to view the website in question.
When I try to view the website through the control, I just get script errors and nothing loads up. I am guessing I am missing certain plug-ins on my form that IE can handle without errors. Is there anyway I can identify what these are and figure out what to do next? I am stumped.
The script errors are:
"Expected identifier, string or number" and
"The value of the property 'setsection' is null or undefined"
Both ask if I want to continue running scripts on the page. But it works in IE and I cannot see why my control is so different. It actually request a username and password which works fine, it is the next step that errors.
I can provide screenies or an extract from the website source html if needed.
Thanks,
Fwiw my code is:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'WebBrowser1.ScriptErrorsSuppressed = True
WebBrowser1.Navigate("http://website.com")
'WebBrowser1.Navigate("http://www.google.com")
End Sub
Thanks for Noseratio I have managed to get somewhere with this.
Even though the errors I was getting seemed to be related to some XML/Java/Whatever functionality going askew it was actually because my webbrowser control was using ie 7.0
I forced it into using ie 9 and all is now well. So, using my above example I basically did something like this:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'WebBrowser1.ScriptErrorsSuppressed = True
BrowserUpdate()
WebBrowser1.Navigate("http://website.com")
'WebBrowser1.Navigate("http://www.google.com")
End Sub
Sub BrowserUpdate()
Try
Dim IEVAlue As String = 9000 ' can be: 9999 , 9000, 8888, 8000, 7000
Dim targetApplication As String = Process.GetCurrentProcess.ToString & ".exe"
Dim localMachine As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.LocalMachine
Dim parentKeyLocation As String = "SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl"
Dim keyName As String = "FEATURE_BROWSER_EMULATION"
Dim subKey As Microsoft.Win32.RegistryKey = localMachine.CreateSubKey(parentKeyLocation & "\" & keyName)
subKey.SetValue(targetApplication, IEVAlue, Microsoft.Win32.RegistryValueKind.DWord)
Catch ex As Exception
'Blah blah here
End Try
End Sub

How to get HTML from the URL and display it in certain place?

I'm in progress with my first application in visual basic, and I'm using the visual basic studio - My question is, how can I get raw HTML data from specified URL, and then display it in my form on the certain position?
I havent tried anything yet, because I havent found much solutions about this on the internet.
You need to use the HttpClient class or the WebClient class to get the raw HTML as a string. Then, you can simply display the string in any control on your form such as a TextBox or Label control.
For instance:
Public Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim client As WebClient = New WebClient()
Label1.Text = client.DownloadString("http://www.stackoverflow.com")
End Sub