Page 11 of 14 FirstFirst ... 891011121314 LastLast
Results 401 to 440 of 555

Thread: VB6 WebView2-Binding (Edge-Chromium)

  1. #401

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,454

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by BooksRUs View Post
    Hopefully, this is something simple. Trying to simply set the Background Color of the webview2 page.
    There is a property for it, but I can't seem to find where it is in the cWebView2 class.
    There is not specific property for it on the WV2 ...

    The WV2-interface is generally much more "spartan", compared to the old IE-control -
    which IMO is a good thing - because the less you have to learn (about the MS-WebView2).

    Instead the focus now shifts from built-in COM-methods -
    to "easy reachable js-Methods- and -Properties, inside the Browser-engine"

    One has to be relatively proficient with JavaScript, to make good use of the WebView2
    (and that's a skill, many developers these days already have).

    Below is a code-snippet, which uses javascript-property-syntax - to influence the backcolor of the document.body.
    Code:
    Option Explicit
     
    Private WithEvents WV As cWebView2
    
    Private Sub Form_Load()
      Me.Visible = True 'ensure visibility of this "Parent.hWnd"
      
      Set WV = New_c.WebView2(Me.hWnd) 'bind to the hWnd
      
          WV.NavigateToString "<p>Hello World</p>" 'create a simple document from string-input
          
          WV.jsProp("document.body.style.background") = "red" 'set the body.style.background-pop to red color
    End Sub
    
    Private Sub Form_Resize()
      If Not WV Is Nothing Then WV.SyncSizeToHostWindow
    End Sub
    HTH

    Olaf

  2. #402
    Addicted Member
    Join Date
    Apr 2017
    Location
    India
    Posts
    238

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Dear Olaf,

    Recently I noticed that if I have two applications (say, A and B) made by me (the 2nd application also invoking webview2 via RC6 WV only), then:

    1. If I start application A, the main interface opens normally, rendering the specified web page normally, and everything is working all right.

    2. But, even as A is running, if I start B, then 'B' would not start. In other words, the WebView2 rendering engine would not start for 'B'.

    So, I searched for a solution in net and landed here - https://stackoverflow.com/questions/...e-same-browser

    Seeing the suggestion in the abovementioned link, in 'B', I gave App.path for 'userDataFolder' parameter while binding (as follows):
    Code:
    WV.BindTo(picWV.hWnd, , , App.Path)
    When I did the above and started B, then B also would start simultaneously even while A is running. That made me happy.

    I noticed however that a directory named "EBWebView" got created in App.Path of 'B' application. The folders and files carried by that directory occupied 4Mb or so. That's also okay for me as long as 'B' started. But, that made me realise that I need to necessarily give 'App.path' during binding in 'A' application too because otherwise, if an application (say 'X') developed by some other developer was already running in user's system (assuming that 'X' did not have any folder specified for userDataFolder parameter), then if user starts my 'A' application simultaneously, then it would start only if I had specified a folder for userDataFolder in 'A'. But that would mean, 'EBWebView' would get created. "As of now", I don't foresee any problem, "as such", for me or the user because of that extra directory getting created but just wanted to know the following:
    --
    1. Is the suggestion (say 'S') given in the abovementioned stackoverflow page the ONLY way to start two or more WV-based applications simultaneously?

    2. If not, then, what are the alternate ways? Will those ways be better than 'S'? Perhaps they might avoid the creation of the 'EBWebView' but will they be better in terms of speed, etc.?
    Note: I do notice that with userDataFolder specified, during the first ever starting of 'A', it takes time for 'A' to start (because of the fresh creation of the 'EBWebView' directory, I believe). But, subsequent starts of 'A' are quite normal.
    --

    Well, just as I was about to complete drafting this message, I checked the size of 'EBWebView' in 'A' and it was 20MB!!! I checked in 'B' and it was 13MB! So, I think they are growing in size in every start of 'A'. If that is the case, then, it is a cause of concern. I will research more on this growing size when I get time and write back here. It seems like the 'Default' folder inside 'EBWebView' starts growing, probably maintaining some session info, etc.

    All said and done, I believe that there should be a proper way to bind by which directories like 'EBWebView' need not get created.

    I just now quickly tried keeping different arbitrary values for SecondsToWaitForInitComplete in both 'A' and 'B' to see whether they would help as "settings that differ per-instance". But, in my quick testing, they did not seem to help.

    Await a good solution, if any.

    OR, in the first place, in case I am wrong in my findings itself, then kindly let me know what mistake I did and what is the corrective action to be taken on my side.

    I take this opportunity to once again thank you in TONs, Olaf, for all your wonderful free frameworks/codes/tools and prompt support. God Bless you! God Bless ALL!

    Kind Regards.

  3. #403

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,454

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by softv View Post
    1. If I start application A, the main interface opens normally, rendering the specified web page normally, and everything is working all right.

    2. But, even as A is running, if I start B, then 'B' would not start. In other words, the WebView2 rendering engine would not start for 'B'.
    Yep, can affirm that...
    ...wasn't aware, how the concrete mechanism behind it works - but studied it a bit - and here's what I found:

    You have to provide a unique UserData-Directory for:
    - executables, which "bytewise differ" (that's probably tested by calculating HashSums in the startup-phase)

    Meaning, when you compile executable A.exe - and then:
    - just make a file-copy of the same A.exe - just changing the FileName to e.g. "Copy of A.exe"
    - this will not cause a conflict, when you start "A.exe" and "Copy of A.exe" in parallel
    (when the HashSum of two binaries is the same, they are allowed to share the same UserData-path - with the same "browser-settings").

    The "protection" kicks in, when you start executables which differ in their binary Hash-Sum (but point to the same "UserData"-Path).
    Then the behaviour is, that "the first one (on this UserData-path) wins".

    Hmm - how to solve that in the RC6...
    (regarding the "Default-UserData-Path" I apply, when you leave out the optional Param in the Bind-Method)

    Currently, I apply the result of: New_c.FSO.GetLocalAppDataPath ... as the "default-UserData-Path" (when the optional Param was not set)

    But I could (in the next release) change that, to e.g.: New_c.FSO.GetLocalAppDataPath & "\" & App.EXEName

    This way, we would achieve "isolation" between "different App.ExeNames" at least.

    If there's better ideas "forth-coming" here, I'd be happy to incorporate them -
    if not I'd proceed (for the next version), with what I've just proposed...

    Edit: forgot to comment about the "EBWebView"-folder below that UserData-path - #
    that's a folder, created by MS - and I wouldn't change its name - or "mess" with any of the content it holds from User-code...

    Olaf
    Last edited by Schmidt; Jun 17th, 2023 at 07:29 AM.

  4. #404
    Addicted Member
    Join Date
    Apr 2017
    Location
    India
    Posts
    238

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by Schmidt View Post
    Yep, can affirm that...
    ... .. .
    ... .. . But I could (in the next release) change that, to e.g.: New_c.FSO.GetLocalAppDataPath & "" & App.EXEName
    ... .. .

    Olaf
    Thanks, as always, for your detailed and prompt reply, Olaf.

    That's (New_c.FSO.GetLocalAppDataPath & "" & App.EXEName) really unobtrusive too, while being unique. I myself saw the 'EBWebView' folder in my LocalAppData directory today only, after reading your message! . It was occupying 618MB! Don't know why it is designed to be growing though (by MS)!

    Kind Regards.

  5. #405
    Hyperactive Member
    Join Date
    Dec 2008
    Location
    Argentina
    Posts
    441

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Hello, what are the dependencies you have, one is CR6.dll but what else?
    leandroascierto.com Visual Basic 6 projects

  6. #406

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,454

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by LeandroA View Post
    Hello, what are the dependencies you have, one is CR6.dll but what else?
    Please always ship the whole content of RC6BaseDlls.zip (3.7MB zipped, currently).

    RC6.dll depends on DirectCOM.dll, cairo_sqlite.dll, as well as on WebView2Loader.dll (all 3 are "flat Dlls")

    I usually put them into a \Bin\ subdirectory below the App.Path (beside the executable) -
    and use one of the "Drop-in regfree-bas-modules" to enable regfree deployment of the whole App.

    Edit: Here's what a "minimum-version" of such a "regfree-DropIn-bas-module" looks like:
    (adjusted, for the libs being contained in the mentioned \Bin\ SubFolder)
    Code:
    Option Explicit
     
    Private Declare Function LoadLibraryW Lib "kernel32" (ByVal lpLibFileName As Long) As Long
    Private Declare Function GetInstanceEx Lib "DirectCOM" (spFName As Long, spClassName As Long, Optional ByVal UseAlteredSearchPath As Boolean = True) As Object
    
    Private Const DirectComDllRelPath = "\Bin\DirectCOM.dll"
    Private Const RCDllRelPath = "\Bin\RC6.dll"
    
    Public Property Get New_c() As cConstructor
      Static st_RC As cConstructor
      If Not st_RC Is Nothing Then Set New_c = st_RC: Exit Property
      
      If App.LogMode Then  'we run compiled - and try to ensure regfree instantiation from \Bin\
         On Error Resume Next
            LoadLibraryW StrPtr(App.Path & DirectComDllRelPath)
            Set st_RC = GetInstanceEx(StrPtr(App.Path & RCDllRelPath), StrPtr("cConstructor"))
            If st_RC Is Nothing Then MsgBox "Couldn't load regfree, will try with a registered version next..."
         On Error GoTo 0
      End If
      If st_RC Is Nothing Then Set st_RC = cGlobal.New_c 'fall back to loading a registered version
      Set New_c = st_RC 
    End Property
    
    Public Property Get Cairo() As cCairo
      Static st_CR As cCairo
      If st_CR Is Nothing Then Set st_CR = New_c.Cairo 
      Set Cairo = st_CR
    End Property
    Olaf
    Last edited by Schmidt; Jun 19th, 2023 at 11:56 AM.

  7. #407
    Hyperactive Member
    Join Date
    Dec 2008
    Location
    Argentina
    Posts
    441

    Re: VB6 WebView2-Binding (Edge-Chromium)

    thank you very much, it was very helpful
    leandroascierto.com Visual Basic 6 projects

  8. #408
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,538

    Re: VB6 WebView2-Binding (Edge-Chromium)

    No spam here. 99% of the questions I ask or reply to are useful or have the correct answer. Maybe a little off topic at times.
    For example, someone asked about your previous WEBVIEW problem, why can’t EXCEL VBA be loaded, and why VB.NET will crash after loading? I replied and it was deleted by you. Because the form on VBA is a very special existence, it does not have a handle attribute, even if there is, there are still many problems, so if RC6.DLL itself can provide a window for displaying web pages, VBS can also display the form, VBA is also solved, and VB.NET will not crash.
    Didn't we solve that problem in the end?
    At this point, you may have said that you have strayed from the topic. Some things are completed in one sentence. If you don’t explain it clearly to you, you will get angry for no reason. I don’t know why. Maybe it’s a translation error?
    But you didn't expect me to be very troubled, why RC6.DLL webview always can't display the webpage, the loading is very slow, and the SDK directory cannot be found.
    For example, jsprop(**) often fails to return results.

  9. #409

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,454

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by xiaoyao View Post
    No spam here. 99% of the questions I ask or reply to are useful or have the correct answer.
    Nope, the opposite is the case... 99% of your postings:
    - are entirely out of context
    - in very bad english
    - are for the most part confusing or misleading
    - are not reacting to "questions, others were asking you"

    Please go "thinking out loud" elsewhere
    (but that's probably something, you will not react to either, although you were asked many times).

    Olaf

  10. #410
    Hyperactive Member
    Join Date
    Dec 2008
    Location
    Argentina
    Posts
    441

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Hello, I want to provide some information or perhaps this has already been discussed, if you want to work with dpiAware = true, you can experience that the control does not initialize WV.BindTo() , it is important to take into account that if another application is instantiated using webview from RC6 with dpiAware = true and another application in dpiAware = false the last one will fail and vice versa, note if the IDE is executed, the manifested exe will fail until stopping the ide.
    leandroascierto.com Visual Basic 6 projects

  11. #411

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,454

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by LeandroA View Post
    Hello, I want to provide some information or perhaps this has already been discussed, if you want to work with dpiAware = true, you can experience that the control does not initialize WV.BindTo() , it is important to take into account that if another application is instantiated using webview from RC6 with dpiAware = true and another application in dpiAware = false the last one will fail and vice versa, note if the IDE is executed, the manifested exe will fail until stopping the ide.
    That's similar to what softv brought up in #402 ...
    and should be fixed now in RC6 verion 6.0.15 - but I've not yet uploaded this new version...

    Olaf

  12. #412
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,538

    Re: VB6 WebView2-Binding (Edge-Chromium)

    how to get selected item html?

    Code:
    var selection = window.getSelection();
    var range = selection.getRangeAt(0);
    var clonedRange = range.cloneRange();
    var fragment = clonedRange.cloneContents();
    var div = document.createElement('div');
    div.appendChild(fragment);
    var htmlString = div.innerHTML;
    console.log(htmlString);
    Code:
    var htmlString = window.getSelection().getRangeAt(0).cloneContents().querySelector('body').innerHTML;
     
    VM317:1 Uncaught TypeError: Cannot read properties of null (reading 'innerHTML')
        at <anonymous>:1:91
    why?

  13. #413

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,454

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by xiaoyao View Post
    how to get selected item html?

    Code:
    var selection = window.getSelection();
    var range = selection.getRangeAt(0);
    var clonedRange = range.cloneRange();
    var fragment = clonedRange.cloneContents();
    var div = document.createElement('div');
    div.appendChild(fragment);
    var htmlString = div.innerHTML;
    console.log(htmlString);
    Code:
    var htmlString = window.getSelection().getRangeAt(0).cloneContents().querySelector('body').innerHTML;
     
    VM317:1 Uncaught TypeError: Cannot read properties of null (reading 'innerHTML')
        at <anonymous>:1:91
    why?
    This is primarily a VB-Forum - and your question is related to "pure Javascript" -
    please ask it elsewhere and stop spamming this thread.

    Olaf

  14. #414
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,538

    Re: VB6 WebView2-Binding (Edge-Chromium)

    The browser control gets the selected text, HTM, or image, which is like a text box, and it is a very useful function to get part of the selected text. In addition to displaying web pages, web controls also need other JS-related functions.

    I have found the code, if it can be added to the DLL, it can make the webview more powerful

    In ie webbrowser, almost no JS functions are used, except that if you want to right-click to pop up the menu, you can actually use some undisclosed or special interfaces of WEBBROWSER to achieve it.
    However, edge webview2 requires a lot of JAVASCRIPT functions to be more convenient to use. If JS is disabled or JAVASCRIPT is not used, many functions cannot be realized.

    Perhaps it is possible to develop another RC6js.dll specifically to enhance JS capabilities, or add a general tools.js to enhance control capabilities, just like jquery.js exists.

    Sometimes I also want to get the text at the current mouse position (not selected) or just right clicked.
    Sometimes I want to get the coordinates of an element in the webpage ( left,top offset of the webview). There are many functions that are still necessary. If everyone can contribute some good JS functions to enhance the ability of edge, everyone's efforts will be great. Benefit 100-1000 other users.

    this is just a suggestion
    Last edited by xiaoyao; Jun 28th, 2023 at 02:31 AM.

  15. #415

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,454

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by xiaoyao View Post
    Perhaps it is possible to develop another RC6js.dll specifically to enhance JS capabilities...
    Why would anyone want to do that - when you can load such a "myUseful_JS_helper_functions.js" file
    into the WebView2-Context in just one line of code?

    This place is for the cWebView2-COM-Class of the RC6 - and javascript-problems should be mentioned only,
    when the COM-interface-methods for that (WV.jsProp, WV.jsRun, etc.) make problems.

    This Forum has a "javascript-SubForum" ... please post your "js-helpers-xiaoyao-style"
    in a separate thread over there.

    Olaf

  16. #416
    Fanatic Member
    Join Date
    Jul 2017
    Posts
    761

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Has anybody found a smart / easy way to use Olafs webview2 wrapper in Winform .NET?

    I wonder if I have to go interop, but I think so.

  17. #417

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,454

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by tmighty2 View Post
    Has anybody found a smart / easy way to use Olafs webview2 wrapper in Winform .NET?

    I wonder if I have to go interop, but I think so.
    I wonder why would you'd go .NET-Winforms (...is there a certain Control, not covered by Krools Suite)?

    Well, ... if you really have to - I'd use the .NET-based ("native") WebView2-wrapper instead of the RC6-based one.

    Olaf

  18. #418
    New Member
    Join Date
    Dec 2022
    Posts
    9

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by Schmidt View Post
    That's similar to what softv brought up in #402 ...
    and should be fixed now in RC6 verion 6.0.15 - but I've not yet uploaded this new version...

    Olaf
    Hi Olaf,
    do you plan to release the 6.0.15 with the fix for the DPI aware and DPI scaling issues?
    Thanks.

  19. #419
    Fanatic Member
    Join Date
    Jul 2017
    Posts
    761

    Re: VB6 WebView2-Binding (Edge-Chromium)

    I would like to block the loading of images.

    I am using this after initialization:

    WV.AddWebResourceRequestedFilter "*", Filter_IMAGE

    However, this event is never called:

    Code:
    Private Sub WV_PermissionRequested(ByVal IsUserInitiated As Boolean, State As RC6.eWebView2PermissionState, ByVal URI As String, ByVal PermissionKind As RC6.eWebView2PermissionKind)
     
        Debug.Assert False
    
        If Has(URI, "jpg") Or Has(URI, "png") Then
            Debug.Assert False
        End If
    
    End Sub

  20. #420

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,454

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by tmighty2 View Post
    I would like to block the loading of images.

    I am using this after initialization:

    WV.AddWebResourceRequestedFilter "*", Filter_IMAGE

    However, this event is never called:

    Code:
    Private Sub WV_PermissionRequested(ByVal IsUserInitiated As Boolean, State As RC6.eWebView2PermissionState, ByVal URI As String, ByVal PermissionKind As
    As explained in #373, the matching event is: WV_WebResourceRequested ...
    (and not WV_PermissionRequested, which is more for hardware-things like "GPS-sensor-access-permission, Microphon- or Camera-access-permissions")

    Olaf

  21. #421

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,454

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by Bob17 View Post
    Hi Olaf,
    do you plan to release the 6.0.15 with the fix for the DPI aware and DPI scaling issues?
    Not sure, whether the DPI-aware stuff is really related to the now "separated UserData-Folders per App-Exename" -
    but version 6.0.15 is now online.

    Olaf

  22. #422
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    733

    Re: VB6 WebView2-Binding (Edge-Chromium)

    i downlaod new current version: 6.0.15, last updated: 2023-07-23

    but i found can not run WV.jsProp. i change to 6.0.0.9 work ok.

    the other question

    Code:
    If Right$(App.Path, 1) <> "\" Then AppPath = AppPath & "\"
    
        If App.LogMode Then '
            On Error Resume Next
            LoadLibraryW StrPtr(AppPath & DirectComDllRelPath)
            Set New_c = GetInstanceEx(StrPtr(AppPath & RCDllRelPath), StrPtr("cConstructor"))
            'Set New_c = GetInstanceEx(StrPtr(AppPath & "Bin\RC6.dll"), StrPtr("cConstructor"), True) '
            If New_c Is Nothing Then MsgBox "Couldn't load regfree, will try with a registered version next..."
            On Error GoTo 0
          
        Else '
            Set New_c = New cConstructor
        End If
    the same code if i chang RC6.dl 6.0.0.9 to 6.0.15 ,MsgBox "Couldn't load regfree, will try with a registered version next..."



    win7 32

    Another issue is that playing online videos often results in buffering. And the same browser plays smoothly。How to solve it?thanks
    Last edited by xxdoc123; Jul 25th, 2023 at 08:41 AM.

  23. #423

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,454

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by xxdoc123 View Post
    i downlaod new current version: 6.0.15, last updated: 2023-07-23

    but i found can not run WV.jsProp. i change to 6.0.0.9 work ok.
    Please give an example...

    Quote Originally Posted by xxdoc123 View Post
    the other question

    Code:
    If Right$(App.Path, 1) <> "\" Then AppPath = AppPath & "\"
    
        If App.LogMode Then '
            On Error Resume Next
            LoadLibraryW StrPtr(AppPath & DirectComDllRelPath)
            Set New_c = GetInstanceEx(StrPtr(AppPath & RCDllRelPath), StrPtr("cConstructor"))
            'Set New_c = GetInstanceEx(StrPtr(AppPath & "Bin\RC6.dll"), StrPtr("cConstructor"), True) '
            If New_c Is Nothing Then MsgBox "Couldn't load regfree, will try with a registered version next..."
            On Error GoTo 0
          
        Else '
            Set New_c = New cConstructor
        End If
    the same code if i chang RC6.dl 6.0.0.9 to 6.0.15 ,MsgBox "Couldn't load regfree, will try with a registered version next..."
    The Dll-binaries within your Bin-Folder have to match with the (registered) RC6-version you last compiled your executable with...

    Quote Originally Posted by xxdoc123 View Post
    Another issue is that playing online videos often results in buffering.
    That's not really a problem of the wrapper... (the Browser-engine is from Google and MS) -
    ...just guessing here, ...
    but perhaps a parallel installed MS-Edge/Chromium has different cache- or "virus-check-within-received stream-buffers" strategies at OS-level.

    Olaf

  24. #424
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    733

    Re: VB6 WebView2-Binding (Edge-Chromium)

    i test your demo WebView2Demo.zip

    Code:
    and this shows, that the WV.jsProp("...") also works in Property-Let-Mode (at the left-hand-side)
      btn1Caption = "Click Me..." 'change the Caption-String
      WV.jsProp("document.getElementById('btn1').innerHTML") = btn1Caption 'and assign it to the Browser-Element as the new Caption via WV.jsProp() = ...
      'just for fun, we can change the style of the btn1-Element to color='red' as well this way
      WV.jsProp("document.getElementById('btn1').style.color") = "red"
    i found not change red.but old vision work fine

  25. #425

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,454

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by xxdoc123 View Post
    i test your demo WebView2Demo.zip

    Code:
    and this shows, that the WV.jsProp("...") also works in Property-Let-Mode (at the left-hand-side)
      btn1Caption = "Click Me..." 'change the Caption-String
      WV.jsProp("document.getElementById('btn1').innerHTML") = btn1Caption 'and assign it to the Browser-Element as the new Caption via WV.jsProp() = ...
      'just for fun, we can change the style of the btn1-Element to color='red' as well this way
      WV.jsProp("document.getElementById('btn1').style.color") = "red"
    i found not change red.but old vision work fine
    This problem came up already a few times here (first time, I think - in #185):
    https://www.vbforums.com/showthread....=1#post5580698

    HTH

    Olaf

  26. #426
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    733

    Re: VB6 WebView2-Binding (Edge-Chromium)

    thanks. jsprop This function is very convenient to use。now must change my code

  27. #427
    Hyperactive Member
    Join Date
    Dec 2008
    Location
    Argentina
    Posts
    441

    Re: VB6 WebView2-Binding (Edge-Chromium)

    This was 3 steps back, the problem with the dpi has been solved, but jsProp no longer works as before, everything changed, I still don't know how to fix it. before this worked for me WV.jsProp("map.getCenter().lat()") now not anymore!
    Point #185 is not a solution, with WV.jsProp I could access a variable, if it worked fine, why did I change it?
    leandroascierto.com Visual Basic 6 projects

  28. #428

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,454

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by LeandroA View Post
    jsProp no longer works as before, everything changed,...
    Not "everything" - only jsProp shows a slightly different behaviour...

    And as explained in #185 - I had no choice in the matter ...
    (because newer Chromium-versions are now blocking eval() when used against some DOM-props).

    So, my workaround around this chromium-issue with eval() was, to now parse a "given property-string" by hand (step by step) -

    But note, that this workaround now only works on real property-sequences (and not "props with intermingled function-calls")...
    So the string still can be nested with "dots" in-between properties - but no parentheses (no func-calls) are allowed in the string.

    WV.jsProp("window.document.title") 'access on "pure" nested props still works

    WV.jsProp("map.getCenter().lat()") '...whilst this doesn't anymore, because it contains ()-identifyable, intermingled function-calls

    Quote Originally Posted by LeandroA View Post
    I still don't know how to fix it.
    It's not that difficult, to write your own little helper-functions for communication with VB6,
    as e.g. (after WV.Init was successful)...
    Code:
      With New_c.StringBuilder 'js-helpers
     
          .AddNL "function getMapCenter(){" 
          .AddNL "    var c = map.getCenter()"
          .AddNL "    return [c.lat(), c.lon()].join(';')" 'returns two values (lat and lon) in a semicolon-separated string
          .AddNL "}"
          
          WV.AddScriptToExecuteOnDocumentCreated .ToString
      End With
    Access then via WV.jsRun instead of WV.jsProp:
    Code:
      Debug.Print WV.jsRun("getMapCenter")
    Again, normally I try my very best, to not break existing functionality -
    but in this case it was the "increased security" of the chromium-engine which "broke things" (on some sites).

    Edit: What you can try, to simulate the "old behaviour" is, to run the javascript eval-function explicitely on your own like this:
    ... Debug.Print WV.jsRun("eval", "map.getCenter().lat()")
    ...meaning, that you could do a global replace of the term [ WV.jsProp( ] against [ WV.jsRun("eval", ]

    This might work on some sites (which don't enforce a "restricted eval()", like the sites delivered from from google-servers for example).

    Olaf
    Last edited by Schmidt; Jul 31st, 2023 at 10:41 AM.

  29. #429
    Hyperactive Member
    Join Date
    Dec 2008
    Location
    Argentina
    Posts
    441

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Thank you very much, this fixes it

    Private Function WV_Eval(ByVal Value As String) As String
    WV_Eval = WV.jsRun("eval", Value)
    End Function

    then replace all WV.jsProp by WV_Eval
    leandroascierto.com Visual Basic 6 projects

  30. #430
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,538

    Re: VB6 WebView2-Binding (Edge-Chromium)

    jsProp,This function has a lot of problems and bugs,

  31. #431
    Frenzied Member
    Join Date
    Aug 2020
    Posts
    1,844

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by xiaoyao View Post
    jsProp,This function has a lot of problems and bugs,
    Your reply doesn't mean anything other than misleading others, and it's not what this forum needs.

    If you think jsProp has some problems, bring them up.
    If you think jsProp has bugs, report them.

    Based on my more than 10 years of experience with RC5/RC6, Olaf's code has very few bugs, and the quality of his code is at the top level even according to the standards of Commercial software.
    Last edited by SearchingDataOnly; Aug 1st, 2023 at 12:48 AM.

  32. #432
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,538

    Re: VB6 WebView2-Binding (Edge-Chromium)

    more times,jsProp("document.title"),result is empty,and other js

    WV_Eval replace to WV.jsProp maybe ok

  33. #433
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    733

    Re: VB6 WebView2-Binding (Edge-Chromium)

    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();"




    wo can tell me why? and hao can do well?

  34. #434

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,454

    Re: VB6 WebView2-Binding (Edge-Chromium)

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

    wo can tell me why?
    WV.ExecuteScript is working asynchronously.
    And it should of course only be executed, when the Document was fully loaded
    (meaning, the call should be executed either from within WV_DocumentCompleted,
    or after that Event "came through").

    And since modern pages are able to enhance their DOM even after DocumentCompleted was signaled,
    it could very well be, that the span-element you want to click - simply "is not there yet".

    Please wrap the Selector-query in a small function, which is able to test for "existence" (of a certain, element-addressing query-string).

    E.g. you can add the 2 functions below via:
    WV.AddScriptToExecuteOnDocumentCreated _
    "function elementExists(sQuery){return document.querySelector(sQuery) ? true:false}" & vbCrLf & _
    "function clickElement(sQuery){document.querySelector(sQuery).click()}"

    And then test for existence via:
    Const sQuery As String = "#app > div > section > aside > span"
    If WV.jsRun("elementExists", sQuery) Then WV.jsRun("clickElement", sQuery) Else Debug.Print "Element doesn't exist yet..."

    HTH

    Olaf

  35. #435
    Fanatic Member
    Join Date
    Jul 2017
    Posts
    761

    Re: VB6 WebView2-Binding (Edge-Chromium)

    There is no built-in method to store the entire contexts (html and images) of a webpage locally, is there?
    I thought that since the data is already on my disk when I ask WebView2 to navigate to a certain page, I could perhaps extract the local data.

  36. #436
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,538

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Please DON'T report bugs by a review, BUT HERE:
    - https://github.com/vsDizzy/SaveAsMHT

    ######## Changelog #######

    https://github.com/vsDizzy

    CAN USE THIS?

  37. #437
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,671

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Hello, I'm struggling to find the way to download a JSon file from an URL as string.
    I need to download it using the WebView2 because I'm already using it to log-in to the site and to download some pages, and I need to send the session Cookie to be able to download the JSon, so since I was not able to get the Cookie with the method suggested here (because it appears that is no working now anymore, at least for me), I will have to get the JSon using the WebView2 itself and not by other download means.

    I tried to get it with WV.jsProp("document.body.outerText") and it kinda worked but if the JSon is too large it gets cut.
    Ideas?

  38. #438

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,454

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by Eduardo- View Post
    Hello, I'm struggling to find the way to download a JSon file from an URL as string.
    I need to download it using the WebView2 because I'm already using it to log-in to the site and to download some pages, and I need to send the session Cookie to be able to download the JSon, ...
    "in-Page" (in-document) - http-requests (aka "Ajax-Requests") are traditionally done via the XMLHttpRequest object:
    (which is quite similar in its usage, as the MS-WinHttp-COM-Object).
    https://developer.mozilla.org/en-US/...XMLHttpRequest

    In other words - don't use the Webviews "Navigate"-methods to retrieve JSON from a certain WebAPI -
    use the XHR-Object instead "from the inside" of a loaded document (e.g. encapsulated in a little pre-added js-function).

    Quote Originally Posted by Eduardo- View Post
    ...so since I was not able to get the Cookie with the method suggested here
    Just tested this here - and it seems to work as described:
    Code:
    Option Explicit
     
    Private WithEvents WV As cWebView2
    
    Private Sub Form_Load()
      Set WV = New_c.WebView2(hWnd, 0)
    End Sub
    
    Private Sub WV_InitComplete()
      WV.Navigate "https://vbForums.com", 0
    End Sub
     
    Private Sub WV_DocumentComplete()
      Debug.Print WV.jsProp("document.cookie")
    End Sub
    
    Private Sub Form_Resize()
      If Not WV Is Nothing Then WV.SyncSizeToHostWindow
    End Sub
    In case you're working against a "Google-URL" - these targets are known to torpedo the WebView2-COM-Object-support
    (the WV.AddObject-stuff ... which I need also on the inside of cWebView2, to interact with the VB-side).

    E.g. when you navigate to "https:/google.com" - then WV.jsProp and WV.jsRun won't work properly.

    Olaf

  39. #439
    PowerPoster
    Join Date
    Feb 2017
    Posts
    5,671

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Hello Olaf. It is not Google, it is a private site.

    Debug.Print WV.jsProp("document.cookie") returns an empty string.

    Maybe that it is because it is an http site (not https)?

  40. #440

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,454

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by Eduardo- View Post
    Hello Olaf. It is not Google, it is a private site.

    Debug.Print WV.jsProp("document.cookie") returns an empty string.

    Maybe that it is because it is an http site (not https)?
    No, the reason in that case is, that document.cookie only returns "regular, non-HttpOnly-cookies"
    (http-only-cookies are hidden and non-accessible via javascript)...

    You can read about the different cookie-types here, for example:
    https://dev.to/costamatheus97/battle...http-only-1n0a

    As for: "How to get to those http-only-cookies without using javascript..." -
    the WebView2 thankfully raises an Event we can use, where received resource-responses are reported
    (including a param, which transports a http-response-headers JSON-collection)...

    I've marked that Event in the following demo-code blue:
    Code:
    Private WithEvents WV As cWebView2
    
    Private Sub Form_Load()
      Set WV = New_c.WebView2(hWnd, 0)
    End Sub
    
    Private Sub WV_InitComplete()
      WV.Navigate "http://SomeDomain.com", 0
    End Sub
     
    Private Sub WV_DocumentComplete()
      Debug.Print WV.jsProp("document.cookie")
    End Sub
    
    Private Sub WV_WebResourceResponseReceived(ByVal ReqURI As String, ByVal ReqMethod As String, ByVal RespStatus As Long, ByVal RespReasonPhrase As String, ByVal RespHeaders As RC6.cCollection)
      If RespHeaders.Exists("Set-Cookie") Then Debug.Print RespHeaders("Set-Cookie")
      
    '  Dim i As Long 'alternatively, one can enumerate all response-headers on the JSON-Collection
    '  For i = 0 To RespHeaders.Count - 1
    '    Debug.Print RespHeaders.KeyByIndex(i), RespHeaders.ItemByIndex(i)
    '  Next
    End Sub
    
    Private Sub Form_Resize()
      If Not WV Is Nothing Then WV.SyncSizeToHostWindow
    End Sub
    Edit: One can also use the somwhat more modern "Fetch-API" instead of the XMLHttpRequest-Object:
    https://developer.mozilla.org/en-US/...PI/Using_Fetch

    The http-cookie should be transported back to the server automatically in these "internal requests" -
    whereas "special tokens" have to be set manually in the clientside Headers of the request (in both cases)...

    But just test it out in your own small js-functions (added in WV_Initcomplete via AddScriptToExecuteOnDocumentCreated)

    HTH

    Olaf
    Last edited by Schmidt; Sep 7th, 2023 at 04:13 PM.

Page 11 of 14 FirstFirst ... 891011121314 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