0

I've just set up VS 2019 and I'm trying to use the WebBrowser in VB.net. I followed a YouTube video, created the form, browser, etc, but when I 'start' the code the Browser screen flashes on for half a second then drops.

There are no errors shown but I get 'The program '[7804] WebBrowser_2.exe' has exited with code 0 (0x0).'

and ideas please?

I've cut it down to the minumum, to go to one web site...

form1.vb
Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        WebBrowser1.Navigate("www.bbc.co.uk")
    End Sub
End Class

I've also tried a few different web sites, and setting txtURL.Text then using:

WebBrowser1.Navigate(txtURL.Text)
WebBrowser1.Navigate(New Uri(txtURL.Text))

Nothing's working yet.

Peterd51
  • 19
  • 1
  • 1
  • 3
  • 2
    What do you mean by *the Browser drops*? Where do you get *'The program '[7804] WebBrowser_2.exe' has exited with code 0*? Is this a WinForms app or something else? -- BTW, in case you actually built a WinForms app, you need to suppress script errors notifications (`ScriptErrorsSuppressed = true`) and enable IE11 emulation mode. Take the `WebBrowserAdvancedFetures` from [here](https://stackoverflow.com/a/57615713/7444103) and call its `ActivateWBAdvancedFeatures()` method as described there – Jimi Apr 11 '21 at 12:32
  • 1
    You might consider using Webview2 instead: https://learn.microsoft.com/en-us/microsoft-edge/webview2/ – Tu deschizi eu inchid Apr 11 '21 at 13:03
  • Jimi: thanks, I'm not sure about anything as I've never used VS before. That response was in the bottom left box. I think it's a WinForm. I found references to the ScriptErrors and IE11 and both are set on my PC. When I start the code something flashes on the screen but only for half a second. It's a black box and I think it has the 'Web Browser' Form Title on the top edge but it's too quick to see it before it's gone. – Peterd51 Apr 12 '21 at 07:03
  • User9938: thanks, I'll look for that now. I just want to go to one web-site and grab the source-code for the page to get specific infomation from it. – Peterd51 Apr 12 '21 at 07:05
  • You probably built a Console app instead of a Windows Forms app. Make a new Solution and this time pick `Windows Forms App (.Net Framework)` as template for the main Project. – Jimi Apr 12 '21 at 08:07
  • Thanks, I'll try again. – Peterd51 Apr 12 '21 at 10:47
  • Thanks Jimi, that made a big difference. The first point was I didn't have to 'add' the form, it was already there. And setting the URL went straight to the page when I ran the code. I missed the 'Windows Forms App' as it wasn't in the original list but I found it on a search. – Peterd51 Apr 12 '21 at 10:57
  • Hi, Webview2 is mostly working now, I can type in a URL hit the 'go' button, forward & back buttons all OK. I can't find the right VB code to copy the outerHTML, I've tried a general google search and found many different possibilities. Any ideas please? – Peterd51 Apr 12 '21 at 19:39
  • "I just want to go to one web-site and grab the source-code for the page to get specific infomation from it." You don't necessarily need the outerHTML in order to get information from the page--get it from the DOM. – Tu deschizi eu inchid Apr 13 '21 at 15:01
  • Yes, I saw that, it looks a lot more complex though. I started looking at using C# yesterday as all of the examples are written in that. Not my first choice as it's been a long time since I've done any C but it looks like I could build the whole thing using other peoples code a stick it together. I'll only need one 'copy code' button as the user won't need to 'navigate' in this program. Any page changes will be done using the website controls. – Peterd51 Apr 14 '21 at 07:24

0 Answers0