Avatar of fmichail
fmichailFlag for Canada asked on

need a more efficient web browser control for Winforms applications

Hi Experts, 

I have windows WinForms application using VB.NET In one form I have a web browser that should display a website page and allow me to populate the fields using the database. when I use navigate method, I keep on getting a lot of reported failures on any site even microsoft.com).it looks like the web browser control is not able to run some scripts correctly.

Is there a more efficient web browser control that I can buy and use in my application

Your help is appreciated. Thanks

Visual Basic.NET.NET Programming

Avatar of undefined
Last Comment
Chinmay Patel

8/22/2022 - Mon
David Favor

If I understand your question, you're attempting to use VB to interact with other Websites, this will likely fail.

Better to use headless browser.

Even using a headless browser, this will also almost surely fail, as most large sites, like https://microsoft.com blocks this type of behavior, so you'll have to write some very crafty code to simulate human behavior to circumvent onsite countermeasures.

This also means you may also be breaking some TOS agreement you've accepted saying you won't be doing this.

Also this type of behavior... depending on exactly what you're doing... may be construed as a site attack which may carry criminal penalties in certain jurisdictions.

If you're trying to auto-magically access any Website + fill out form data mechanically, best avoid this + just do this as a human.

Note: Many sites have APIs you can use to access data, so start by researching site API docs.
ASKER
fmichail

Hi David, Thanks for the reply, what if I need to capture some information from a specific site and import it to the database... This is the main task I want to do... like reading the confirmation number of a request, processing results that are done in the site, Notes returned from the site...etc. I need to open the site first, and this is the problem, the web browser control looks like unable to run the site's scripts. 
ASKER CERTIFIED SOLUTION
Chinmay Patel

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
fmichail

Hi Chinmay
I followed the steps, however, when I ran the solution nothing shows in the form in step (9)... it is an empty form
What Am I missing?
I suppose the form should display the Microsoft site as expected... If that works, It looks like a great start. Help, please. Thanks
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
ASKER
fmichail

Hi Chinmay
It worked, It was my mistake, I forgot to download and install the webview2 runtime. Finally, what will be the files to distribute? let us consider the application as one form containing only the Webview2 control and targeting a fixed preset website. just for the view. In this case, what will be the distributable files to be copied to the client machine?

Please let me know. Thanks
Chinmay Patel

The WebView Runtime is the only thing that you will need. However, I would recommend that you let your installer take care of it in a different fashion. Also, you can check for Edge's existence on the client machine and if Edge is already installed, you can simply ignore the WebView installation.

Now in case you want to have your Installer / App the option to do this additional installation, you can take this approach: From the same page where you downloaded it: https://developer.microsoft.com/en-us/microsoft-edge/webview2/, you can use any one of the following:

1. You can get a full-offline installer.
2. You can get a bootstrapper (It's a software that downloads the rest of the required software based on the client machine - basically freeing you from that headache)
3.You can get a dynamic link for your app to use so either during the installation or after the installation, you can execute the link and the user will get a prompt to download and install WebView.

PS: I made a mistake, WebView is not in Preview. It wen GA a year ago. I am sorry for that blunder.

PPS: Thank you for your comment in the testimonial, You just made my day.


ASKER
fmichail

Thanks, Chinmay again
I do not know if I need to go for another question or You can answer me in this post. How to access the document in the page opened in the webview2 control. I need to access the HTML elements in the document by ID, and this is my main target. If you want I can open a new question and trust that you will be there for help. Thanks

Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Chinmay Patel

Not sure. It may help if you want to attract other experts (as different people have different views and some times those are better as well :) ).

I am not sure how would you like to proceed, the official way right now is to use ExecuteScript / ExecuteScriptAsync to run JS and get what you need from the Page by running the script.

If you do not like that you can use this third party, experimental library: https://github.com/ukandrewc/Webview2.Winforms.DOM

PS: Also I would like to know if you already have built installer project for your existing project. If so we might be able todo something about WebView2 installation.


ASKER
fmichail

Hi Chinmay,
I appreciate your response and dedication.

I tried to assign a value to text input on a page displayed in the webview. The text element is called EmailId
Here is the code from a button_click event

Dim msg As String = "fmichail@hotmail.com"
Dim x As Task(Of String) = WebView.ExecuteScriptAsync($"document.getElementById('EmailId').innerText = '" & msg & "';")

The text input was not changed in the webview control...isn't that what is supposed to happen
ASKER
fmichail

Sorry Chinmay, It is my mistake again, I should have used Property value instead of the InnerText

Dim msg As String = "fmichail@hotmail.com"Dim x As Task(Of String) = WebView.ExecuteScriptAsync($"document.getElementById('EmailId').value = '" & msg & "';")

 Now I need to start the pain of finding Javascripts to read/write values from / To Dropdown lists, radio buttons, checkboxes,  and for completeness also read/write the base64 src of img controls, and possibly to create a class to construct these Javascript different statements in preparation for sending it using ExecuteScriptAsync ... I Hate Javascript.
can you suggest for me Any guide where I can get help on how to read/write the basic values to elements in Javascript?
  1. Textbox text value I think this is "Value" property
  2. :Radio button On/Off ???
  3. Checkbox On/Off ???
  4. combo box text ???
  5. combo box value ???
  6. img base64 value (I think this is "src" property)

PS: concerning the installation, I will get there after I finish a proof of concept of using the webview, however, thank you for your offer to help in including the webview installation, you already gave me a lot of options to implement.
Your help has saved me hundreds of hours of internet surfing.
fblack61
ASKER
fmichail

I think you are right Chinmay, I will get some Javascript experts involved... Your help is unforgettable, Thank you
Chinmay Patel

I Hate Javascript.

I love every tech that helps me make get things done :P and while ... my first love is C#... I like JS as I love making web apps :P... I dunno I am not too loyal to any tech.. I guess..

And about not using JS, would you like to give this one a try?
https://github.com/ukandrewc/Webview2.Winforms.DOM