Page 8 of 12 FirstFirst ... 567891011 ... LastLast
Results 281 to 320 of 480

Thread: VB6 WebView2-Binding (Edge-Chromium)

  1. #281
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,746

    Re: VB6 WebView2-Binding (Edge-Chromium)

    If have a such website, everybody can add modify complement perfect knowledge base together, write example code, like this convenient.

    Do you have a help file? If you can control OCX or COM DLL, Windows API as a database knowledge base, list all properties, methods, events, constant values, optional parameters, meaning. An example call for each method. Then automatically generated HTM format help file is very convenient, you need a tool like this. Rc6. CWEBVIEW2, there are 70 or so method properties, if you can make a complete example, including all the method calls is perfect, in the code marked: ' 1/AcceleratorKeyPressed/event' 2/AddObject/method' 3/AddScriptToExecuteOnDocumentCreated such a workload is undoubtedly very large, most people use only a small amount of functionality. If do a such general control knowledge base software, Windows API, SQLITE3.0. DLL, VBA Excel. Application and other uses of the knowledge base management, use should be very convenient.

    Name:  2241RC6.cWebView2谷歌内核浏览器控件&#30340.jpg
Views: 1498
Size:  73.9 KB
    Last edited by xiaoyao; Mar 6th, 2023 at 06:58 PM.

  2. #282
    Hyperactive Member
    Join Date
    Jul 2017
    Posts
    344

    Re: VB6 WebView2-Binding (Edge-Chromium)

    1)
    How would I do this in WebView2, please?
    cefSetting.CefCommandLineArgs.Add("autoplay-policy", "no-user-gesture-required");

    2)
    How could I disable opening new windows?

    3)
    How could I disable that users can right-click the browser to invoke for example "Save as...", "Inspect", etc.?

  3. #283
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,412

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by tmighty2 View Post
    3)
    How could I disable that users can right-click the browser to invoke for example "Save as...", "Inspect", etc.?
    Does setting the WebView2 AreDefaultContextMenusEnabled property to False prevent the menu from appearing?

  4. #284
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,412

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by tmighty2 View Post
    2)
    How could I disable opening new windows?
    Does this work?

    Code:
    Private  Sub WV_NewWindowRequested(ByVal IsUserInitiated As Boolean, IsHandled  As Boolean, ByVal URI As String, NewWindowFeatures As RC6.cCollection)
      IsHandled = True '<- suppress the Browser-Controls default-handler
    End Sub
    See this post: https://www.vbforums.com/showthread....=1#post5597387

  5. #285

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by tmighty2 View Post
    1) How would I do this in WebView2, please?
    cefSetting.CefCommandLineArgs.Add("autoplay-policy", "no-user-gesture-required");
    Chromium CommandLine-switches can be passed in one of the optional Arguments of the "Bind-call"...
    (and were discussed more than once in this threads history)...
    WV.BindTo(hWnd, , , ,"--autoplay-policy=no-user-gesture-required")

    Here's the Link again, which describes them:
    https://peter.sh/experiments/chromiu...utoplay-policy

    Olaf

  6. #286
    Addicted Member
    Join Date
    Apr 2017
    Location
    India
    Posts
    234

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by Schmidt View Post
    Chromium CommandLine-switches can be passed in one of the optional Arguments of the "Bind-call"...
    (and were discussed more than once in this threads history)...
    WV.BindTo(hWnd, , , ,"--autoplay-policy=no-user-gesture-required")

    Here's the Link again, which describes them:
    https://peter.sh/experiments/chromiu...utoplay-policy

    Olaf
    // and were discussed more than once in this thread's history //
    Yes indeed, My Dear Olaf. And using this particular tip led me to have moments of great joy once I discovered that Spell-Checker (for languages other than the default English) can also be invoked via the Bind-Call. I had to try for quite some time to get it right (I almost decided to write here and ask you) but eventually when I got it working, that was such a joy (Word suggestions for misspelt words are also shown!!!). The joy you are giving to so many (few known to you, millions unknown to you) in this world society must be getting registered constantly in the Divine books, I firmly believe. May be it is possible to invoke the translator too! I am yet to explore. If possible and if you know the argument(s) for the same already, kindly let me know. Thanks in advance.

    Well, coming to the Bind-Call (e.g. "--accept-lang=en-US,en,fr" wherein I have included 'fr' also to be considered for spellchecking), I wish to know the following:

    1. For the spellchecker/word-suggestions to function (for any included language), does MS always send the words typed to its servers, to get the required results? Or, is it always done locally after downloading the required language dictionaries once (perhaps updated occasionally too) to user's system? How "exactly" is this spell-checker/word-suggestions functionality effected by MS in WebView2? Will be helpful to share this info with users if such info is "concretely" known.

    2. Is it possible to access the word suggestions programmatically and show it in my own separate list?. For instance, when I typed "SpellChecker", the spellchecker engine identifies it as misspelt and when I right click on it, the resultant context menu is as in the picture below. Is it possible for me to programmatically access these three word suggestions (Spellchecker, Spellcheckers, Spell-checker) and show them alone in my own list on right-clicking (OR any other way, so that the default right-click menu gets displayed as usual)?


    Name:  SpellChecker.png
Views: 1323
Size:  4.2 KB

    3. I noticed that if I use more than one reference (say WV and WV2) to cWebView2 in my program, then while binding, I needed to "exactly" give the same "--accept-lang" argument in both Bindings. i.e. it had to be as follows:
    --
    If WV.BindTo(picWV.hWnd, TIME_TO_WAIT_m, , , "--accept-lang=en-US,en,fr") = 0
    If WV2.BindTo(picWV2.hWnd, TIME_TO_WAIT_m, , , "--accept-lang=en-US,en,fr") = 0
    --
    Otherwise, the 2nd binding won't happen. I have no problems keeping the same argument in both bind calls, but I feel that perhaps I am doing a mistake and there possibly is a way by which I can pass different "--accept-lang" argument in each of the WV bind calls. May be the correct argument is different from "--accept-lang" itself for SpellChecker?

    I searched in this thread right now in each of it's pages and did not find the above matters (with respect to "accept-lang") discussed directly, except one indirect reference to "accept-lang" in the 5th page [xhr.setRequestHeader('Accept-Language', 'en-US,en;q=0.9';]. Hence, I decided to go ahead writing&asking about the above matters via this post. Sure I have done the right thing. In case all of the above have been already discussed (in this thread or elsewhere), then sorry about it. Kindly point me to those messages (here or elsewhere), Olaf. Thank you once again, Olaf, from the bottom of my heart. God Bless you! God Bless ALL!

    Kind Regards.

    Edited:
    - just corrected "picWV" to "picWV2" in the "WV2.BindTo" line.
    - just a while ago noticed that the picture I inserted is missing. Have inserted it again.
    Last edited by softv; Mar 17th, 2023 at 06:56 AM.

  7. #287
    Hyperactive Member
    Join Date
    Jul 2017
    Posts
    344

    Re: VB6 WebView2-Binding (Edge-Chromium)

    I would like to access certain elements of a webpage like links, buttons, etc.
    I want to use JavaScript to do that.
    I have uploaded my script here: https://drive.google.com/file/d/1nfC...usp=share_link

    First, I need to call grid_ensureHotSpotIds to create these elements.
    I know that this question is relatively specific to JS, but can anybody tell me anyways how I would then access these hotspots from VB6?

  8. #288

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by tmighty2 View Post
    ...I need to call grid_ensureHotSpotIds to create these elements.
    From what's defined in your js-code, I only see 3 Functions, defined on the (global) window-object:
    window._grid_ensureHotSpotIds
    window._grid_getHotSpots
    window._grid_getFocusedElementHotSpots

    Note the leading underscore of these 3 functions (which you'd have to specify in the function-name-arg of WV.jsRun )

    Here's an example:
    Code:
    Option Explicit
    
    Private WithEvents WV As cWebView2
    
    Private Sub Form_Load()
      Me.Visible = True 'ensure Visibility before the Bind-call
      
      Set WV = New_c.WebView2(Me.hWnd)
          WV.AddScriptToExecuteOnDocumentCreated "window._foo = function(){alert('bar')}"
          WV.NavigateToString "<p>dummy-content, nothing to see here...</p>" 'ensure simple "document-content"
      
      WV.jsRun "window._foo" 'should show an alert('bar')-popup
      WV.jsRun "_foo" '... should show the same (the preceding window. is optional)
    End Sub
    Quote Originally Posted by tmighty2 View Post
    ...how I would then access these hotspots from VB6?
    Just call the functions directly via WV.jsRun (if they are directly callable, due to definition on the Window-Object)...
    Or add little wrapper-functions via WV.AddScriptToExec... (to indirectly call stuff which is deeper hidden behind other objects)

    In either case, please return either "simple types" from these functions (Strings, or Numbers, or Booleans or Nulls) -
    or (in case you want to return js-Arrays or js-Objects) return them this way:
    return JSON.stringify(MyArray_Or_MyObject)

    A function which returns such stringified JSON, can be called this way from VB (auto-decoding the JSON-string already):
    Dim JSON as cCollection
    Set JSON = New_c.JSONDecodeToCollection( WV.jsRun("myfunc", P1, P2) )

    HTH

    Olaf

  9. #289
    Addicted Member
    Join Date
    Apr 2017
    Location
    India
    Posts
    234

    Re: VB6 WebView2-Binding (Edge-Chromium)

    The following global EventListener on the document works perfectly for the target element 'abc'.

    Code:
    With New_c.StringBuilder
        .Add "document.addEventListener('change', function(e) {"
        .Add "  e = e||window.event;"
        .Add "  if (e.target.id == 'abc') {"
        .Add "    vbH().RaiseMessageEvent('abcChange', e.target.value)"
        .Add "  };"
        .Add "}, false);"
        WV.AddScriptToExecuteOnDocumentCreated .ToString
    End With
    But, the same EventListener when applied specifically to the target element 'abc' (as follows) does not work (i.e. the 'abcChange' event is not raised).
    Code:
    WV.AddScriptToExecuteOnDocumentCreated "var abc = document.getElementById('abc'); abc.addEventListener('change', function(event) {vbH().RaiseMessageEvent('abcChange', abc.value);},false);"
    I think the 'abc' element is not yet loaded when the above script is added. Am I right?

    Of course the above line (modified suitably as follows) and included in the <script> section of the html file works perfectly.
    Code:
    var abc = document.getElementById('abc'); abc.addEventListener('change', function(event) {alert (abc.value + ' eureka');},false);
    So, to make the above line work through my application itself, I added the following line in the "WV_DocumentComplete" event and it works but it takes effect after the 2nd 'change' event onwards only. First time when there is change in the 'abc' element, the 'abcChange' event is not raised.
    Code:
    WV.ExecuteScript "var abc = document.getElementById('abc'); abc.addEventListener('change', function(event) {vbH().RaiseMessageEvent('abcChange', abc.value);},false);"
    So, what is the right way to proceed if I need to add an EventListener to a specific target element alone? Can somebody kindly educate and help me out? Please.

    Kind regards.

  10. #290
    Addicted Member
    Join Date
    Apr 2017
    Location
    India
    Posts
    234

    Re: VB6 WebView2-Binding (Edge-Chromium)

    In order that the scripts added to a WV (via functions like AddScriptToExecuteOnDocumentCreated, etc.) for the 1st page I load (e.g. God.html) do not get effected in a 2nd and different page (e.g. Compassion.html) loaded in the same WV, I am right now loading the 2nd page in the manner below. Is that correct? If not, what is the correct method?

    Code:
    If WV.BindTo(picWV.hWnd) <> 0 Then
       WV.Navigate App.Path & "\Cosmos\" & "Compassion.html"
    End If
    If I load the 2nd page straightaway using just the following line of code alone, then the scripts added to the 1st page get effected in the 2nd page also if I have elements in the 2nd page with the same 'id's (or classes) as in the 1st page.
    Code:
    WV.Navigate App.Path & "\Cosmos\" & "Compassion.html"
    Note: I looked for any 'RemoveScript' methods so that by executing them I can remove the scripts already added to a WV so that I can use the abovementioned line of code alone directly. But, I could not find any. I am yet to get time to explore as to what RemoveObject method does.

    God Bless you, olaf! God Bless ALL!

    Kind regards.

  11. #291

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: VB6 WebView2-Binding (Edge-Chromium)

    So, what is the right way to proceed if I need to add an EventListener to a specific target element alone?
    Why not use the global Listener, when it works nicely already?

    I'd make it even more generic, so that it works for any Widget which raises a change-event:
    (this way you can filter on the VB-side)...
    Code:
    Option Explicit
    
    Private WithEvents WV As cWebView2
    
    Private Sub Form_Load()
      Me.Visible = True 'ensure Visibility before the Bind-call
      
      Set WV = New_c.WebView2(Me.hWnd)
      
      With New_c.StringBuilder
          .AddNL "document.addEventListener('change', (e)=>{"
          .AddNL "    vbH().RaiseMessageEvent(e.target.id+'_change', e.target.value)"
          .AddNL "})"
          WV.AddScriptToExecuteOnDocumentCreated .ToString
      End With
      
      WV.NavigateToString "<input id='abc' type='text'><br><br><textarea id='xyz'>"
    End Sub
     
    Private Sub WV_JSMessage(ByVal sMsg As String, ByVal sMsgContent As String, oJSONContent As RC6.cCollection)
      Select Case LCase$(sMsg)
        Case "abc_change": Debug.Print "abc was changed to:"; sMsgContent
        Case "xyz_change": Debug.Print "xyz was changed to:"; sMsgContent
      End Select
    End Sub
    Olaf

  12. #292
    Addicted Member
    Join Date
    Apr 2017
    Location
    India
    Posts
    234

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by Schmidt View Post
    Why not use the global Listener, when it works nicely already?

    I'd make it even more generic, so that it works for any Widget which raises a change-event:
    (this way you can filter on the VB-side)...
    ... .. . ... .. .
    Olaf
    // Why not use the global Listener, when it works nicely already? //
    Yes, I definitely shall, olaf. I needed such a confirmation from you. Because, otherwise, I was somewhat concerned whether listening to events at the document level would increase the load on the 'events manager'. Now that you have given your assured go-ahead with a beautiful tip of a generic method itself, I am confident now that I need not have any concerns as aforesaid. Thanks a TON, as always.


    Kind regards.

  13. #293
    Hyperactive Member
    Join Date
    Jul 2017
    Posts
    344

    Re: VB6 WebView2-Binding (Edge-Chromium)

    I think my question was misleading. I would like to ask how I could then interact with the hotspots that I assigned.
    Does your framework perhaps offer a built-in method to iterate over them? I am not yet sure how I should access them, for example to get all the links in a webpage or to assign a different color to a hotspot area.

  14. #294
    Addicted Member
    Join Date
    Apr 2017
    Location
    India
    Posts
    234

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by softv View Post
    // and were discussed more than once in this thread's history //
    ... .. .
    Well, coming to the Bind-Call (e.g. "--accept-lang=en-US,en,fr" wherein I have included 'fr' also to be considered for spellchecking), I wish to know the following:

    1. For the spellchecker/word-suggestions to function (for any included language), does MS always send the words typed to its servers, to get the required results? Or, is it always done locally after downloading the required language dictionaries once (perhaps updated occasionally too) to user's system? How "exactly" is this spell-checker/word-suggestions functionality effected by MS in WebView2? Will be helpful to share this info with users if such info is "concretely" known.

    2. Is it possible to access the word suggestions programmatically and show it in my own separate list?. For instance, when I typed "SpellChecker", the spellchecker engine identifies it as misspelt and when I right click on it, the resultant context menu is as in the picture below. Is it possible for me to programmatically access these three word suggestions (Spellchecker, Spellcheckers, Spell-checker) and show them alone in my own list on right-clicking (OR any other way, so that the default right-click menu gets displayed as usual)?


    Name:  SpellChecker.png
Views: 1323
Size:  4.2 KB

    3. I noticed that if I use more than one reference (say WV and WV2) to cWebView2 in my program, then while binding, I needed to "exactly" give the same "--accept-lang" argument in both Bindings. i.e. it had to be as follows:
    --
    If WV.BindTo(picWV.hWnd, TIME_TO_WAIT_m, , , "--accept-lang=en-US,en,fr") = 0
    If WV2.BindTo(picWV2.hWnd, TIME_TO_WAIT_m, , , "--accept-lang=en-US,en,fr") = 0
    --
    Otherwise, the 2nd binding won't happen. I have no problems keeping the same argument in both bind calls, but I feel that perhaps I am doing a mistake and there possibly is a way by which I can pass different "--accept-lang" argument in each of the WV bind calls. May be the correct argument is different from "--accept-lang" itself for SpellChecker?
    ... .. .

    Kind Regards.
    With respect to my above post, Since Olaf may not be finding time always, can somebody else (dear JpBro, dear Wwolf, ..., .., .), if at all their time and situation permits, kindly help me out providing answers to my above 3 questions.

    There is also a sub-question in my 3rd question above. Let me pose it as a separate question hereunder so that it is easier for anyone to answer.
    --
    I have used "--accept-lang=en-US,en,fr" in the 'BindTo' call to enable and make use of the SpellChecker/WordSuggestions facility of Edge-WebView2 for languages other than the default English. Is that enough? Is that exactly the right way? If so, has anybody found time to use it extensively? And, if so, is the Spellchecking/WordSuggestions facility working well under all situations?
    --

    Sorry that I have not found time yet to explore the Spellchecking/WordSuggestions facility extensively, myself. Also, first I need to get confirmed from Olaf or others that "--accept-lang=en-US,en,fr" is enough and its the right way to enable and make use of the Spellchecking/WordSuggestions facility.

    Thanks in advance.

    Kind Regards.
    Last edited by softv; Mar 22nd, 2023 at 12:15 AM.

  15. #295

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by softv View Post
    ...kindly help me out providing answers to my above 3 questions.
    ...as for 1)
    MS-WebView2 is still "just a relatively thin wrapper" around the chromium -opensource-project (mainly managed by google) - and therefore all the main-functionalities (as e.g. spellchecking and its context-menus) are in all likelihood "chromium-implementations".

    There might be an exception here, regarding the necessary dictionaries (compared to chromium-CEF-binaries on e.g. Linux).
    I'm not sure whether MS is redirecting to the "local OS-dictionaries, which come with the Win-language-packs" -
    this might be the case, to keep the "Edge-Evergreen-package" relatively small... though I'm not sure about that...

    "Constant online-access" (to do word-lookups) does not seem to happen in my tests...
    (have temporarily disabled any Inet-connections here - and get proper spell-suggestions for "de" and "en" nevertheless.

    ...as for 2)
    There's currently no "context-menu-parsing" exposed in the RC6.cWebView2-class -
    (although interfaces for that exist in the MS-typelib).

    There's also no way, to retrieve the contextmenu-contents at "js-level".

    What is supported currently is, to entirely suppress any context-menu-popups (AreContextmenusEnabled) -
    and then show your own, by using the appropriate ContextMenu-EventHandler (according to the transported x/y-pos).

    ...as for 3)
    Was astonished by that myself (that the commandline-args have to remain constant for a Process-session) -
    but have not tried to find a reason or a workaround, because I can live with the behaviour...
    Perhaps changing the "UserDataFolder" in the Bind-call for the second instance could help, but haven't tested that either.

    Generally, the browser-internal spellchecking functionality is not well-exposed
    (only very few things can be influenced via javascript),
    and that's the reason why there's such an amount of js-libs which address this
    (usually in conjunction with some <textarea>bindings).

    It's up to you to use some of these libs (or the "big-guns" like CKEditor or TinyMCE, which come with their own spellcheckers as well).

    Olaf
    Last edited by Schmidt; Mar 22nd, 2023 at 02:20 AM.

  16. #296

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by tmighty2 View Post
    I would like to ask how I could then interact with the hotspots that I assigned.
    Does your framework perhaps offer a built-in method to iterate over them?
    Why not iterate over them from the inside of a little js-function?
    You can pass String-Parameters into such functions just fine from the VB-Side...
    (like e.g. QuerySelector-StringPatterns, or just "plain IDs", along with e.g. Color-Strings).

    In short, complex DOM-operations remain "in generic, clever parametrized js-helpers" -
    and then these "nice trigger-parameters" could (should) be passed from the VB-side.

    Olaf

  17. #297
    Addicted Member
    Join Date
    Apr 2017
    Location
    India
    Posts
    234

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by Schmidt View Post
    ...as for 1)
    MS-WebView2 is still "just a relatively thin wrapper" around the chromium -opensource-project (mainly managed by google) - and therefore all the main-functionalities (as e.g. spellchecking and its context-menus) are in all likelihood "chromium-implementations".

    There might be an exception here, regarding the necessary dictionaries (compared to chromium-CEF-binaries on e.g. Linux).
    I'm not sure whether MS is redirecting to the "local OS-dictionaries, which come with the Win-language-packs" -
    this might be the case, to keep the "Edge-Evergreen-package" relatively small... though I'm not sure about that...

    "Constant online-access" (to do word-lookups) does not seem to happen in my tests...
    (have temporarily disabled any Inet-connections here - and get proper spell-suggestions for "de" and "en" nevertheless.

    ...as for 2)
    There's currently no "context-menu-parsing" exposed in the RC6.cWebView2-class -
    (although interfaces for that exist in the MS-typelib).

    There's also no way, to retrieve the contextmenu-contents at "js-level".

    What is supported currently is, to entirely suppress any context-menu-popups (AreContextmenusEnabled) -
    and then show your own, by using the appropriate ContextMenu-EventHandler (according to the transported x/y-pos).

    ...as for 3)
    Was astonished by that myself (that the commandline-args have to remain constant for a Process-session) -
    but have not tried to find a reason or a workaround, because I can live with the behaviour...
    Perhaps changing the "UserDataFolder" in the Bind-call for the second instance could help, but haven't tested that either.

    Generally, the browser-internal spellchecking functionality is not well-exposed
    (only very few things can be influenced via javascript),
    and that's the reason why there's such an amount of js-libs which address this
    (usually in conjunction with some <textarea>bindings).

    It's up to you to use some of these libs (or the "big-guns" like CKEditor or TinyMCE, which come with their own spellcheckers as well).

    Olaf
    Thanks a TON, as always, dear Olaf.


    And, before anything else, I just presume from your detailed answers that "--accept-lang" is indeed the right way, as of now, to add SPWS (short for SpellChecker/WordSuggestions) facility via WebView2 in our own applications and that is enough too (though SPWS via "--accept-lang" does not seem to work for some languages; please see details in my "observations" below). So, I can very much go ahead using "--accept-lang" in my applications to enable and make use of SPWS (for whatever languages it works for now). Right? Kindly confirm.


    Well, I took time to explore more on this SPWS (short for SpellChecker/WordSuggestions) facility since the past 5 hours or so. And, noted down the following observations. As I was doing that, when I checked in between, I saw your answers to my 3 questions, that too in such great detail. Thanks a TONNNN, again, dear Olaf. Well, a few(not all) portions of my following observations may have been already responded to by you in your recent answers but if I start rephrasing my following observations, it may turn out to be a difficult/confusing process for me since already I have spent quite some time phrasing and rephrasing them in an understandable manner. So, I am sharing my observations just as I originally started noting them down itself and not modifying them based on your recent answers. Kindly bear with me for the same. Thanks in advance for your understanding in this regard.


    My observations:
    --
    1. When using "--accept-lang" to enable and use SPWS, some languages work and others don't. For instance, "fr,de,es,ta,hi,ml,te" work but NOT "ar,sa,kn,mr,gu,pa,as,bn". To confirm that all the language codes I am specifying are correct only, I referred to this page - https://www.biswajeetsamal.com/blog/...fication-codes. It came first on google search for "browser language codes" and I just used it. That's all.


    2. As an example for the abovementioned observation, if "--accept-lang=ar-AE,es,kn,en-US,en,fr-FR,de,as,bn" is specified in the BindTo call, the "Check spelling" context menu shows "Spanish, English (United States), English, French (France), German)" alone. i.e. only "es, en-US, en, fr-FR, de" are considered for spell-checking. "ar,kn,as,bn" are not considered. Please see screenshot at the end of this message (I opted to place the screenshot at the end so that the flow of this long message is not disturbed while reading).


    3. I just tried providing a list of non-working languages alone to "-accept-lang". That did not work. I tried placing the non-working languages in a different order in the list, just in case. That did not help either.


    4. For some sets of languages specified, I noticed that if a language which does NOT work is found in the list, even a language for which SPWS works is not shown in the "Check spelling" context menu.
    For example, if "--accept-lang=en,fr,ta,hi,te,ml,mr" is specified in the BindTo call, the "Check spelling" context menu shows "English, French, Tamil, Hindi" (en,fr,ta,hi) alone. "te,ml" are not shown. This is because of the 'mr'(Marathi) after 'ml'(Malayalam). In other words, if 'mr' is omitted and if "--accept-lang=en,fr,ta,hi,te,ml" is specified in the BindTo call, the "Check spelling" context menu does show all of "English, French, Tamil, Hindi, Telugu, Malayalam".


    5. In my Microsoft Edge browser (updated to the latest - 111.0.1661.51), under 'Settings->Languages->User writing assistance', it shows two modes of SPWS - 'Microsoft Editor' mode and 'Basic' mode. It is mentioned therein that if the former is used, "enhanced" SPWS is done by MS and the typed words are sent to MS for processing. If the latter is used, typed words are processed locally. What mode possibly WebView2 could be using?


    6. Since the SPWS seem to work when the internet is OFF also, only the 'Basic' mode is used by WebView2? If so and if 'Microsoft Editor' mode has to be used for "enhanced" SPWS, what should be done (if at all it can be done with the current WebView2 itself)? I just checked the SPWS with a limited set of words only for a few languages both with internet ON and OFF. Need to check with 5 to 6 sets of BIG chunk of words for the same few languages at some later point of time, to see whether the same misspelt words are shown underlined both when internet is ON and OFF.


    7. For some languages, MS Edge itself says that SPWS is not yet supported. For e.g. for "Bangla(India)".


    8. I noticed that sa(Sanskrit) was not found in the original list (of languages provided by MS Edge to add for SPWS) itself.


    9. https://github.com/nwjs/nw.js/issues/4954 - in this page, this comment (https://github.com/nwjs/nw.js/issues...ment-607348899) suggests a summary of 3 very simple things to do to add SPWS facility via package.json and Javascript. This thread was in 2017 though. So, I don't know whether the same is applicable via JavaScript to WebView2 too. If it is applicable and if it can serve as an additional way (apart from "--accept-lang") to enable and use SPWS for different languages, then, when your time permits, kindly elucidate more on the same, because I am not familiar with package.json, etc. May be SPWS for the currently non-working languages (ar,kn,gu,pa,etc.) will work through the aforementioned JS way?


    10. Even if I remove all the languages added through my MS Edge, I was still able to add SPWS facility via WebView2 in my application. So, MS language settings do not seem to have any connection with the language settings added via BindTo call in my application. Only thing is that WebView2 does not seem to support SPWS for all languages, for whatever reasons. Or perhaps I am doing some mistake. If I am doing some mistake, then, kindly point out the same so that I am able to enable and use SPWS facility for the currently non-working languages (ar, kn, gu, pa, etc.) too via "--accept-lang".


    11. Thanks for your helpful suggestion on js-libs for SPWS. Actually, I also noticed (just today, during my above exploration) that some js libs are available for spellchecking. I did not explore what they are though. If they are of MIT License supporting many languages, that would be great. Otherwise, for the kind of freeware-only work I do, whatever languages currently supported by WebView2 are itself such an "extremely exciting" thing. Really. Thanks for your suggestions, once again.
    --


    All said and done, as requested at the start of this message, kindly confirm, dear Olaf, that I can very well go ahead using "--accept-lang" in my applications to enable and make use of SPWS (for whatever languages it works for now).


    Once again, TONs of Thanks from the bottom of my heart for such prompt and detailed replies to each and every doubt of each and every user of RC6 in various threads related to RC6. And, those invaluable tips and cute compact code snippets now and then, to help us along with. God Bless you, dear Olaf. God Bless All.


    Kindest Regards.

    Screenshot (for point no.2 above):
    Name:  SpellChecker-2.png
Views: 1014
Size:  7.9 KB

  18. #298
    Hyperactive Member
    Join Date
    Jul 2017
    Posts
    344

    Re: VB6 WebView2-Binding (Edge-Chromium)

    I make a software for handicapped people.
    I need to get the links and clickable button elements of a webpage in order to show them on extra big buttons in my software.
    Instead of clicking in the website, handicapped users can press the big buttons in my software.
    At a first click on a button, the element in the webpage will be highlighted with a red outline, and its text will be spoken by a computer voice.
    At a 2nd click on the button in my application, the link of them element will be navigated to.

    That is why I need to be able to iterate through these elements from outside.

    For example, when the user presses button #2, I need to highlight hotspot #2 in the webpage.

    Can you tell me what you mean by "complex DOM-operations remain "in generic, clever parametrized js-helpers"?
    If possible, could you show me how to iterate over these hotspots from within VB6 using JS?

    I don't know how I could get back an array of hotspots from the browser by calling the JS function. I hope I could explain it well.
    Last edited by tmighty2; Mar 22nd, 2023 at 08:06 AM.

  19. #299
    Addicted Member
    Join Date
    Apr 2017
    Location
    India
    Posts
    234

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Note: This is a follow-up message to my post No. 297 ("11-point observations" message).

    First thing first, Olaf. SPWS works for all the languages with "--accept-lang" argument.

    What happened was that after a while after sending my "11-point observations" message to you, it occurred in my mind that I was all the while concentrating on adding languages to MS Edge rather than checking the Language packs installed in my system. At that point of time, your wise statement (I'm not sure whether MS is redirecting to the "local OS-dictionaries, which come with the Win-language-packs") also came to my mind simultaneously.

    So, I checked the language packs installed and found out that language packs for only a few languages (out of the many languages I was checking out) were installed in my Win10 system. So, I started installing the missing language packs but for whatever reasons, none of the language packs got installed, however many times I tried. That is when it occurred to me that I can easily check out the compiled exe in one of my other Win10 systems which I use only now and then (but keep its OS upto-date with the latest OS updates whenever I use it).

    So, I switched on my other system and checked out the compiled exe. And, all languages worked straightaway! . I checked the language packs installed in my other system and all the required language packs had been installed in it. So, as of now, SPWS works for all the languages with "--accept-lang" argument. The thing is that, as guessed by you very correctly (as it is so usually ), the language packs for all the languages for which SPWS is needed should be installed priorly in the system. Thanks a TON ton ton, my dear Olaf.

    Well, in the complied exe I had "--accept-lang=ta,hi,sa,te,kn,ml,mr,kok,gu,bn,pa,or,as,ar,es,en-US,en,fr-FR,de" and all of them (19 languages) showed up in the "Check spelling" context menu.

    One more thing. In my eagerness to check out the working of SPWS in my other system, I forgot the fact that I was checking out the compiled exe in one other system (in which RC6 is not installed/registered) for the very first time. So, when the starting screen of the compiled exe appeared, only after a second I realised that the compiled exe started "registration-free". Hats off to you, Olaf. This is the first time I am running a "compiled exe with DLL dependencies" and yet seeing it opening without me having to register the DLLs myself. Your DirectCOM.dll does it automatically. I did use your "modRCRegFree.bas" drop-in in my application, just exactly as you had suggested. . Thanks once again.

    All said and done, as requested in my earlier post (11-point message), when possible, kindly give your confirmation that I can very well go ahead using the "--accept-lang" approach in my applications to enable and make use of SPWS and no issues are foreseen in this approach/method. Thanks in advance. Any helpful/useful/important tips that you wish to give me when I go forward using this "--accept-lang" approach for SPWS, kindly let me know please. Looking forward to the same too. God Bless you, olaf. God Bless ALL.

    Kind Regards.

  20. #300
    Addicted Member
    Join Date
    Apr 2017
    Location
    India
    Posts
    234

    Re: VB6 WebView2-Binding (Edge-Chromium)

    By the way, Olaf, thanks (as usual) A TONNNN for your most wonderful tip on VSCODE editor (in post no. 277).

    What a gem this little cute editor is! I was thinking that VSCODE would be yet another bulky IDE (like Visual Studio) where I would be taking several days to learn (and also remember) the IDE's various menus/options/features itself. But it was not at all so! It was such a pleasant surprise and joy to see VSCODE being so light-weight (yet features-packed!). I never knew that such a tailor-made cute little app can exist for html5/css/js coding. It has all the features (and more ) one would expect in an html/css/js editor. Simply Fantastic. Happy that I got to see this helpful tip of yours early. Your superb tip has saved me so many hours thereafter and increased my productivity a lot. You are so special for our VBForums. Thanks once again. .

    Kindest Regards.

  21. #301
    Addicted Member
    Join Date
    Apr 2017
    Location
    India
    Posts
    234

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Dear Olaf,


    Code:
    WV.AddSCriptToExecuteOnDocumentCreated New_c.FSO.ReadTextContent("MyHelpers.js", False, CP_UTF8)
    With reference to your above one line of code in post no. 277, I have the following query.
    --
    When trying to add a .js file (say 'simple.js') in the above manner, I found that it was working only if there are no jQuery calls in my 'simple.js' file. It took me some considerable amount of time to find out that jQuery calls were the problem. Am I doing a mistake? Or, is it that I indeed cannot use jQuery calls in the js strings added via WV.AddSCriptToExecuteOnDocumentCreated? If I can use jquery, then how to achieve that? I do have proper references to jquery.js in my 'simple.html' file. 'Simple.html' does work correctly if I include 'simple.js' directly in it and I "WV.Navigate" to 'simple.html' directly in my VB application.
    --


    Note: I did take time to search each of the pages in this thread for 'jQuery'. But, I could not find any post discussing about it. I thought may be it is written in some post by dear Olaf that only 'Pure JS' can be used. So, right now I searched on "Pure JS" in this thread but could not find any post mentioning the same. Well, may be it is mentioned in a different way by dear Olaf. I don't know.


    In the above context, I will be truly grateful if someone can let me know what is the best way to find out whether a particular matter has been already discussed in this thread (in this thread "alone"). At present, I am clicking each numbered page link at the top of this thread and searching on a particular term (say 'jQuery'). Is there a faster way of searching so that if I search on 'jQuery', I immediately get to see all the pages (in this thread alone) in which it appears or 'no results' if it is not present in any of the pages (in this thread). That will help me a lot. Really. I did try the 'Advanced search but it does not seem to zero-in on the specific post(s). For e.g. for a 'Keyword:' of FSO.ReadTextContent and 'User Name:' of Schmidt, the results do not show me the exact post (277) in which the Keyword has been used. May be I am searching wrongly, I don't know. Sometimes, I do miss the obvious and focus elsewhere. Probably that is the case here also. So, kindly help me out.

    I take this opportunity to thank you once again, Olaf, for helping us all out, to the best extent you can, always, even amidst your hectic schedules. I personally know how arduous it is (to give such help, regularly) but at the same time how joyful it is too (ultimately) since it results in immense benefit to the world society. God Bless you. God Bless ALL.


    Kind Regards.

  22. #302

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by softv View Post
    ...When trying to add a .js file (say 'simple.js') in the above manner,
    I found that it was working only if there are no jQuery calls in my 'simple.js' file.
    With the now available browser-built-in selector-functions, there's rarely a need for jQuery anymore...

    That said - jQuery is an external js-lib - and therefore needs to be (pre)loaded as well -
    ideally before you add your own js-scripts.

    You can ensure that either in the HTML (via the usual <script>-tags) -
    or use AddScriptOnDocumentCreate as well for jQuery...

    Below is some Demo-Code:
    (which downloads jQuery dynamically "as String" via a http51-helperfunction - but once downloaded via wgetJQ(),
    you can of course put the retrieved string into your own local js-file - and load it from there in future-runs)...

    Code:
    Option Explicit
     
    Private WithEvents WV As cWebView2
     
    Private Sub Form_Load()
      Me.Visible = True
     
      Set WV = New_c.WebView2(hWnd)
          WV.AddScriptToExecuteOnDocumentCreated wgetJQ("https://code.jquery.com/jquery-3.6.4.js")
          WV.AddScriptToExecuteOnDocumentCreated "function setColor_SelectorBased(sel,clr){" & _
                                                 "   $(sel).each(function(){$(this).css('background-color',clr)})" & _
                                                 "}"
      
      WV.NavigateToString "<p>first Para</p><p>second Para</p><p>last Para</p>"
      
      WV.jsRun "setColor_SelectorBased", "p:first, p:last", "magenta"
    End Sub
    
    Public Function wgetJQ(URL) As String
      With CreateObject("WinHttp.WinHttpRequest.5.1")
          .open "GET", URL: .send: wgetJQ = .responseText
          
          'hot-fixes for two edge/chromium-related bugs in the current jQuery-release
          wgetJQ = Replace(wgetJQ, "el = document", "el = window.document")
          wgetJQ = Replace(wgetJQ, "documentElement.getRootNode", "documentElement && documentElement.getRootNode")
      End With
    End Function
    If all works well, the first and the last of the 3 <p>-Tags should be colored magenta.

    Edit: Seems, that the WebView2-method: AddScriptToExecuteOnDocumentCreated -
    does not live up to its "second symbolname-part" anymore...
    (hope, they are fixing this soon)...

    In the interim, you can enclose all such added scripts with your own js-event-listener:
    (example is based on the working one above, but now not even the "jQuery-hotfixes" are needed anymore,
    when the script-adding is delayed until the document "is sitting properly in the DOM")
    Code:
    Option Explicit
     
    Private WithEvents WV As cWebView2
     
    Private Sub Form_Load()
      Me.Visible = True
     
      Set WV = New_c.WebView2(hWnd)
      With New_c.StringBuilder
          .AddNL wget("https://code.jquery.com/jquery-3.6.4.js")
     
          .AddNL "$('p:first, p:last').each(function(){$(this).css('background-color','magenta')})"
       
          WV.AddScriptToExecuteOnDocumentCreated "window.addEventListener('load',(e)=>{" & .ToString & "})"
      End With
     
      WV.NavigateToString "<p>first Para</p><p>second Para</p><p>last Para</p>"
    End Sub
    
    Public Function wget(URL) As String 'generic text-retrieval "by URL"
      With CreateObject("WinHttp.WinHttpRequest.5.1")
          .open "GET", URL: .send: wget = .responseText
      End With
    End Function
    Olaf
    Last edited by Schmidt; Mar 24th, 2023 at 08:47 AM.

  23. #303
    Hyperactive Member
    Join Date
    Jul 2017
    Posts
    344

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by Schmidt View Post
    Why not iterate over them from the inside of a little js-function?
    You can pass String-Parameters into such functions just fine from the VB-Side...
    (like e.g. QuerySelector-StringPatterns, or just "plain IDs", along with e.g. Color-Strings).

    In short, complex DOM-operations remain "in generic, clever parametrized js-helpers" -
    and then these "nice trigger-parameters" could (should) be passed from the VB-side.

    Olaf
    Sorry to ask again, but can you please show me an example?

    My problem is that I don't know how to access the hotspots that the function returns.
    I have tried this:

    Dim hotspots
    hotspots = WV.jsRun("window._grid_ensureHotSpotIds")

    Debug.Print UBound(hotspots) 'here it errors out saying "Type mismatch" (obviously it's not an array. It's empty)
    Last edited by tmighty2; Mar 24th, 2023 at 07:59 AM.

  24. #304
    Addicted Member
    Join Date
    Apr 2017
    Location
    India
    Posts
    234

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by Schmidt View Post
    With the now available browser-built-in selector-functions, there's rarely a need for jQuery anymore...

    ... .. .

    Edit: Seems, that the WebView2-method: AddScriptToExecuteOnDocumentCreated -
    does not live up to its "second symbolname-part" anymore...
    (hope, they are fixing this soon)...

    In the interim, you can enclose all such added scripts with your own js-event-listener:
    (example is based on the working one above, but now not even the "jQuery-hotfixes" are needed anymore,
    when the script-adding is delayed until the document "is sitting properly in the DOM")
    Code:
    ... .. .
    Olaf
    Dear Olaf,

    Thanks a TON for both the initial demo-code and its Edit later on.

    The starting info mentioned by you in your "Edit" portion was exactly the cause of my problem (reported earlier) and not jQuery.

    Actually, after posting my earlier message, as I was exploring further, I realised that even some "pure js" statements were not working (much like the jQuery statements) if they were lying globally (instead of inside some functions) in my ".js" file. So, what I did finally was to place all of those non-working lines of code inside the following DOMContentLoaded "listener" function

    Code:
    Document.addEventListener('DOMContentLoaded', function () {
     ... .. .
    }
    Then, everything worked "perfectly" with absolutely no hitch. That made me come to the realisation that the DOM elements were not visible to the globally lying lines of code if my whole js file is added as a string via 'AddScriptToExecuteOnDocumentCreated'. Based on that realisation, the conclusion to which I reached was that my understanding of what "AddScriptToExecuteOnDocumentCreated" would do was incorrect.

    I came back here to share my conclusion and asking you whether my understanding is correct. That is when I saw your Edit wherein you have remarked that the 2nd part of "AddScriptToExecuteOnDocumentCreated" is a sort of bug itself. Thanks Olaf.

    And, it was very nice to see the following 'yet another' cute compact one-liner from you to overcome the seeming bug in "AddScriptToExecuteOnDocumentCreated".


    Code:
    WV.AddScriptToExecuteOnDocumentCreated "window.addEventListener('load',(e)=>{" & .ToString & "})"
    So, what I did (as a very quick test) was to check out your above one-liner straightaway in my VB application [of course after replacing the ".ToString" in your one-liner with "New_c.FSO.ReadTextContent("MyFullFile.js", False, CP_UTF8)"]. But, it looked like that the above resulted in the existing function [Document.addEventListener('DOMContentLoaded', function ()] in my ".js" file to not to take effect. I remember reading somewhere in the net today (and some days back too) that if we decide to use more than one OnLoad listener, then these listerners should be added to a list of listeners. OR else, sometimes, one of the listeners would replace the other listeners. Perhaps that is what is happening when I use your one-liner. I don't know that for sure now. Because, as of now, I just did a very quick test only. Thanks once again for your cute one-liner. I just loved it. When time permits, I will try to learn what to do in my ".js", in order to use your one-liner.


    By the way, when you say "With the now available browser-built-in selector-functions, ... .. .", I think you mean the querySelector and querySelectorAll functions. If so, then, yes, after reading your posts mentioning about them, I do have started using them and are very convenient. Will try to slowly move over to querySelectors completely. Thanks a TON.


    Kind Regards.

  25. #305

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by softv View Post
    ...it looked like that the above resulted in the existing function
    [Document.addEventListener('DOMContentLoaded', function ()] in my ".js" file
    to not to take effect. ...
    If it is enclosed by "my" outer "onload"-callback-snippet, then "your" (inner) event-listener-installation comes "too late" ...
    since you prepare your listening, when the document-load-event has already happened (was already catched by me) -
    and therefore installing the Listener "at that point in time" will never trigger the code in "your" inner callback-function-block...

    Easy solution would be, to remove your own listener-installation from your js-source-file
    (also in preparation for a potentially upcoming bugfix by MS for the AddScriptToExecuteOnDocumentCreated-call).

    Olaf

  26. #306

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by tmighty2 View Post
    Sorry to ask again, but can you please show me an example?

    My problem is that I don't know how to access the hotspots that the function returns.
    I have tried this:

    Dim hotspots
    hotspots = WV.jsRun("window._grid_ensureHotSpotIds")

    Debug.Print UBound(hotspots) 'here it errors out saying "Type mismatch" (obviously it's not an array. It's empty)
    You will have to check in your js-source, whether the window._grid_ensureHotSpotIds function,
    returns something at all...

    And if it does, then gather these results in your own array -
    and then return this array as a serialized JSON-string via:
    return JSON.stringify(myHotspotArray)

    At the vb6-side you can then easily convert that returned JSON-string into a cCollection:
    Dim oHotSpots As cCollection
    Set oHotSpots = New_c.JSONDecodeToCollection(WV.jsRun("window._grid_ensureHotSpotIds"))

    HTH

    Olaf

  27. #307
    Addicted Member
    Join Date
    Apr 2017
    Location
    India
    Posts
    234

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by Schmidt View Post
    ... .. .
    Easy solution would be, to remove your own listener-installation from your js-source-file
    (also in preparation for a potentially upcoming bugfix by MS for the AddScriptToExecuteOnDocumentCreated-call).
    Olaf
    What care and concern from you in your support!!! I am quite enjoying it, working with RC6 and also receiving your wonderful loving support. Have missed a LOT of both, I am sure, by not getting time to start using 'RC' very many years back itself, though I always knew inside my heart that 'RC' was such a treasure of a contribution!

    Well, the very first thing I tried was that only - removing my own 'DOMContentLoaded' listener line. But, it did not work. That quite surprised me, like anything! Because, I was almost certain that that would be enough. So, I started examining my code carefully and found out that I had left a piece of helper-function code still in my VB app itself. I commented out that line and added that function also in my 'MyFullFile.js' and everything worked like a charm!

    Your tip in post 277 that all helper functions shall be called from a single .js file made me think why not call my whole .js file itself from inside VB. Now that it is possible, it is (and will continue to be) of great help to me, going forward, I believe. Once again thanks for your OnLoad listener one-liner! Superb!

    Ever remaining in awe of both your work and your heart.

    Kindest Regards.

  28. #308
    Hyperactive Member
    Join Date
    Jul 2017
    Posts
    344

    Question Re: VB6 WebView2-Binding (Edge-Chromium)

    My problem is that stringify does not work. hotspots.count is 196, but the line "alert('after stringify');" is not fired in the code below:

    Code:
    HTMLElement.prototype._grid_ensureHotSpotIds = function(selector)
    {
      let hotSpots = [];
      if (selector != null)
      {
        var splitSelector = selector.split(',');
        //Some websites need a selector that's too complex to make just in one step. So we need to split the selector on commas and do querySelectors that will chain the results.
        splitSelector.forEach(singleSelector =>
        {
          if (hotSpots != null)
          {
            let hotSpotsFound = this.querySelectorAll(singleSelector);
            if (hotSpotsFound != null)
            {
              hotSpots = hotSpots.concat(Array.from(hotSpotsFound));
            }
            else
            {
              //alert('hotspots is null in splitselector');
            }
          }
        });
      }
      else
      {
        hotSpots = this.querySelectorAll(hotSpotSelector);
      }
      //alert("Found " + hotSpots.length + " hotspots."); // Alert showing the number of hotspots found
      
      for (var hotSpot of hotSpots)
      {
        hotSpot._grid_ensureId();
      }
      alert('before stringify');
      let hotSpotsString = JSON.stringify(hotSpots); // Convert the hotspots array to a JSON string
      alert('after stringify');
      alert("Hotspots: " + hotSpotsString); // Alert showing the hotspots as a string
      
      return hotSpotsString; // Return the hotspots array as a JSON string
    };
    I guess it could be due to members of such a hotspot.
    I have uploaded the prototype of "element" which I try to stringify:

    https://drive.google.com/file/d/1XPd...usp=share_link

    Edit: I know now that in C# the hotspots are handled like this:

    C# code:

    Code:
    protected virtual Task<HtmlElementReference> GetStartElementAsync(HtmlElementReference startElement, CursorDirection direction)
    		{
    			return Task.FromResult<HtmlElementReference>(startElement);
    		}
    
    		protected async Task<HtmlElementReference> HandleFindElementResultAsync(ElementCursorBase.FindElementResult result, IWebBrowserFrame currentFrame, string getNodesFunc, int? nodeType, CursorDirection direction)
    		{
    			HtmlElementReference htmlElementReference;
    			HtmlElementReference elementReferenceAsync;
    			CursorDirection cursorDirection;
    			string str;
    			if (result != null)
    			{
    				switch (result.ResultType)
    				{
    					case ElementCursorBase.FindElementResultType.Element:
    					{
    						htmlElementReference = new HtmlElementReference(currentFrame.Identifier, result.Element);
    						return htmlElementReference;
    					}
    					case ElementCursorBase.FindElementResultType.IterateUpIntoParent:
    					{
    						HtmlElementReference elementReferenceAsync1 = await WebBrowserExtensionMethods.GetElementReferenceAsync(currentFrame.Parent, String.Format("document.querySelector('[data-grid-frame-identifier=\"{0}\"]')._grid_ensureId()", currentFrame.Identifier));
    						cursorDirection = direction;
    						if (cursorDirection == CursorDirection.Backward || cursorDirection == CursorDirection.BackwardToHeading)
    						{
    							getNodesFunc = "_grid_getPreviousNodes";
    						}
    						htmlElementReference = await this.FindElementAsync(elementReferenceAsync1, getNodesFunc, nodeType, false, direction);
    						return htmlElementReference;
    					}
    					case ElementCursorBase.FindElementResultType.IterateDownIntoFrame:
    					{
    						using (IWebBrowserFrame frame = this._webBrowser.GetFrame(Convert.ToUInt64(result.Element)))
    						{
    							if (frame != null)
    							{
    								cursorDirection = direction;
    								switch (cursorDirection)
    								{
    									case CursorDirection.Forwards:
    									case CursorDirection.ForwardsToHeading:
    									{
    										str = "document.body._grid_ensureId()";
    										break;
    									}
    									case CursorDirection.Backward:
    									case CursorDirection.BackwardToHeading:
    									{
    										str = "document.body._grid_getLastElement()._grid_ensureId()";
    										getNodesFunc = "_grid_getSelfAndPreviousNodes";
    										break;
    									}
    									default:
    									{
    										throw new InvalidOperationException();
    									}
    								}
    								elementReferenceAsync = await WebBrowserExtensionMethods.GetElementReferenceAsync(frame, str);
    							}
    							else
    							{
    								htmlElementReference = null;
    								return htmlElementReference;
    							}
    						}
    						frame = null;
    						htmlElementReference = await this.FindElementAsync(elementReferenceAsync, getNodesFunc, nodeType, true, direction);
    						return htmlElementReference;
    					}
    				}
    				throw new InvalidOperationException();
    			}
    			else
    			{
    				htmlElementReference = null;
    			}
    			return htmlElementReference;
    			throw new InvalidOperationException();
    		}
    Would there be any way to do the same with your browser?
    Last edited by tmighty2; Mar 25th, 2023 at 04:05 PM.

  29. #309
    Hyperactive Member
    Join Date
    Jul 2017
    Posts
    344

    Re: VB6 WebView2-Binding (Edge-Chromium)

    To be more specific: Can VB6-WebView2 handle async tasks like shown in the C# code?

  30. #310
    Hyperactive Member
    Join Date
    Jul 2017
    Posts
    344

    Re: VB6 WebView2-Binding (Edge-Chromium)

    ps: cairo_sqlite.dll is missing a version number.

  31. #311
    Hyperactive Member
    Join Date
    Jul 2017
    Posts
    344

    Re: VB6 WebView2-Binding (Edge-Chromium)

    I have tried to disable the context command, but I think there are no commandline switches available for these settings:

    webView.CoreWebView2.Settings.AreBrowserAcceleratorKeysEnabled = false;
    webView.CoreWebView2.Settings.AreDefaultContextMenusEnabled = false;

    How could I do this with VB6-WebView2?

  32. #312

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by tmighty2 View Post
    To be more specific: Can VB6-WebView2 handle async tasks like shown in the C# code?
    I'd ask the developer who has programmed the C# interaction (with CEF),
    to write a similar js-function for you...

    WebView2 is using chromium as well, but as said, the DOM-interfaces are not exposed to the VB/COM-side here.
    Therefore you have to use "preloaded js-functions" to interact with the Browser-DOM "on the inside" of WV2 -
    and communicate with the outside via JSON-strings.

    Such a C#->js-v8 porting should not be that hard for the developer, who originally wrote the C#-stuff.

    All I can do here from my end, is to show you the "principle".
    Code:
    Option Explicit
    
    Private WithEvents WV As cWebView2, Elements As cCollection
     
    Private Sub Form_Load()
      Visible = True
      Set WV = New_c.WebView2(hWnd)
      
      With New_c.StringBuilder 'js-helpers
          .AddNL "function getElements(sExpr){"
          .AddNL "    var resArr = []"
          .AddNL "    for (var e of document.querySelectorAll(sExpr).values()){"
          .AddNL "        resArr.push({tag:e.tagName, id:e.id, val:e.value, name:e.name, href:e.href})"
          .AddNL "    }"
          .AddNL "    return JSON.stringify(resArr)"
          .AddNL "}"
          
          .AddNL "function setElementBackgroundById(id, color){"
          .AddNL "    document.querySelector('#'+id).style.background = color"
          .AddNL "}"
          
          WV.AddScriptToExecuteOnDocumentCreated .ToString
      End With
      
      With New_c.StringBuilder 'two anchors and two buttons as test-HTML-content
        .AddNL "<a id='a1' href='#foo'>LinkFoo</a><br>"
        .AddNL "<input id='b1' type='button' value='button 1'><br>"
        .AddNL "<a id='a2' href='#bar'>LinkBar</a><br>"
        .AddNL "<input id='b2' type='button' value='button 2'><br>"
        
        WV.NavigateToString .ToString
      End With
      
      'retrieve a few elements "by selector-expression"
      Set Elements = New_c.JSONDecodeToCollection(WV.jsRun("getElements", "a, input"))
      
      Dim Elmt As cCollection 'the enumerated Elements themselves are (again) of type cCollection - but hold a JSON-Object instead of a JSON-array
      For Each Elmt In Elements 'iteration over the gathered Element-Objects in the JSON-Array: Elements
         Debug.Print Elmt.SerializeToJSONString 'just to show, which properties are contained "per element"
         
         Select Case UCase$(Elmt("tag")) 'first Property-access on an Element (here the "tag"-Property)
           Case "A":     WV.jsRun "setElementBackgroundById", Elmt("id"), "#f00"
           Case "INPUT": WV.jsRun "setElementBackgroundById", Elmt("id"), "#0f0"
         End Select
      Next
    End Sub
    ... but the adaption of the above shown principle (to your concrete problem), really is your part.


    And as for cairo_sqlite.dll versions:
    - New_c.Cairo.Version ... will hand out the cairo-version
    - New_c.Connection.Version ... will hand out the SQLite-version
    ...and if you put a question-mark before those expression, you can print the results directly in your immediate-window

    HTH

    Olaf

  33. #313

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by tmighty2 View Post
    I have tried to disable the context command, but I think there are no commandline switches available for these settings:

    webView.CoreWebView2.Settings.AreBrowserAcceleratorKeysEnabled = false;
    webView.CoreWebView2.Settings.AreDefaultContextMenusEnabled = false;

    How could I do this with VB6-WebView2?
    The blue marked boolean Properties are exposed on cWebView2
    (as the <F2>reachable VBIDE-ObjectBrowser would show you, or alternatively intellisense, when you type a . behind WV).

    Olaf

  34. #314
    Hyperactive Member
    Join Date
    Jul 2017
    Posts
    344

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Thank you. I access it from outside in an installer to see if I need to deploy a new version to my users.
    There are only a few files that don't provide a version number, and yours were some of them.
    I will work around it.

  35. #315
    Hyperactive Member
    Join Date
    Jul 2017
    Posts
    344

    Re: VB6 WebView2-Binding (Edge-Chromium)

    The JS operations are really lengthy.
    Would it somehow be possible to make them async and yet return values?

  36. #316

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by tmighty2 View Post
    Would it somehow be possible to make them async ...
    Sure... (you're still not familiar with the WV-interface, which you can study in the ObjectExplorer)

    MyToken = WV.jsRunAsync("MyJsFunctionName", MyInputParams, ...)

    Quote Originally Posted by tmighty2 View Post
    ...and yet return values?
    Private Sub WV_JSAsyncResult(Result As Variant, ByVal Token As Currency, ByVal ErrString As String)
    ' If Token = MyToken Then ...
    End Sub

    HTH

    Olaf

  37. #317
    New Member
    Join Date
    Dec 2022
    Posts
    7

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Hello Olaf,

    WebView2 has Stop method, is there a reason why your cWebView2 doesn't have it? Can you add it to the interface?

  38. #318

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,219

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by Bob17 View Post
    WebView2 has Stop method, is there a reason why your cWebView2 doesn't have it? Can you add it to the interface?
    WV.jsRun "stop" 'should work

    Olaf

  39. #319
    Hyperactive Member
    Join Date
    Jul 2017
    Posts
    344

    Re: VB6 WebView2-Binding (Edge-Chromium)

    -----
    Last edited by tmighty2; Apr 1st, 2023 at 01:53 PM.

  40. #320
    Hyperactive Member
    Join Date
    Jul 2017
    Posts
    344

    Re: VB6 WebView2-Binding (Edge-Chromium)

    I am showing an email in the form of an xml string in the browser.

    Even though the encoding is declared as utf8 and also saved as such, I get strange Umlauts.

    What am I doing wrong?
    Code:
    Public Sub ShowMail(ByVal uXml As String)
    
        Set WV = New_c.WebView2 'create the instance
        If WV.BindTo(Me.picWV.hwnd, , , , "--autoplay-policy=no-user-gesture-required") = 0 Then
            modLog.WriteLog "#error initilializing browser!"
            MsgBox "couldn't initialize WebView-Binding": Exit Sub
        End If
     
        WV.AreBrowserAcceleratorKeysEnabled = False
        WV.AreDefaultContextMenusEnabled = False
    
    Dim HtmlFile As String
    HtmlFile = New_c.fso.GetLocalAppDataPath & "\temp.html"
    
    New_c.fso.WriteTextContent HtmlFile, uXml, True
      
    WV.Navigate HtmlFile
    Code:
    This XML file does not appear to have any style information associated with it. The document tree is shown below.
    <mime_message>
    <header>
    <mime-version>1.0</mime-version>
    <date>Fri, 26 Mar 2021 20:38:23 +0100</date>
    <message-id> <95B4AC75D4DC194DA3865C264BC6885877F3BB89@xxxxx> </message-id>
    <content-type boundary="------------010803010009050608040505"> multipart/alternative </content-type>
    <x-priority>3 (Normal)</x-priority>
    <from>
    <address>
    <addr>xxxx@gmx.net</addr>
    <name>xxxxxx</name>
    </address>
    </from>
    <ckx-bounce-address>xxxxx.xxxxx@gmx.net</ckx-bounce-address>
    <to>
    <address>
    <addr>xxxxx@gmx.net</addr>
    <name/>
    </address>
    </to>
    <subject>Fwd: AW: </subject>
    </header>
    <body>
    <subpart>
    <mime_message>
    <header>
    <content-type charset="utf-8"> text/plain </content-type>
    <content-transfer-encoding>7bit</content-transfer-encoding>
    </header>
    <body> </body>
    </mime_message>
    </subpart>
    <subpart>
    <mime_message>
    <header>
    <content-type charset="utf-8"> text/html </content-type>
    <content-transfer-encoding>quoted-printable</content-transfer-encoding>
    </header>
    <body>
    <![CDATA[ <hr style=3D"color:#62B3FF"><div style=3D"background-color: #DDDDDD; font-s= ize:10pt"><b>Von: </b><a href=3D"mailto:xxxxx@bvkm.de">"Anne Willeke= " <xxxxx@bvkm.de></a></br><b>Datum: </b>26.03.2021 13:02:16</br><b>A= n: </b><a href=3D"mailto:xxxxx.xxxxx@gmx.net">Johannes xxxxx</a></br><b>B= etreff: </b>Fwd: AW: </div></br><html xmlns:v=3D"urn:schemas-microsoft-com:= vml" xmlns:o=3D"urn:schemas-microsoft-com:office:office" xmlns:w=3D"urn:sch= emas-microsoft-com:office:word" xmlns:m=3D"http://schemas.microsoft.com/off= ice/2004/12/omml" xmlns=3D"http://www.w3.org/TR/REC-html40"> <head><META http-equiv=3D"Content-Type" content=3D"text/html;charset=3Dutf-= 8"> <meta name=3D"Generator" content=3D"Microsoft Word 15 (filtered medium)"> <style><!-- /* Font Definitions */ @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4;} @font-face {font-family:Calibri; panose-1:2 15 5 2 2 2 4 3 2 4;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {margin:0cm; font-size:11.0pt; font-family:"Calibri",sans-serif;} span.E-MailFormatvorlage18 {mso-style-type:personal-reply; font-family:"Calibri",sans-serif; color:windowtext;} =2EMsoChpDefault {mso-style-type:export-only; font-size:10.0pt;} @page WordSection1 {size:612.0pt 792.0pt; margin:70.85pt 70.85pt 2.0cm 70.85pt;} div.WordSection1 {page:WordSection1;} --></style><!--[if gte mso 9]><xml> <o:shapedefaults v:ext=3D"edit" spidmax=3D"1026" /> </xml><![endif]--><!--[if gte mso 9]><xml> <o:shapelayout v:ext=3D"edit"> <o:idmap v:ext=3D"edit" data=3D"1" /> </o:shapelayout></xml><![endif]--> </head> <body lang=3D"DE" link=3D"#0563C1" vlink=3D"#954F72" style=3D"word-wrap:bre= ak-word"> <div class=3D"WordSection1"> <p class=3D"MsoNormal"><span style=3D"mso-fareast-language:EN-US">Ah, jetzt= habe ich es verstanden, den Fragebogen kannst du auch n=C3=A4chste Woche s= chicken. Klar.<o:p></o:p></span></p> <p class=3D"MsoNormal"><span style=3D"mso-fareast-language:EN-US">Sch=C3=B6= nes Wochenende!<o:p></o:p></span></p> <p class=3D"MsoNormal"><span style=3D"mso-fareast-language:EN-US"><o:p>&nbs= p;</o:p></span></p> <div style=3D"border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm = 0cm 0cm"> <p class=3D"MsoNormal"><b>Von:</b> Johannes xxxxx &lt;xxxxx.xxxxx@gmx.net= &gt; <br> <b>Gesendet:</b> Freitag, 26. M=C3=A4rz 2021 09:40<br> <b>An:</b> Anne Willeke &lt;xxxxx@bvkm.de&gt;; xxxxx@gmx.net<= br> <b>Betreff:</b> <o:p></o:p></p> </div> <p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p> <p class=3D"MsoNormal"><o:p>&nbsp;</o:p></p> </div> </body> </html> ]]>
    </body>
    </mime_message>
    </subpart>
    </body>
    </mime_message>
    Name:  umlaute.png
Views: 972
Size:  2.8 KB

Page 8 of 12 FirstFirst ... 567891011 ... 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