Page 4 of 12 FirstFirst 1234567 ... LastLast
Results 121 to 160 of 480

Thread: VB6 WebView2-Binding (Edge-Chromium)

  1. #121
    New Member
    Join Date
    Feb 2022
    Posts
    7

    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

  2. #122

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by Bearfot View Post
    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 View Post
    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 View Post
    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

  3. #123
    New Member
    Join Date
    Feb 2022
    Posts
    7

    Re: VB6 WebView2-Binding (Edge-Chromium)

    @Olaf, thanks for reply!

    Quote Originally Posted by Schmidt View Post
    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

  4. #124

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by Bearfot View Post
    My earlier question was regarding basic authentication.
    Oops, my bad (interchanged your post with that from Andrew/EasyOneX)...

    Quote Originally Posted by Bearfot View Post
    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

  5. #125
    New Member
    Join Date
    Feb 2022
    Posts
    7

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Yes, passing usernameassword 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

  6. #126
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    673

    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?

  7. #127
    New Member
    Join Date
    Feb 2022
    Posts
    11

    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.

  8. #128
    New Member
    Join Date
    Feb 2022
    Posts
    7

    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

  9. #129
    New Member
    Join Date
    Feb 2022
    Posts
    7

    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
    Last edited by Bearfot; Feb 13th, 2022 at 01:30 PM. Reason: Syntax and spelling

  10. #130
    Lively Member saturnian's Avatar
    Join Date
    Dec 2017
    Location
    France
    Posts
    75

    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 !

  11. #131
    New Member
    Join Date
    Feb 2022
    Posts
    7

    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.

  12. #132
    New Member
    Join Date
    Feb 2022
    Posts
    11

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by saturnian View Post
    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!

  13. #133
    New Member
    Join Date
    Mar 2022
    Posts
    1

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by Schmidt View Post
    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.

  14. #134
    Hyperactive Member
    Join Date
    Dec 2008
    Location
    Argentina
    Posts
    439

    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?
    leandroascierto.com Visual Basic 6 projects

  15. #135
    Member
    Join Date
    Mar 2022
    Posts
    38

    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.

  16. #136
    Frenzied Member
    Join Date
    Aug 2020
    Posts
    1,421

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by BooksRUs View Post
    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

  17. #137
    Member
    Join Date
    Mar 2022
    Posts
    38

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by SearchingDataOnly View Post
    Maybe it's a question about the RC6 path.
    https://www.vbforums.com/showthread....=1#post5443031

    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!

  18. #138

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by BooksRUs View Post
    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

  19. #139
    Member
    Join Date
    Mar 2022
    Posts
    38

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by Schmidt View Post
    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.

  20. #140
    Lively Member
    Join Date
    Sep 2016
    Location
    Germany, Bavaria
    Posts
    75

    Re: VB6 WebView2-Binding (Edge-Chromium)

    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

  21. #141
    Member
    Join Date
    Mar 2022
    Posts
    38

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by wwolf View Post
    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
    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!

  22. #142

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by BooksRUs View Post
    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

  23. #143
    Member
    Join Date
    Mar 2022
    Posts
    38

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by Schmidt View Post
    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.


  24. #144
    Member
    Join Date
    Mar 2022
    Posts
    38

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by Schmidt View Post
    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!
    Last edited by BooksRUs; Mar 15th, 2022 at 09:00 AM.

  25. #145

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by BooksRUs View Post
    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

  26. #146
    Member
    Join Date
    Mar 2022
    Posts
    38

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by Schmidt View Post
    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?
    Last edited by BooksRUs; Mar 16th, 2022 at 08:11 PM.

  27. #147

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by BooksRUs View Post
    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 View Post
    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 View Post
    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

  28. #148
    Lively Member
    Join Date
    Sep 2016
    Location
    Germany, Bavaria
    Posts
    75

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by BooksRUs View Post

    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 View Post
    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 View Post
    3. How do I "click" a button that doesn't seem to have a name?
    https://stackoverflow.com/questions/...706236#2706236

  29. #149
    Member
    Join Date
    Mar 2022
    Posts
    38

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by BooksRUs View Post

    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!

  30. #150
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,412

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by BooksRUs View Post
    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:

    WebViewEventCollection.zip

    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.

  31. #151
    Member
    Join Date
    Mar 2022
    Posts
    38

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by jpbro View Post
    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:

    WebViewEventCollection.zip

    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!

  32. #152

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by BooksRUs View Post
    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
    Last edited by Schmidt; Mar 20th, 2022 at 12:27 PM.

  33. #153
    Member
    Join Date
    Mar 2022
    Posts
    38

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by Schmidt View Post
    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!

    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!
    Last edited by BooksRUs; Mar 21st, 2022 at 11:40 AM.

  34. #154
    Lively Member saturnian's Avatar
    Join Date
    Dec 2017
    Location
    France
    Posts
    75

    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
    Last edited by saturnian; Mar 24th, 2022 at 03:46 AM.

  35. #155
    New Member
    Join Date
    Feb 2022
    Posts
    11

    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:

  36. #156

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by BooksRUs View Post
    Ok, Newbie alert!

    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 View Post
    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 View Post
    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

  37. #157

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by avinash7 View Post
    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

  38. #158
    Member
    Join Date
    Mar 2022
    Posts
    38

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by saturnian View Post
    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!

  39. #159
    Member
    Join Date
    Mar 2022
    Posts
    38

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by Schmidt View Post

    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).

  40. #160
    Lively Member saturnian's Avatar
    Join Date
    Dec 2017
    Location
    France
    Posts
    75

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by BooksRUs View Post
    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()

Page 4 of 12 FirstFirst 1234567 ... LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width