-
Re: VB6 WebView2-Binding (Edge-Chromium)
Hi again,
what is the difference between providing arguments in the New_c.WebView2(...) compared to BindTo(...)?
I.e. adding userDataFolder and additionalBrowserArguments seems only have to affect in BindTo(), and also it seems that even the arguments are optional I can't just provide the additionalBrowserArguments without also specifying a userDataFolder. If userDataFolder is left empty or as an empty string, BindTo will fail.
regs
Stefan
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
Bearfot
what is the difference between providing arguments in the New_c.WebView2(...) compared to BindTo(...)?
None ...
The only difference is, that the optional timeout-param is a bit shorter (5sec) behind New_c, than in BindTo (8sec) -
though this might exactly be the difference on some older (slower) machines between the two calls.
I have corrected that timeout-difference in the cConstructor-call to 8sec now (to match with BindTo).
Quote:
Originally Posted by
Bearfot
I.e. adding userDataFolder and additionalBrowserArguments seems only have to affect in BindTo(),
All the Params are just "routed through" to BindTo, as they come in via New_c.WebView2 -
(the only exception - as said - being a different timeout, when you leave this param-slot free).
Quote:
Originally Posted by
Bearfot
and also it seems ...
I can't just provide the additionalBrowserArguments without also specifying a userDataFolder.
If userDataFolder is left empty or as an empty string, BindTo will fail.
If userData is left empty, the BindTo-call will internally not "leave it that way", but initialize it to:
If Len(userDataFolder) = 0 Then userDataFolder = New_c.FSO.GetLocalAppDataPath
(which resolves e.g. on my Win10 to: C:\Users\Olaf\AppData\Local)
Perhaps certain commandline-arguments only work with certain UserDataFolder-Paths
(which might also depend on the OS-version you are using - I've heard of Users who have had problems on Win7)...
As for your earlier question... I think "finding the right HTML5" (and Css- or style-attributes)
is in the responsibility of the Users of this control-binding (to not blow this thread here "out of proportion") -
and would suggest to post your HTML-questions in a better matching Forum (or SubForum on this site).
HTH
Olaf
-
Re: VB6 WebView2-Binding (Edge-Chromium)
@Olaf, thanks for reply!
Quote:
Originally Posted by
Schmidt
As for your earlier question... I think "finding the right HTML5" (and Css- or style-attributes)
is in the responsibility of the Users of this control-binding (to not blow this thread here "out of proportion") -
and would suggest to post your HTML-questions in a better matching Forum (or SubForum on this site).
My earlier question was regarding basic authentication. If it was possible to get a callback from cWebView2 and provide user name and password in order to prevent the Sign in prompt (if a site uses basic authentication). E.g. something like GetCredentials(ByVal Url As String, UserName As String, Password As String, Cancel As Boolean).
regs
Stefan
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
Bearfot
My earlier question was regarding basic authentication.
Oops, my bad (interchanged your post with that from Andrew/EasyOneX)...
Quote:
Originally Posted by
Bearfot
If it was possible to get a callback from cWebView2 and provide user name and password in order to prevent the Sign in prompt (if a site uses basic authentication). E.g. something like GetCredentials(ByVal Url As String, UserName As String, Password As String, Cancel As Boolean).
I don't know what exact behaviour you relate to, when you talk about "WinInet-usage" in conjunction with the old IE-Control.
If you "already know" the user-credentials from an earlier "logon-attempt"...
then the basic-auth credentials can be passed directly in the URL, as e.g.:
There's also a lot of different "auth"-related params for the commandline... you might want to experiment with.
And finally, there's (since 6.0.9) a new method:
- NavigateWithWebResourceRequest (which has an optional param: Headers_CrLfSeparated As String)
which will allow you to specify headers like e.g.: "Authorization: Basic <your base64-encoded credentials>"
HTH
Olaf
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Yes, passing username:password in the url is how I now currently solved it, but that is not a preferable solution from a security perspective.
Instead username/password should not be provided unless the site requests for it, and with a callback I can check if I have the proper credentials for the url, and in that case provide them or otherwise set cancel = true which will bring up the default Sign in prompt. Just a proposal for a nice feature for the future :-)
Thanks again
Stefan
-
Re: VB6 WebView2-Binding (Edge-Chromium)
When I execute the js command,
WV.AddScriptToExecuteOnDocumentCreated jscode
WV.jsRunAsync "GetLinks", "div.picList > ul > li>a" '. error Unable to read in WV_JSAsyncResult. .
if changed to
WV.AddScriptToExecuteOnDocumentCreated jscode
sleep 1000
WV.jsRunAsync "GetLinks", "div.picList > ul > li>a" '.
execution succeed. Is there a better way without sleep?
Also execute WV.ExecuteScript "document.querySelector('#app > div > section > aside > span').click();" sometimes the webpage is not executed successfully. So I will modify it to
WV.ExecuteScript "document.querySelector('#app > div > section > aside > span').click();"
sleep 1000
WV.ExecuteScript "document.querySelector('#app > div > section > aside > span').click();"
sleep 1000
WV.ExecuteScript "document.querySelector('#app > div > section > aside > span').click();"
Is there any good way to wait for js to finish executing synchronously?
How is the jsCallTimeOutSeconds function used?
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Hi Olaf,
Thank you for such a great contribution. I was able to achieve most of the task that I need to.
However, I am unable to handle below scenarios:
1. Handle multiple downloads: I want to enable this by default to allow multiple file download (disable multiple file download confirmation). This is because I perform very lengthy process which ends with downloading multiple files which is currently blocked after downloading first file.
2. Default file download location: How to specify default file download location?
I tried to play with %appdata%\EBWebView\Default\Preference file that stores this settings. However, this file is overwritten automatically by some process every few seconds which causes reversal of my changes.
Also, I see that WebView2 has DownloadStarting event that allows to achieve some part of above, but I do not see that available in cWebView2.
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Hi Olaf,
if you have any plans of extending the cWebView2 events (e.g. DownloadStarting) then also the DocumentTitleChange is of interest. I have solved it now by adding the following code in the DocumentComplete event:
m_webView.ExecuteScript "document.addEventListener('DOMSubtreeModified', function(e){if(e.target.nodeName === 'TITLE') vbH().RaiseMessageEvent('OnTitleChange',e.target.text)})"
This is maybe not the most efficient solution, but at least it works.
In addition I'm also very interested in getting access to "CoreWebView2EnvironmentOptions". Its property "AdditionalBrowserArguments" can be applied in the constructor and BindTo method, but is is possible to access the "Language" and "AllowSingleSignOnUsingOSPrimaryAccount" properties?
Finally in order to solve my earlier WinInet issues there seems to be a solution by copying cookies from WinInet to WebView2, but it would the require access to the "CoreWebView2CookieManager" object. Any plans to make such extensions of the cWebView?
regs
Stefan
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Hi again Olaf,
one more question. I found a bug when adding an object using the AddObject() method which I guess internally calls the "AddHostObjectToScript". It seems that you can't access an attribute named "length" of such object. The solution I found was to add the following line for the created javascript proxy object:
var myobject = window.chrome.webview.hostObjects.sync.myobject; // myobject with a "length" attribute added with cWebView2.AddObject()
alert(myobject.length); // will always display 0
// adding the following solves the issue
myobject._forceRemoteProperties.add("length"); // myobject is actually a proxy object in javascript
alert(myobject.length); // now shows the correct value of myobject.length
As I don not know the implementation details, is this a bug in cWebView2.AddObject() or something I should report in github for CoreWebView2.AddHostObjectToScript()?
regs
Stefan
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Hello avinash7 and Bearfot
Olaf seems to rarely respond to requests to add functionality to RC6. It's probably to avoid putting pressure on himself. The task he has set himself is indeed hudge.
In a recent conversation, he told me he hoped to integrate Webview2 download management in version 6.0.10 of RC6. I look forward to this version to continue my developments. I even check every day if the new version is posted on his site!
We'll have to be patient :)
Thanks again to Olaf for his fantastic work !
-
Re: VB6 WebView2-Binding (Edge-Chromium)
The AddHostObjectToScript issue is confirmed bug in webview2 (issue #2185) so this can be ignored.
Access of the cookie manager can also be skipped as this seems not solve my issue.
Other things just nice to have, so no remaining issues from me.
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
saturnian
It's probably to avoid putting pressure on himself
Sorry Olaf and saturnian if it looked like creating pressure. I posted here to see if there is anything already available and can be leveraged to achieve what I wanted to do. This is because I see that Olaf has surfed breadth and depth of this area!
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
Schmidt
Have just finished a Binding to the new WebView2-BrowserControl (based on Edge-Chromium).
I've included this Binding (all in a single Class, named cWebView2) in the new RC6-version of the RichClient-lib
(please download this new version 6 from its usual place, at vbRichClient.com first).
The new BaseDll-package of the RC6 now includes the official WebView2Loader.dll (version 1.0.674),
which the cWebView2-class then works against.
Please note, that the above Binding will currently require, that you install the larger:
"Evergreeen WebView2-Runtime" (not included in the RC6-BasePackage).
Here the official MS-DownloadLink for the evergreen-installer:
https://go.microsoft.com/fwlink/p/?LinkId=2124703
So, after ensuring the mentioned two prerequisites:
- the Dlls of the new RC6-package in a folder of your choice + a registered RC6.dll
- and the successfull installation of the "evergreen-WebView2-runtime" via the MS-download-link above
You should now be able to test this new Edge-Browser-Binding (even on Win7-OSes) via this little VB6-Demo:
Attachment 179166
Please let me know, when something is not working as expected -
or when you want me to include a certain extra-functionality into the new cWebView2-class.
I want to "finalize" the new RC6-functionality at the end of the year (then switching Binary-Compatibility on).
Happy testing... :)
Olaf
Hi Schmidt,
I tired WebView2Demo it is really great. I wanted to know if we can integrate events of webbrowser1 with its replacements in WebView2.
For Example :
1.StatusTextChange
2.BeforeNavigate2
3.WindowClosing
I tried few events but was unable to recreate the events I mentioned before.
Could you please guide me for the same.
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Hi is it possible to get an object with jsProp, getElementsByClassName doesn't work for me either.
Code:
Dim Elements As Object
Set Elements = Document.GetElementsbyClassName("FTBzM")
with IE this worked, should I think about it differently?
-
Re: VB6 WebView2-Binding (Edge-Chromium)
I'm new to all this, so take it easy on me, please :)
I have successfully used the WebView2 in the VB6 IDE without issues... BUT, when I go to MAKE my project, it fails to compile with the following error:
Unexpected error occurred in code generator or linker. --View error messages?
I click on Yes and get a text tmp file that contains this error:
C:\<MYFOLDER>\<MYFORM>.frm(6624) : fatal error C1001: INTERNAL COMPILER ERROR
(compiler file 'e:\work\utc2\src\P2\main.c', line 495)
Please choose the Technical Support command on the Visual C++
Help menu, or open the Technical Support help file for more information
If I comment out any lines where I'm doing this:
Set wv5 = New_c.WebView2
or this:
If wv5.BindTo(... blah, blah... ) then
Then the program compiles fine. Obviously, it doesn't *work* correctly because these lines are commented out.
Again, if I just Run the program in the VB6 IDE, then it works great.
Please help.
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
BooksRUs
I'm new to all this, so take it easy on me, please :)
I have successfully used the WebView2 in the VB6 IDE without issues... BUT, when I go to MAKE my project, it fails to compile with the following error:
Unexpected error occurred in code generator or linker. --View error messages?
I click on Yes and get a text tmp file that contains this error:
C:\<MYFOLDER>\<MYFORM>.frm(6624) : fatal error C1001: INTERNAL COMPILER ERROR
(compiler file 'e:\work\utc2\src\P2\main.c', line 495)
Please choose the Technical Support command on the Visual C++
Help menu, or open the Technical Support help file for more information
If I comment out any lines where I'm doing this:
Set wv5 = New_c.WebView2
or this:
If wv5.BindTo(... blah, blah... ) then
Then the program compiles fine. Obviously, it doesn't *work* correctly because these lines are commented out.
Again, if I just Run the program in the VB6 IDE, then it works great.
Please help.
Maybe it's a question about the RC6 path.
https://www.vbforums.com/showthread....=1#post5443031
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
SearchingDataOnly
I used the included RegisterRC6inPlace.vbs to register RC6 on my dev PC, directly inside my App folder, in hopes that nothing would be confused as to where anything was.
I did extract all the DLL files into this same folder. Does any of the other DLLs need to be registered just so the VB6 can compile an EXE that uses RC6?
Thanks!
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
BooksRUs
I used the included RegisterRC6inPlace.vbs to register RC6 on my dev PC, directly inside my App folder, in hopes that nothing would be confused as to where anything was.
I did extract all the DLL files into this same folder. Does any of the other DLLs need to be registered just so the VB6 can compile an EXE that uses RC6?
Thanks!
If it runs in the IDE, then there is nothing wrong with the registration of RC6 -
so the compiler-error you see has to have other reasons - like e.g.:
- you're not running the IDE "as Admin" (when compiling)
- you're not using the most recent ServicePack for the VB6-IDE
- you've registered the RC6 on a Network-Path, or a "mapped Network-Drive"
- you've opened your VB-Project from a Network-Path or a "mapped Network-Drive"
- you're trying to compile the Binary "into a Network-Path or a mapped Network-Drive"
I'd start trying to fix this, by ensuring Admin-Mode for the IDE -
and try to "open, and compile to" from/to local Folders on local Disks...
(also making sure, that "compiling Debug-info into your Executable" is deactivated in the IDEs compiler-settings)
HTH
Olaf
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
Schmidt
If it runs in the IDE, then there is nothing wrong with the registration of RC6 -
so the compiler-error you see has to have other reasons - like e.g.:
- you're not running the IDE "as Admin" (when compiling)
- you're not using the most recent ServicePack for the VB6-IDE
- you've registered the RC6 on a Network-Path, or a "mapped Network-Drive"
- you've opened your VB-Project from a Network-Path or a "mapped Network-Drive"
- you're trying to compile the Binary "into a Network-Path or a mapped Network-Drive"
I'd start trying to fix this, by ensuring Admin-Mode for the IDE -
and try to "open, and compile to" from/to local Folders on local Disks...
(also making sure, that "compiling Debug-info into your Executable" is deactivated in the IDEs compiler-settings)
HTH
Olaf
First, I want to say a big THANKS to Olaf, for all your hard work on all of these tools! Also, for your time to jump in and try to help me out. Right away, *none* of the suggestions you have apply, I double-checked them all.
The particular form I'm adding this to is the "main" form for a pretty large program that has been my project for the last 13 years. It is on the edge of having more controls than VB6 allows, so I thought perhaps having to declare WV (with events) was pushing it over the limit. I don't know if it's possible, but it would be wonderful if we could have an ARRAY of WV (with events). I'm not sure if these declarations "count" towards the VB6 limits or not, but either way, this would allow an array of WV that match an array of PicBoxes that "host" the WVs that I want to use the in program (there are several). This is exactly how I'm implementing this with the Webbrowser controls that I'm trying to replace.
Anyway, I went "back to basics" and tried to compile the sample program and it compiled right up without problems AND it actually works when Run, both in the IDE and the EXE.
So, I *moved* these statements:
Set wv5 = New_c.WebView2
If wv5.BindTo(FZwv(5).hwnd, , "C:\<myfolder>\EdgeWebView") = 0 Then
... to the Form_Load event (as in the Demo program) and the program now *does* Compile, but it does *not* work. For some reason, in my program, it seems to want me to do the BindTo again in order to work correctly...
Perhaps, this is because the PicBox isn't really visible YET in the Form_Load event? Does the PicBox actually *have* to be Visible in order for the BindTo to work correctly? The main form isn't yet visible in the load event, it's busy loading... AND the user has yet to actually do anything that will make the WV/PicBox visible in the program, as this is an option for the user to turn this on or off.
Again, Thanks for all your work on this and other tools over the years.
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Perhaps, this is because the PicBox isn't really visible YET in the Form_Load event? Does the PicBox actually *have* to be Visible in order for the BindTo to work correctly? The main form isn't yet visible in the load event, it's busy loading... AND the user has yet to actually do anything that will make the WV/PicBox visible in the program, as this is an option for the user to turn this on or off.
That's right! The window to whose hwnd the WebView is bound must be visible. This can be quite tricky with modal windows.
In my sample code, I do something like this: https://www.vbforums.com/showthread....mo-application
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
wwolf
It appears that the entire project is not based on normal VB6 forms. Without a total rewrite, are there some snippets of code that I could possibly use to get passed the Visible requirement, or to trick it into working?
Thanks!
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
BooksRUs
Perhaps, this is because the PicBox isn't really visible YET in the Form_Load event?
Yes, the PicBox.hWnd (any hWnd) you bind to,
has to be visible at the point you call WV.BindTo...
And any hWnd-based Child-Control will report False (regarding its visibility),
as long as its hosting TopLevel-Parent is still invisible (in your case, your Form).
Please take another look at the first line in my original Demo-Codes Form_Load (and the comments I made there).
Olaf
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
Schmidt
Yes, the PicBox.hWnd (any hWnd) you bind to,
has to be visible at the point you call WV.BindTo...
And any hWnd-based Child-Control will report False (regarding its visibility),
as long as its hosting TopLevel-Parent is still invisible (in your case, your Form).
Please take another look at the first line in my original Demo-Codes Form_Load (and the comments I made there).
Olaf
Thanks again, Olaf. I spent alot of time trying different things, but I feel like I'm spinning my wheels because I was getting away from the *real* problem. I can live within the parameters of when to be Visible and when to SET & BINDTO, as the program is actually *working*.
The real problem is that the program won't *compile*. So, I tried different settings on the VB6 compiler dialog -- it appears that the only way I can get it to compile is to change it to Compile to P-Code. Any other setting I tried with a working program, would generate the compiler error in the original post.
Only time will tell if I'm able to keep these settings and distribute without causing other unknown issues, but I'm going to give it a try.
Thanks again for helping me out. If there's anything else I can provide that might help solve the issue, just let me know.
:)
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
Schmidt
WV.jsRun is thought for simple (for the most part, self-defined) functions...
For more complex "actions" like yours above, try it with:
WV.ExecuteScript "document.getElementById('Somebutton').click()"
instead.
HTH
Olaf
I'm trying to simply automatically login to a website. I'm replacing a VB6 webbrowser control. I have already analyzed the login page and I know the fields I want to fill in are "user_name" and "user_password". The login button is on the first (0) form on the page. So, I used to do this:
set w=webbrowser.Document
set f=w.forms.item(0)
set e=f.elements
e.Item("user_name").Value = <myuserid>
e.Item("user_password").Value = <mypassword>
f.submit
My question is, how do I do this with the new WebView since the DOM is not there, and the Submit button doesn't *have* a name?
Thanks!
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
BooksRUs
My question is, how do I do this with the new WebView since the DOM is not there...
The DOM is there, but you have to interact with it in js now...
(cWebView2 is making this easy via AddScriptToExecuteOnDocumentCreated)
Code:
With New_c.StringBuilder
.AddNL "function submitLoginForm(usr, pwd){"
.AddNL " var f = document.forms[0]"
.AddNL " f.elements['user_name'].value = usr"
.AddNL " f.elements['user_password'].value = pwd"
.AddNL " f.submit()"
.AddNL "}"
wv.AddScriptToExecuteOnDocumentCreated .ToString
End With
Such an "extension-function" can be added before you navigate to a certain page.
Only the usage of this function - e.g. via:
wv.jsRun "submitLoginForm", "myUsrID", "myPwd"
has to be done after the document was loaded (e.g. from within Navigation_Complete or Document_Complete)
Olaf
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
Schmidt
The DOM is there, but you have to interact with it in js now...
(cWebView2 is making this easy via
AddScriptToExecuteOnDocumentCreated)
Code:
With New_c.StringBuilder
.AddNL "function submitLoginForm(usr, pwd){"
.AddNL " var f = document.forms[0]"
.AddNL " f.elements['user_name'].value = usr"
.AddNL " f.elements['user_password'].value = pwd"
.AddNL " f.submit()"
.AddNL "}"
wv.AddScriptToExecuteOnDocumentCreated .ToString
End With
Such an "extension-function" can be added
before you navigate to a certain page.
Only the
usage of this function - e.g. via:
wv.jsRun "submitLoginForm", "myUsrID", "myPwd"
has to be done after the document was loaded (e.g. from within Navigation_Complete or Document_Complete)
Olaf
Cool, thanks for the info. A few questions:
1. Once I inject this function, is it "persistent" upon each subsequent Navigate event, or is it just good for *one* Navigate, then it goes away?
2. Is there a way to "peruse" the DOM with WV? Sometimes I have to basically "dump" all of the forms and elements of a page in order to find/pick out the particular form, element or field that I need to match, fill in, check, or click.
3. How do I "click" a button that doesn't seem to have a name?
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
BooksRUs
1. Once I inject this function, is it "persistent" upon each subsequent Navigate event, or is it just good for *one* Navigate, then it goes away?
It is persistent (on that bound wv-instance) for all subsequent navigations -
basically ensuring "your own set of global js-helper-functions"... -
(which BTW could also be aggregated in a normal "myGlobalHelpers.js" File for better editability,
and then added in one go like this:
wv.AddScriptToExecuteOnDocumentCreated New_c.FSO.ReadTextContent(App.Path & "\myGlobaHelpers.js")
Quote:
Originally Posted by
BooksRUs
2. Is there a way to "peruse" the DOM with WV?
Sure, you can even get "visual assistance" on a loaded DOM, by opening the "Chrome-Inspector" via:
wv.OpenDevToolsWindow
Quote:
Originally Posted by
BooksRUs
3. How do I "click" a button that doesn't seem to have a name?
You could learn to use "selector-string-expressions" via e.g.:
- document.querySelector("<your selector string>") https://developer.mozilla.org/en-US/.../querySelector
- SomeElement.querySelector("<your selector string>") https://developer.mozilla.org/de/doc.../querySelector
Selector-Strings are extremely powerful (they allow to search for any attribute, parent/child-relation and so on...)
At the end of the day, there's no way around doing all your "DOM-stuff" in javascript ...
but it has to be said, that this usually requires less lines of code, compared to VB6/IE-COMbased-DOM-parsing.
Olaf
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
BooksRUs
1. Once I inject this function, is it "persistent" upon each subsequent Navigate event, or is it just good for *one* Navigate, then it goes away?
Click on different links on the Google page and watch out for the alert window:
Code:
Option Explicit
Private WithEvents WV As cWebView2
Private Sub Form_Activate()
If WV Is Nothing Then
Set WV = New_c.WebView2(Me.hWnd)
WV.AddScriptToExecuteOnDocumentCreated "function getSiteTitle(){alert (document.title)}"
WV.Navigate "http://www.google.com"
End If
End Sub
Private Sub Form_Resize()
If WindowState <> vbMinimized Then
If Not WV Is Nothing Then WV.SyncSizeToHostWindow
End If
End Sub
Private Sub WV_DocumentComplete()
WV.jsRun "getSiteTitle"
End Sub
Quote:
Originally Posted by
BooksRUs
2. Is there a way to "peruse" the DOM with WV? Sometimes I have to basically "dump" all of the forms and elements of a page in order to find/pick out the particular form, element or field that I need to match, fill in, check, or click.
Code:
Option Explicit
Private WithEvents WV As cWebView2
Private Sub Form_Activate()
If WV Is Nothing Then
Set WV = New_c.WebView2(Me.hWnd)
WV.Navigate "http://www.google.com"
End If
End Sub
Private Sub Form_Resize()
If WindowState <> vbMinimized Then
If Not WV Is Nothing Then WV.SyncSizeToHostWindow
End If
End Sub
Private Sub WV_DocumentComplete()
Debug.Print "Source: " & WV.jsProp("Array.prototype.slice.call(document.getElementsByTagName('INPUT')).join(';')")
End Sub
Quote:
Originally Posted by
BooksRUs
3. How do I "click" a button that doesn't seem to have a name?
https://stackoverflow.com/questions/...706236#2706236
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
BooksRUs
The particular form I'm adding this to is the "main" form for a pretty large program that has been my project for the last 13 years. It is on the edge of having more controls than VB6 allows, so I thought perhaps having to declare WV (with events) was pushing it over the limit. I don't know if it's possible, but it would be wonderful if we could have an ARRAY of WV (with events). I'm not sure if these declarations "count" towards the VB6 limits or not, but either way, this would allow an array of WV that match an array of PicBoxes that "host" the WVs that I want to use the in program (there are several). This is exactly how I'm implementing this with the Webbrowser controls that I'm trying to replace.
I wanted to highlight the above, as I believe I have hit the VB6 maximum number of controls for a form. I was able to save the code (for a while), but then randomly, VB6 started kicking me out of the IDE without warning -- no Save, no nothing.
I currently need 10 WebView controls to replace the webbrowser controls in the form. They are an array, so it seems to be ok with these, but I will have to see if there's anything that can be deleted from the form in order to truly replace all of them.
I don't have a clue what would go into doing this, but I'd like to think everyone would benefit from it.
Thanks!
-
1 Attachment(s)
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
BooksRUs
It would be wonderful if we could have an ARRAY of WV (with events)
The RC6.cEventCollection might be what you are looking for. I've adapted Olaf's original demo to show how you can use the cEventCollection with cWebView2 bound to a control array of PictureBoxes:
Attachment 184364
The code should be fairly easy to understand on it's own - it's only slightly more complicated that it would be if we the cEventCollection had an Item property, but I've made do with a separate cArrayList to hold WV references that we can access via the cEventCollection Key property). Let me know if you have any questions though.
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
jpbro
The RC6.cEventCollection might be what you are looking for. I've adapted Olaf's original demo to show how you can use the cEventCollection with cWebView2 bound to a control array of PictureBoxes:
Attachment 184364
The code should be fairly easy to understand on it's own - it's only slightly more complicated that it would be if we the cEventCollection had an Item property, but I've made do with a separate cArrayList to hold WV references that we can access via the cEventCollection Key property). Let me know if you have any questions though.
Cool!
I'll check it out and let you know.
Thanks!
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
BooksRUs
I currently need 10 WebView controls to replace the webbrowser controls in the form.
They are an array, ...
Then the easiest way to keep up with the existing "scheme" would be,
to implement a little "Project-Private-UserControl" for your WebView2-Binding.
E.g. something like that into a UserControl, named ucWV:
Code:
Option Explicit
Event DocumentComplete() 'redefine all the Events you need externally in this place...
Private WithEvents mWV As cWebView2, InitDone As Boolean
Public Property Get WV() As cWebView2
EnsureBinding
Set WV = mWV
End Property
Private Sub EnsureBinding()
If Not Ambient.UserMode Then Exit Sub
If mWV Is Nothing And Not InitDone And Extender.Visible Then
InitDone = True: Set mWV = New_c.WebView2(UserControl.hWnd)
UserControl_Resize
End If
End Sub
Private Sub UserControl_Resize()
If Not mWV Is Nothing Then mWV.SyncSizeToHostWindow
End Sub
'*** Event-ReDelegation of internal Events (only those which are needed externally)...
Private Sub mWV_DocumentComplete()
RaiseEvent DocumentComplete 're-raise the internal Event to the outside
End Sub
After your Private UC was defined, you can now place two of them on a Form (as a Ctl-Array), then using this Code:
Code:
Option Explicit
Private Sub Form_Load()
Visible = True 'always ensure Visibility of the TopLevel-Window first
ucWV(0).WV.NavigateToString "<h1>Hello World</h1>" 'Ctl at Index 0 navigates to a String
ucWV(1).WV.Navigate "https://google.com" 'Ctl at Index 1 navigates to Google
End Sub
Private Sub ucWV_DocumentComplete(Index As Integer) 'example for Ctl-Array-based Event-Handling
With ucWV(Index).WV
Debug.Print .jsProp("Array.from(document.getElementsByTagName('h1')).map(e=>e.innerText).join(',')")
End With
End Sub
So it just boils down to a bit of work inside the UC (for the Event-Definition and -ReDelegation).
Though in the end this should be quite elegant and robust.
Olaf
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
Schmidt
Then the easiest way to keep up with the existing "scheme" would be,
to implement a little "Project-Private-UserControl" for your WebView2-Binding.
E.g. something like that into a UserControl, named
ucWV:
Code:
Option Explicit
Event DocumentComplete() 'redefine all the Events you need externally in this place...
Private WithEvents mWV As cWebView2, InitDone As Boolean
Public Property Get WV() As cWebView2
EnsureBinding
Set WV = mWV
End Property
Private Sub EnsureBinding()
If Not Ambient.UserMode Then Exit Sub
If mWV Is Nothing And Not InitDone And Extender.Visible Then
InitDone = True: Set mWV = New_c.WebView2(UserControl.hWnd)
UserControl_Resize
End If
End Sub
Private Sub UserControl_Resize()
If Not mWV Is Nothing Then mWV.SyncSizeToHostWindow
End Sub
'*** Event-ReDelegation of internal Events (only those which are needed externally)...
Private Sub mWV_DocumentComplete()
RaiseEvent DocumentComplete 're-raise the internal Event to the outside
End Sub
After your Private UC was defined, you can now place two of them on a Form (as a Ctl-Array), then using this Code:
Code:
Option Explicit
Private Sub Form_Load()
Visible = True 'always ensure Visibility of the TopLevel-Window first
ucWV(0).WV.NavigateToString "<h1>Hello World</h1>" 'Ctl at Index 0 navigates to a String
ucWV(1).WV.Navigate "https://google.com" 'Ctl at Index 1 navigates to Google
End Sub
Private Sub ucWV_DocumentComplete(Index As Integer) 'example for Ctl-Array-based Event-Handling
With ucWV(Index).WV
Debug.Print .jsProp("Array.from(document.getElementsByTagName('h1')).map(e=>e.innerText).join(',')")
End With
End Sub
So it just boils down to a bit of work inside the UC (for the Event-Definition and -ReDelegation).
Though in the end this should be quite elegant and robust.
Olaf
Ok, Newbie alert! :duck:
I know this will sound crazy, but I have never created my own control... but, I'm willing to give it a try.
To start, is this an ActiveX DLL, EXE, OCX?
For the events that have parameters, do I have to declare the same parameters in the Event declaration, then pass them "up" to the real control, or do the parameters automatically go up?
Also, I was trying to add a "Busy" flag, as I didn't see how I can do this:
1. Navigate somewhere
2. wait until WV is actually there and complete
3. continue
So, in my main program, I basically set a global Boolean for *each* WV as WVbusy=true, just before I WV.navigate, then in the NavigationCompleted event, I reset the global WVbusy back to false.
Since I'm "extending" the WV, I didn't know how/if I could extend it this way?
Thanks!
-
Re: VB6 WebView2-Binding (Edge-Chromium)
I programmed an ocx encapsulating the RC6's Webview2 for my own purposes. It is available here, for those interested.
It is a version which will evolve with the improvements of the RC6 and which is delivered as it is, without any guarantee. But in my software, it works perfectly. Thanks again to Olaf!
François
-
Re: VB6 WebView2-Binding (Edge-Chromium)
While opening the application for the 1st time after starting computer, application crashes with below details in the event viewer. From 2nd time onwards, no issues at all on same computers. This happens for both installed EXE or running project from VB6 IDE. We have kept 30 seconds timeout for BindTo method (WV.BindTo(picWV.hWnd, 30)). Timeout doesn't seem to be the issue as application crashes immediately. All computers have Evergreeen WebView2-Runtime installed which is updated automatically as well as properly registered required RC6 related DLLs in single folder. This happens on multiple computers. We are opening both EXE as well as VB6 IDE with Run as Administrator, if that matters.
Faulting application name: VB6.EXE, version: 6.0.81.76, time stamp: 0x3592011f
Faulting module name: ntdll.dll, version: 10.0.19041.1566, time stamp: 0xbde09443
Exception code: 0xc0000374
Fault offset: 0x000e6d03
Faulting process id: 0xde4
Faulting application start time: 0x01d83e7836746466
Faulting application path: D:\Program Files (x86)\Microsoft Visual Studio\VB98\VB6.EXE
Faulting module path: C:\Windows\SYSTEM32\ntdll.dll
Report Id: 91d860ff-e220-4c76-b631-9b18f578ba09
Faulting package full name:
Faulting package-relative application ID:
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
BooksRUs
Ok, Newbie alert! :duck:
I know this will sound crazy, but I have never created my own control... but, I'm willing to give it a try.
To start, is this an ActiveX DLL, EXE, OCX?
A "Project-Private-UserControl" is "just another module" (in your normal Std-Exe-Project)
You add it in the same way as an additional Form (*.frm), Module (*.bas), Class (*.cls)...
via Context-Menu in your Project-Tree as a UserControl (ending up with a *.ctl -File in your ProjectTree when saving).
Quote:
Originally Posted by
BooksRUs
For the events that have parameters, do I have to declare the same parameters in the Event declaration...?
Yes - and since you have to "Re-Delegate them" anyways (see the last section of my Demo),
you will have to receive them first in the internal EventSink-Handler of the WV.
And once you have that EventHandler selected (via DropDown),
you can immediately copy its "Param Signature" as is - into the Event-Declaration at the Top of your little UC.
Re-Delegating 10 Events or so, should not take more than 5 minutes of "Copy&Paste-work".
Quote:
Originally Posted by
BooksRUs
Also, I was trying to add a "Busy" flag, as I didn't see how I can do this:
1. Navigate somewhere
2. wait until WV is actually there and complete
3. continue
Actually, you don't need to implement your own "Wait-Handling" for Navigation... since this is already built-in.
(please look at the optional TimeOut-Param in the Navigate-Methods).
HTH
Olaf
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
avinash7
While opening the application for the 1st time after starting computer, application crashes
Are you sure that this crash is caused by the WebView2?
What if you take a very simplified example (e.g. similar to the one w.wolff has posted in #148):
Code:
Option Explicit
Private WithEvents WV As cWebView2
Private Sub Form_Load()
Visible = True: Caption = "Now navigating to Google..."
Set WV = New_c.WebView2(Me.hWnd)
WV.Navigate "https://google.com"
End Sub
Private Sub Form_Resize()
If Not WV Is Nothing Then WV.SyncSizeToHostWindow
End Sub
Private Sub WV_DocumentComplete()
Caption = "Document complete"
End Sub
Put this into a virginal StdExe-Project(-Form) and compile.
Then re-start your machine and check the little Executable, how it behaves "at first Startup, shortly after booting the machine".
If that works, then the error is in all likelihood *not* caused by the WebView2-lib (or the wrapper).
Olaf
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
saturnian
I programmed an ocx encapsulating the RC6's Webview2 for my own purposes. It is available
here, for those interested.
It is a version which will evolve with the improvements of the RC6 and which is delivered as it is, without any guarantee. But in my software, it works perfectly. Thanks again to Olaf!
François
Thanks for this!! I have downloaded and I'm trying it out. My first problem is how to set it up to call the .JSrun with Parameters? I'm converting the code from using the WebView2 directly and it's complaining:
Type Mismatch: array or user-defined type expected
I have injected a small JS with 2 parameters (user and password), so that I can auto-login to a website.
Thanks!
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
Schmidt
Re-Delegating 10 Events or so, should not take more than 5 minutes of "Copy&Paste-work".
While this exercise seemed trivial enough, it appears that to provide a true "wrapper" around this with Indexes, I must re-create/declare *ALL* the other Let/Get and Methods for *each* of the properties/methods of the actual WV object.
I did try to do this, but the .jsProp was a little confusing, while most others were straightforward. I only tried to do the ones that I'm using to change your Demo program to work with 2 of my own ucWV objects (I dynamically Load a 2nd one, just to make sure that I can dynamically Load the object).
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
BooksRUs
Thanks for this!! I have downloaded and I'm trying it out. My first problem is how to set it up to call the .JSrun with Parameters? I'm converting the code from using the WebView2 directly and it's complaining:
Type Mismatch: array or user-defined type expected
I have injected a small JS with 2 parameters (user and password), so that I can auto-login to a website.
Have you tried : (where FLogin is the Javascript procedure)
Code:
Dim Param_Array(1) As Variant
Param_Array(0) = "MyUserID"
Param_Array(1) = "MyPassword"
OrdoWebView1.jsRun "FLogin", Param_Array()
-
Re: VB6 WebView2-Binding (Edge-Chromium)
I All,
I am not able to use the RC6 WebView2 from outside VB6. In VB6 (in the IDE and compiled) everything works correctly. The same if I use the "saturnian" control (an ocx encapsulating the RC6 WebView2). The problem is when I want to use the WebView2 from, for example, PowerBuilder. I've been using RC without problems in PB for a long time, but I can't get the WebView2 to work. When I call BindTo , the PB IDE crashes (the same in a compiled version) with the same error it gives to "avinash7" (error in ntdll.dll").
I have tested the AntView control (https://antview.dev/downloads/) which I believe uses the same mechanism (WebView2Loader.dll) and everything works correctly, both in VB6, PowerBuilder, even in an Excel userForm.
If I use the saturnian control in PowerBuilder, I get the error (just instantiate the control):
Attachment 184685
For what it's worth, in PowerBuilder's object browser, I can see all RC6 classes except "cWebView2":
Attachment 184686
However, the error does not occur when creating the cWebView2 object, but when calling BindTo (or when creating it by passing the hWnd parameter).
Any ideas?
Thanks!
-
Re: VB6 WebView2-Binding (Edge-Chromium)
@saturnian
Does your ActiveX control allow the setting of the userDataFolder ?
Can't seem to find it in VB6 Object Browser.
Thanks
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
carl039
@saturnian
Does your ActiveX control allow the setting of the userDataFolder ?
Can't seem to find it in VB6 Object Browser.
Thanks
For the moment no. But if you are using a Fixed Version of WebView2, the user directory data is in the installation folder of this version (by default: C:\ProgramData\OrdoWebView2\Microsoft.WebView2.FixedVersionRuntime\Data\EBWebView)
You can copy the contents of the C:\ProgramData\OrdoWebView2\Microsoft.WebView2.FixedVersionRuntime folder several times and assign a version of the webview2 control to each user by setting the EdgeFixedPath property.
But this cannot be changed on the fly. You must use one OrdoWebView2 control per user, modify the EdgeFixedPath property and launch the Init method.
Best regards
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
saturnian
For the moment no. But if you are using a Fixed Version of WebView2, the user directory data is in the installation folder of this version (by default: C:\ProgramData\OrdoWebView2\Microsoft.WebView2.FixedVersionRuntime\Data\EBWebView)
You can copy the contents of the C:\ProgramData\OrdoWebView2\Microsoft.WebView2.FixedVersionRuntime folder several times and assign a version of the webview2 control to each user by setting the EdgeFixedPath property.
But this cannot be changed on the fly. You must use one OrdoWebView2 control per user, modify the EdgeFixedPath property and launch the Init method.
Best regards
Thanks, great job on your control btw.
-
Re: VB6 WebView2-Binding (Edge-Chromium)
@Olaf
Is there any plans to include all properties as detailed here in particular:
IsPasswordAutosaveEnabled
IsGeneralAutofillEnabled
Thanks
-
Re: VB6 WebView2-Binding (Edge-Chromium)
just ran across this, it's exactly what i've been looking for, so thank you.
i have a question, hopefully someone can help.
i've figured out mostly everything i need, but i need help with 2 things.
1) outputting the entire html of the website into a textbox. i was able to use WV.jsProp("document.body.innerHTML") but it only captures part of the html, and i need the entire source of the page.
2) scan entire page for elements such as ID, NAME, HREF, and display them in a textbox. basically, with the webbrowser control i would do this:
For X = 0 To WebBrowser1.Document.All.Length
strID = WebBrowser1.Document.All.Item(X).Id
If Not strID = "" Then txtIDs.Text = txtIDs.Text & "(" & X & ") " & wB.Document.All.Item(X).Id & vbNewLine
Next X
so basically that just loops through every element on the page, checks if it has an ID, and if so it displays it in a textbox. then you can replace Id with name or href. i need to re-create that same thing here. does anyone know how to achieve this? thanks!
----
edit:
i figured out #1 i think. if anyone else is having the same issue, try using WV.jsProp("document.documentElement.outerHTML")
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
inspace
2) scan entire page for elements such as ID, NAME, HREF, and display them in a textbox.
With the WebView2 you should get more familiar with its JS-interface ...
(doing all of the more complex stuff, by adding js-Functions beforehand - and then calling these from VB)
For example, if you add the following js-function (via WV.AddScriptToExecuteOnDocumentCreated):
Code:
WV.AddScriptToExecuteOnDocumentCreated New_c.ArrayList(vbString, _
"function getByExpression_id_tag_val_name_href(sExpr){", _
" var resArr = []", _
" for (var e of document.querySelectorAll(sExpr).values()){", _
" resArr.push({id:e.id, tag:e.tagName, val:e.value, name:e.name, href:e.href})", _
" }", _
" return JSON.stringify(resArr)", _
"}").Join(vbLf)
You can then use this js-routine from VB (with a "Selector-Filter-Expression"-param) e.g. this way:
Debug.Print WV.jsRun("getByExpression_id_tag_val_name_href", "[id]:not([id=''])")
The blue marked Expression-String above, filters for:
- all Elements which contain the ID-attribute (the leading [id] -part)
- and of those with an id-attribute, ignore the ones which have an empty string in it (the not([id=''] -part)
These Selector-Expressions are extremely powerful - just google for examples...
HTH
Olaf
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Does anyone have an example of how to use NavigateWithWebResourceRequest with HTTP Basic Auth?
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Hi everyone
I just wanted to know is there any equivalent method in webview2 for the followings:
suppose mdocDocument is declared as an HTMLDocument
set mhtmInput1 = mdocDocument.createElement("Input")
mdocDocument.appendChild mhtmInput1
set mhtmCoords = mdocDocument.getElementById("coords")
mdocDocument.parentWindow.event
mdocDocument_onClick
mdocDocument.parentWindow.Blur
Thanks in advance
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
suppose mdocDocument is declared as an HTMLDocument
The HTMLDocument and the corresponding interface do not exist here. You have to program this code (a function) in JavaScript and either integrate it statically into the page or add it dynamically via VB. You can call the function from your programme at any time (also parameterised). See also: AddScriptToExecuteOnDocumentCreated, jsRun, jsRunAsync and ExecuteScript.
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Hi Olaf
The problem "Runtime Error 53: Error in FindFirstFile: ErrNum: 3, The system cannot find the path specified." persists.
I had to clean install my windows 10, registered RC6.dll and today installed WebView2. WebView version 103.0.1264.71 installed into the folder "C:\Program Files (x86)\Microsoft\EDGE\Application", your program looks for the "EdgeWebView" folder.
Solution? Should I rename this folder?
Regards
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Hi Olaf
Solutions sometimes can be quick: I did what I should have done before posting.
I copied the "Edge" folder and renamed the copy "EdgeWebView" - now my program runs smooth!
Regards
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Hi !
Thank you for this great tool !
I am looking for a way to change the WebView2 default User-Agent.
I know that I can send a request with NavigateWithWebResourceRequest and set the User-Agent via the headers but I need that all the resources of the page are loaded with the same User Agent. In .net the solution is to call this method :
var settings = new Web.CoreWebView2.Settings;
settings.UserAgent = "XXXXX";
Is there a way to do this ?
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
lodep
I need that all the resources of the page are loaded with the same User Agent...
There's a ton of settings possible via optional commandline-string (which you can pass along in the Bind-Method) -
"--user-agent ..." just being one of them...
https://peter.sh/experiments/chromiu...es/#user-agent
I'd try it this way first...
HTH
Olaf
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
Schmidt
How can I say... JUST A HUGE THANK YOU !!!
This is just amazing, it works !
Thank you :)
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Hi @Olaf,
One more question : I can't access the documenturl property sometimes (it's blank).
I've read in previous posts that you have a workaround for this problem and that you'll need to update the DLL.
Is it possible to access this property with a temp fix using JSPROP for example ?
Thanks,
-
Re: VB6 WebView2-Binding (Edge-Chromium)
can anybody share with me how to get webview2 cookies vb6
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
jenniger9
can anybody share with me how to get webview2 cookies vb6
Please study (or at least search through) the postings of the discussion-thread you're currently in...
Cookie-retrieval was already a topic here in: https://www.vbforums.com/showthread....=1#post5498591
Olaf
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Can this tool(webview2) replace selenium to emulate user behavior on the webpage?
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
sergeos
Can this tool(webview2) replace selenium to emulate user behavior on the webpage?
In my understanding, Selenium was written as a generic Test-Tool which can "work against multiple Browser-engines".
The WebView2 is just an encapsulation of a single Browser-engine (chromium) -
minus the additional "generic Automation- and Test-interfaces".
So, if you currently use Selenium for your own testing-purposes with success,
why change it to something "less capable" and "less generic".
Just my $0.02...
Olaf