-
Re: VB6 WebView2-Binding (Edge-Chromium)
Hello Olaf.
I am using this excellent option of using webview2 with vb6, I have managed to make functions to interact with the elements of some websites, but I found a problem that I have been struggling with for days, this is when simulating the click() event in an Input of type File, it simply does not open the file chooser dialog, when opening devtools the following alert can be displayed "File chooser dialog can only be shown with a user activation", I understand that this is a security block, but I want to know if There is the option to bypass that restriction.
Here I show the return message in the DevTools
Attachment 191017
Best regards.
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
JoseLiza
I have managed to make functions to interact with the elements of some websites, but I found a problem that I have been struggling with for days, this is when simulating the click() event in an Input of type File, it simply does not open the file chooser dialog, when opening devtools the following alert can be displayed "File chooser dialog can only be shown with a user activation"
I understand that this is a security block...
Then don't fight it (within the Browser-Control)... ;)
The nice thing about these "Dual-Apps" is, that you can always choose the side more suited for the task -
so why not show a modal FileOpen-Dialog via VB6-code?
Olaf
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
Schmidt
Then don't fight it (within the Browser-Control)... ;)
The nice thing about these "Dual-Apps" is, that you can always choose the side more suited for the task -
so why not show a modal FileOpen-Dialog via VB6-code?
Olaf
Using the vb6 FileOpen-Dialog would not allow assigning the path of the selected file in the file type input, since I am trying to upload a file to a website.
If I'm wrong, I would appreciate if you could guide me on it.
-
Re: VB6 WebView2-Binding (Edge-Chromium)
The way I handle resizing is to set the form font to the control font and then use TextWidth with the text to determine the width and then size the control to whatever number it gives me back plus a little buffer.
It only works on one-liners though - like labels and single-line textboxes. I've never tried it with multiline textboxes.
I use it for all controls (that are one-lines) that I want to resize at run-time such as labels, check and optionboxes and single-line text boxes.
Code:
Private Function ResizeCheckBox(ByRef Check As Control, ByRef Form As Form, Optional ByRef Padding As Long = 0) As Long
Dim nWidth As Long
' Returns CheckBox width.
On Error GoTo errHandler
CopyFontFromControl Check, Form
nWidth = Form.TextWidth(Check.Caption)
nWidth = nWidth + CHECKBOX_PADDING + Padding
Check.Width = nWidth
ResizeCheckBox = nWidth
Exit Function
errHandler:
Dim nErrorNumber As Long
Dim nErrorHandlerResult As Long
Dim sError As String
Dim nErr As Long
Dim Parameters(1) As String
sError = Error
nErrorNumber = Err
Parameters(0) = "Check.Name = " & Check.NAME
Parameters(1) = "Check.Parent.Name = " & Check.Parent.NAME
nErrorHandlerResult = ErrorHandler(sError, nErrorNumber, ParameterString(Parameters), NAME & ".ResizeCheckBox(Private Function)")
Resume CleanUp
End Function
Public Function CopyFontFromControl(ByRef FromControl As Object, ByRef ToControl As Object) As Long
' Returns Error Code.
On Error GoTo errHandler
With ToControl.Font
.Bold = FromControl.Font.Bold
.Charset = FromControl.Font.Charset
.Italic = FromControl.Font.Italic
.NAME = FromControl.Font.NAME
.Size = FromControl.Font.Size
.Strikethrough = FromControl.Font.Strikethrough
.Underline = FromControl.Font.Underline
.Weight = FromControl.Font.Weight
End With
Exit Function
errHandler:
Dim nErrorNumber As Long
Dim nErrorHandlerResult As Long
Dim sError As String
Dim Parameters(1) As String
CopyFontFromControl = Err
nErrorNumber = Err
sError = Error
Parameters(0) = "FromControl.Name = " & FromControl.NAME
Parameters(1) = "ToControl.Name = " & ToControl.NAME
nErrorHandlerResult = ErrorHandler(sError, nErrorNumber, ParameterString(Parameters), NAME & ".CopyFontFromControl(Public Function)")
End Function
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
SearchingDataOnly
(From dm)
.....but the problem is that if a commercial software can only run in a Windows environment, its market demand and market share will be very low. Such softwares cannot form a solid software ecological chain, nor can they provide you with more resources.
Not quite true. Even in 2024 - some 4 years after this post - MS Windows still dominates the desktop, especially in productivity applications. And yes, there is still a smaller-than-in-the-past but re-growing market for desktop apps on Windows. Windows has always had - and likely always will - far more available software for most any conceivable desktop purpose then MAC OS and Linux combined. And I don't even want to go down the Linux mess rabbit hole - WAY too many "Distros", WAY to much incompatibility among them etc. so Linux is best left where it shines most - the server side.
One can still build, sell and maintain good quality commercial 32-bit desktop apps with VB6. I've done it not so long ago and I plan to again. My users/customers can't tell/don't know/don't care what language their tools are written in.
And now, with twinBasic up-and-coming, it's only going to get better!
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
SearchingDataOnly
(From dm)
.....but the problem is that if a commercial software can only run in a Windows environment, its market demand and market share will be very low. Such softwares cannot form a solid software ecological chain, nor can they provide you with more resources......
\
Not quite true. Even in 2024 - some 3.5 years after this post, MS Windows still dominates the desktop, especially for productivity apps. There is still a smaller-than-before but re-growing market for commercial desktop applications. Windows has always had and likely always will have a much, much wider selection of available software than MAC OS & Linux combined. And the Linux desktop mess only makes it worse i.e. WAY to many "Distros", WAY too many incompatibilities between them, endless searches for needed dependencies, etc.
One can still create, use and sell good quality commercial software with VB6. I've done it not so long ago and I plan to again. Some on this forum have also and still are.The core VB6 runtime will be supported until at least 2031 and likely beyond.
My users/customers/groupies ;) can't tell/don't know/don't care what programming language their tools are written in. They just fire 'em up and away they go.
And with twinBasic on the playing field, its just gonna get even better :).
-
Re: VB6 WebView2-Binding (Edge-Chromium)
DOCUMENT.ACTIVEELEMENT ??
Hi, Does anyone know how to use document.activeelement in webview2 please. Im struggling a bit, any code about how to set it up. Thanks very much
-
Re: VB6 WebView2-Binding (Edge-Chromium)
IT IS POSSIBLE TO EXTRAPOLATE TEXT FROM A WEB PAGE WITH WEBVIEW2. Thank you
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Hello Olaf,
can you please expose webview.defaultbackgroundcolor or show me how to access it in RC6 / WV2?
Here is what I can do with WV in .NET and which I can not do with RC6 yet:
Code:
Private Async Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim View As New WebView2()
Me.Controls.Add(View)
View.Dock = DockStyle.Fill
Me.WindowState = FormWindowState.Maximized
View.DefaultBackgroundColor = Color.Transparent
View.BringToFront()
Dim exeDirectory As String = Path.GetDirectoryName(Application.ExecutablePath)
View.Source = New Uri(Path.Combine(exeDirectory, "cssanimation.html"))
Me.FormBorderStyle = FormBorderStyle.None
Me.AllowTransparency = True
Me.BackColor = Color.Red
Me.TransparencyKey = Color.Red
Await View.EnsureCoreWebView2Async()
End Sub
This makes the browser transparent.
Or is there a way to set the defaultbackcolor any different way?
I need to have a transparent browser. This will enable me to display the browser like a screen overlay.
Currently I can not do this as this property is not exposed in the wrapper.
Thank you.
Also, I would like to point out that simply settings transparency like this...
Code:
<!DOCTYPE html>
<html>
<head>
<style>
body,
html{
background-color: transparent;
user-select: none;
margin: 0;
padding: 0;
border: 0;
font-family: 'Nunito', sans-serif;
}
canvas{
margin: 0;
padding: 0;
display: block; /* ¯\_(?)_/¯ */
touch-action: none;
background-color: rgba(0, 0, 0, 0);
}
h1{
position: absolute;
top: 50%;
left: 0;
margin: auto;
width: 100%;
text-align: center;
}
</style>
</head>
does not do the job.
The property that I am talking about causes the browser view to be really transparent: https://learn.microsoft.com/en-us/do...et-1.0.2478.35
Just in case you think that the property that I am talking about can be achieved by just defining it in html.
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Yet another question:
I want to subclass the wv2 window.
I want to make it transparent, but I still the mouse move events, but it should also pass the window mesages on.
What I did was to make me the hosting window layered and then I used subclassing.
I received all the windows messages, and ignored the mouse clicks on the form, and I used the mouse move events as the browser required these in this case, but I also passed these on.
However, this did not work as the hostHwnd is not what is required to subclass the messages that the browser receives I think.
If anybody knows how to handle such a task, please let me know.
Thank you.
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Hello Olaf,
In addition to extension management, would it be possible to integrate the asynchronous functions PrintAsync and PrintToPdfAsync into the cWebView2 component of the upcoming RC6 version?
Simply integrating these functions (without defining CoreWebView2PrintSettings) would allow for the automation of certain printing tasks.
Thank you for your response.
Sincerely,
François
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Hi Olaf,
I have compiled your demo (WebView2Demo.zip) using the VB6 UI running on Win XP in order to test the exe on Win 10 and 11. It appears to be working correctly but in order to create the exe I had to rem out two of your event handlers which both generate the same error:
Procedure declaration does not match description of event or procedure having the same name
'Private Sub WV_AcceleratorKeyPressed(ByVal KeyState As eWebView2AccKeyState, ByVal IsExtendedKey As Long, ByVal WasKeyDown As Long, ByVal IsKeyReleased As Long, ByVal IsMenuKeyDown As Long, ByVal RepeatCount As Long, ByVal ScanCode As Long, IsHandled As Long)
'Debug.Print "WV_AcceleratorKeyPressed"
'End Sub
'Private Sub WV_NavigationCompleted(ByVal IsSuccess As Long, ByVal WebErrorStatus As Long)
'Debug.Print "WV_NavigationCompleted"
'End Sub
Do you know what is wrong here and also does your comment ['*** the rest of the EventHandlers below, are raised by the WebView-instance itself] mean that they are not needed anyway?
Thanks,
Mike
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
misar
... I had to rem out two of your event handlers which both generate the same error:
Procedure declaration does not match description of event or procedure having the same name
Have redefined the Interface since writing the demo... (e.g. in the two events - some of the Long-Param-Flags are now Booleans) -
just re-select (after commenting out) these EventHandlers from the DropDown-Combobox again for correct Param-population...
Quote:
Originally Posted by
misar
Do you know what is wrong here and also does your comment ['*** the rest of the EventHandlers below, are raised by the WebView-instance itself] mean that they are not needed anyway?
As with most Events - some of them are needed, some of them are left untouched...
Which sub-set of them ends up being used, depends on the concrete scenario at hand...
Olaf
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Thanks Olaf.
If anyone else has the same problem these are the corrected routines.
Private Sub WV_AcceleratorKeyPressed(ByVal KeyState As RC6.eWebView2AccKeyState, ByVal IsExtendedKey As Boolean, ByVal WasKeyDown As Boolean, ByVal IsKeyReleased As Boolean, ByVal IsMenuKeyDown As Boolean, ByVal RepeatCount As Long, ByVal ScanCode As Long, IsHandled As Boolean)
Debug.Print "WV_AcceleratorKeyPressed"
End Sub
Private Sub WV_NavigationCompleted(ByVal IsSuccess As Boolean, ByVal WebErrorStatus As Long)
Debug.Print "WV_NavigationCompleted"
End Sub
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Hello.
I have a quick question. In some old VB6 projects I used AutoComplete to connect a textbox with the history of IE. Is this also possible with WebView2 and if so how.
Old VB6 Code:
On the Form
Code:
Function EnableAutoComplete(hwnd As Long, dwFlags As Long) As Boolean
On Error GoTo Err1
SHAutoComplete hwnd, dwFlags
EnableAutoComplete = True
Exit Function
Err1:
EnableAutoComplete = False
End Function
Modul
Code:
Option Explicit
Public Declare Function SHAutoComplete Lib "shlwapi" (ByVal hwnd As Long, ByVal dwFlags As Long) As Long
'API constants
Public lngRet As Long
' // Currently (SHACF_FILESYSTEM | SHACF_URLALL)
Public Const SHACF_DEFAULT = &H0
' // This includes the File System as well as the rest of the shell (Desktop\My Computer\Control Panel\)
Public Const SHACF_FILESYSTEM = &H1
' // URLs in the User's History
Public Const SHACF_URLHISTORY = &H2
' // URLs in the User's Recently Used list.
Public Const SHACF_URLMRU = &H4
' // URLs in the User's Recently Used list.
Public Const SHACF_USETAB = &H8
' // Don't AutoComplete non-File System items.
Public Const SHACF_FILESYS_ONLY = &H10
Public Const SHACF_URLALL = (SHACF_URLHISTORY Or SHACF_URLMRU)
' // Ignore the registry default and force the feature on.
Public Const SHACF_AUTOSUGGEST_FORCE_ON = &H10000000
' // Ignore the registry default and force the feature off.
Public Const SHACF_AUTOSUGGEST_FORCE_OFF = &H20000000
' // Ignore the registry default and force the feature on.
' (Also know as AutoComplete)
Public Const SHACF_AUTOAPPEND_FORCE_ON = &H40000000
' // Ignore the registry default and force the feature off.
' (Also know as AutoComplete)
Public Const SHACF_AUTOAPPEND_FORCE_OFF = &H80000000
Many thanks in advance.
Andreas
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Olaf,
Thanks again for the WebView2 control. This has really given new life to an old VB6 app (and developer :)
I have a use for InPrivate mode or Incognito mode. I was wondering if there is an easy way to turn this on? My app logs into the same site multiple times with different credentials, and I have found that I have to make it logout/login for it to switch between them. I want to split this into 2 WVs and separately login to each.
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Hello Olaf,
Since I last posted I have used the WebView2 control very successfully to display web pages in my programs. I would now like to extend that to extracting the html content of a page (to a variable or save to file) after it has displayed. This is required with pages that use code to generate their content from a database (eg an Amazon S3 bucket). I assume it requires a script but could not work out how to do it from the examples in the demo. Is it possible and could you give me an example?
Thanks
Update:
I already had the solution I need:
Code:
WV.jsProp("document.body.outerText")
but forgot that with a large amount of content the page needs a long time to complete!
-
Re: VB6 WebView2-Binding (Edge-Chromium)
misar,
1. try using .jsProp("document.documentElement.innerHTML") - i do this all the time to pull out information i need from web pages. you just need to make sure that the document is "settled" and fully loaded.
2. you actually replied to *my* post (just above) that asks about implementing "incognito" mode. I believe you should Reply to the very first post, so that Olaf is alerted.
HTH!
:)
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Thanks BooksRUs,
WV.jsProp("document.body.outerText") is sufficient for my present need (I just want to search the page content for specific text) but your suggestion is useful for future reference. It is easy to find lists of the DOM components but I have never come across clear descriptions distinguishing the specific data captured with different permutations. Hence I resort to trial and error to extract what I need!
-
Re: VB6 WebView2-Binding (Edge-Chromium)
I am working with a website (https://bus.data.tfl.gov.uk/) which generates a file list from the contents of a large Amazon S3 data bucket. There is a substantial delay between the navigation completing and completion of the document that I want to capture. I thought that using Sub WV_DocumentComplete in Olaf's demo would deal with this but it fires immediately after Sub WV_NavigationCompleted. Is there a way to detect the true document completion? At present I work around this with a loop which checks the document size until it remains constant.
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
misar
I am working with a website (
https://bus.data.tfl.gov.uk/) which generates a file list from the contents of a large Amazon S3 data bucket. There is a substantial delay between the navigation completing and completion of the document that I want to capture. I thought that using Sub WV_DocumentComplete in Olaf's demo would deal with this but it fires immediately after Sub WV_NavigationCompleted. Is there a way to detect the true document completion? At present I work around this with a loop which checks the document size until it remains constant.
I tested and the event that keeps firing is WV_WebResourceResponseReceived.
Maybe you could check when that event stops firing.
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
Eduardo-
I tested and the event that keeps firing is WV_WebResourceResponseReceived.
Maybe you could check when that event stops firing.
What are the correct parameters?
Code:
WV_WebResourceResponseReceived(ByVal ReqURI As String, ByVal ReqMethod As String, ByVal RespStatus As Long, ByVal RespReasonPhrase As String, ByVal RespHeaders As RC6.cCollection)
gives an error.
-
Re: VB6 WebView2-Binding (Edge-Chromium)
It must start with "Private Sub".
The control adds the correct code automatically (I have no idea what you did).
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
Eduardo-
It must start with "Private Sub".
The control adds the correct code automatically (I have no idea what you did).
I started it with "Private Sub". The compiler throws an incorrect parameter error. I assumed this routine posted earlier in the thread had the correct parameters:
Code:
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)
On Error Resume Next
Text2.Text = Text2.Text & RespHeaders & vbNewLine
End Sub
-
Re: VB6 WebView2-Binding (Edge-Chromium)
I have it working in one project, and it is the same:
Code:
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)
' (code)
End Sub
I'm using RC6 version 6.00.0014
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
Eduardo-
I'm using RC6 version 6.00.0014
I'm using RC6 version 6.0.0.15 with the code from Olaf's demo. Apart from WV_WebResourceResponseReceived everything is compiling correctly.
The version history says:
version 6.0.0.15
- cWebView2: now using *App-specific* UserData-Folders, in case the UserData-Param was left out in the Bind-Method
- cSimplePSD: a bit of hardening, to properly cooperate with a "wider range of PSD-Files"
- RC6Widgets got a new cwAlphaImg Widget
-
1 Attachment(s)
Re: VB6 WebView2-Binding (Edge-Chromium)
This example works for me:
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
Eduardo-
This example works for me:
Your example also works for me. The difference was the line Static c As Long
- I added that to the routine and now my code also compiles and runs correctly.
Many thanks for your help. :)
Edit
After looking at this more carefully I realised that the line "Static c As Long" is irrelevant to my code so I deleted it
- and of course the routine still worked OK.
I cannot understand what changed as previously I made several attempts to get apparently identical code to work. :confused:
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
misar
I cannot understand what changed as previously I made several attempts to get apparently identical code to work. :confused:
Sometimes there are mysteries... :afrog:
The event handler declaration that you pasted here was exactly the same.
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
BooksRUs
Olaf,
Thanks again for the WebView2 control. This has really given new life to an old VB6 app (and developer :)
I have a use for InPrivate mode or Incognito mode. I was wondering if there is an easy way to turn this on? My app logs into the same site multiple times with different credentials, and I have found that I have to make it logout/login for it to switch between them. I want to split this into 2 WVs and separately login to each.
Just bumping this... hopefully someone else has a need for this also. Before i posted before, and again just now, I tried passing different options for the parameter additionalBrowserArguments. I tried:
"--enable-features=incognito"
"--disable-features=msSmartScreenProtection"
"--enable-features=incognito --disable-features=msSmartScreenProtection"
None of which appear to do the job, even though no complaints from the New_c.WebView2 call.
Any pointers would be great.
Thanks!
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
BooksRUs
Just bumping this... hopefully someone else has a need for this also. Before i posted before, and again just now, I tried passing different options for the parameter additionalBrowserArguments. I tried:
"--enable-features=incognito"
"--disable-features=msSmartScreenProtection"
"--enable-features=incognito --disable-features=msSmartScreenProtection"
None of which appear to do the job, even though no complaints from the New_c.WebView2 call.
Any pointers would be great.
Thanks!
Have you tried using a different user data folder for each instance? You can then delete the "incognito" user folder on shutdown yourself. This approach is mentioned at the following links, but I haven't tried it myself:
https://stackoverflow.com/questions/...n-privacy-mode
https://github.com/MicrosoftEdge/Web...ack/issues/779
I also found mention of an IsInPrivateModeEnabled option in the second thread, so maybe that's an avenue to explore?
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
jpbro
Have you tried using a different user data folder for each instance? You can then delete the "incognito" user folder on shutdown yourself. This approach is mentioned at the following links, but I haven't tried it myself:
https://stackoverflow.com/questions/...n-privacy-mode
this is how i work to create a private browsing mode !
Code:
Option Explicit
Private WithEvents WV As cWebView2
....
'when loading the container
Set WV = New_C.WebView2 'create the instance
Load picWV(1)
picWV(1).Visible = True
....
If mPrivate = True Then
DataEdgePath = AddDirSep(Environ("TEMP")) & "MyAppName\" & CreateGUIDString(True) 'The navigation is in private mode and begins in a directory free of any data which will be destroyed at the end of navigation
Else
DataEdgePath = fGetSpecialFolderLocation(CSIDL_COMMON_APPDATA) & "\"MyAppName\Data\" & Environ$("Username")
End If
MD DataEdgePath
.....
WV.BindTo picWV(1).hWnd, m_InitTimeOut, , DataEdgePath, TmpLang, mAllowSingleSignOnUsingOSPrimaryAccount
.....
'before unloading the container
Set WV = Nothing
Unload picWV(1)
If mPrivate = True Then KillFiles DataEdgePath, True
....
Private Sub MD(DirPath As String)
If InStr(DirPath, "\") > 0 Then
DirPath = AddDirSep(DirPath)
On Error Resume Next
Dim strTmp$(), f%, StrPath$
strTmp$ = Split(DirPath, "\")
For f% = 0 To UBound(strTmp()) - 1
StrPath$ = StrPath$ & strTmp(f) & "\"
MkDir StrPath
Next f%
Else
MkDir DirPath
End If
End Sub
Private Function AddDirSep(strPathName As String) As String
If strPathName = "" Then Exit Function
strPathName = RTrim$(strPathName)
If Right$(strPathName, 1) <> "\" Then
strPathName = strPathName & "\"
End If
AddDirSep = strPathName
End Function
........................................................................
CreateGUIDString(True) return an unique GUID
KillFiles delete all Folder,subFoldes and Files
fGetSpecialFolderLocation retrieve specials Folders Paths
...see VBForums CodeBank...
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Dear Olaf,
I have been using your product for a long time without problems.
I have been loading Facebook page into WV and getting the body.innerhtml without any problem. Now, when I try to get the body.innerhtml, empty string is returned. I am waiting to get the html, but nothing returned. The code is as follows:
Code:
WVerrorflag = False
WV.Navigate "about:blank"
WV.Navigate cururl$
If WVerrorstatus <> 0 Or WV.DocumentURL = "chrome-error://chromewebdata/" Then
Stop
Else
retcount = 0
Do
retcount = retcount + 1
If retcount > 2 Then Stop
curhtml$ = WV.jsProp("document.body.innerHTML")
If curhtml$ <> "" Then Exit Do
Wait 1
Loop
End If
Is there a way to get the html from Facebook page?
Thank you for your kind help.
Regards
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Dear Olaf,
Is is possible to get the Content of the Response in
WebResourceResponseReceived
event?
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
saturnian
this is how i work to create a private browsing mode !
:)
Appreciate you guys putting me on the right path! It appears that using a different User Data Folder on each call *does* do the trick, so that the WV's run in separate folders. The unfortunate "side effect" is that it doesn't remember some of the user's default or previous selections, but the ability to run multiple separate instances far outweighs the inconvenience.
Thanks!!
Now, if I could just figure out how to keep/fix the ZoomFactor, I would be golden... if I hold control and roll the mouse to zoom in/out on a website, then go to a different place on the same site, the zoom resets.
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
BooksRUs
Appreciate you guys putting me on the right path! It appears that using a different User Data Folder on each call *does* do the trick, so that the WV's run in separate folders.
I was just looking at the WebView2 browser flags/params for another purpose and notice that there is a "--incognito" flag (maybe it is new?):
Code:
incognito Forces Incognito mode even if user data directory is specified by using the --user-data-dir flag.
Might be worth trying that to see if it keeps all of the user's existing settings but doesn't save/overwrite anything during/after the session.
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
BooksRUs
Now, if I could just figure out how to keep/fix the ZoomFactor, I would be golden... if I hold control and roll the mouse to zoom in/out on a website, then go to a different place on the same site, the zoom resets.
Regarding the zoom factor, it looks like others have reported the same problem:
https://github.com/MicrosoftEdge/Web...ck/issues/3459
I haven't had a chance to investigate, but that thread mentioned that there may be a solution in this thread:
https://github.com/MicrosoftEdge/Web...ck/issues/2451
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
jpbro
I was just looking at the WebView2 browser flags/params for another purpose and notice that there is a "--incognito" flag (maybe it is new?):
Code:
incognito Forces Incognito mode even if user data directory is specified by using the --user-data-dir flag.
Might be worth trying that to see if it keeps all of the user's existing settings but doesn't save/overwrite anything during/after the session.
I think I had found the same documentation previously... I have tried passing each one of these as the additionalBrowserArguments parameter:
- "--disable-features=msSmartScreenProtection"
- "--enable-features=incognito"
- "--enable-features=incognito --disable-features=msSmartScreenProtection"
- "incognito"
- "--incognito"
None of these worked for me. These are all from scouring the Internet trying to make this happen. Perhaps my formatting is off for passing in these parameters.
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
jpbro
:afrog:
Eureka!
After digging into the 2nd link, it appears that I can now keep the same Zoom Factor between navigations (programmatically anyway):
Code:
dim ZoomFactor as double
...
' Before navigating to another page/site, save current ZF
ZoomFactor=WV.ZoomFactor
WV.ZoomFactor = ZoomFactor + .001
'navigate to site here
...
WV.ZoomFactor = ZoomFactor
I tried something similar before, but I think it needs a value that is *different* than what it currently is, in order to actually do anything. So bumping it by a little, navigating, and bumping it back by a little actually makes the WV respond.
:)
-
Re: VB6 WebView2-Binding (Edge-Chromium)
can anybody please look into this thread https://www.vbforums.com/showthread....C6-Help-please and advise?
Thankyou!
-
Re: VB6 WebView2-Binding (Edge-Chromium)
how to use --disable-web-security??
can't runjs to frame document.
Uncaught DOMException: Failed to read a named property 'document' from 'Window': Blocked a frame with origin "https://**.com" from accessing a cross-origin frame.
at <anonymous>:2:64
???? @ VM1604:2
var iframe = document.querySelector("#pt_iframe");
error here:
var iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Did you try passing the switch to the additionalBrowserArguments parameter on the BindTo method?
e.g.:
Code:
MyWebView2.BindTo MyHwnd, , , , "--disable-web-security"
?
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
jpbro
Did you try passing the switch to the additionalBrowserArguments parameter on the BindTo method?
e.g.:
[/code]
?
thank you
how to get response data by vb6?
how to
c# like " var response = await e.Request.GetResponseAsync();"
how to get all url data ,like fiddler.exe or httpwatch.exe?
Code:
private async void InitializeWebView2()
{
webView2 = new WebView2();
webView2.Dock = DockStyle.Fill;
this.Controls.Add(webView2);
await webView2.EnsureCoreWebView2Async(null);
webView2.CoreWebView2.WebResourceRequested += CoreWebView2_WebResourceRequested;
webView2.CoreWebView2.Navigate("https://example.com");
}
private async void CoreWebView2_WebResourceRequested(object sender, Microsoft.Web.WebView2.Core.CoreWebView2WebResourceRequestedEventArgs e)
{
// ??????
if (e.Request.Uri.Contains("specific-url-to-monitor"))
{
// ??????
var response = await e.Request.GetResponseAsync();
var responseStream = await response.GetContentAsync();
using (var reader = new System.IO.StreamReader(responseStream))
{
var responseContent = await reader.ReadToEndAsync();
// ??????
Console.WriteLine("Response content: " + responseContent);
}
}
}
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Attachment 194487How do I trigger the ?start learning??“????”? button in VB6.0 version webview2?
-
Re: VB6 WebView2-Binding (Edge-Chromium)
now i have a question
Code:
Private Sub WV_DocumentComplete()
WV.jsRunAsync "LoadNextVideo" 'i used this js command to find video ,but Data is not available?
but if i set this command in commandbutton and click ?i wil get the data
Private Sub cmdCommand2_Click()
infoLab.Caption = flag
WV.jsRunAsync "LoadNextVideo"
End Sub
why ?
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Perhaps the "data" loads asynchronously after the main document has finished loading? You might need to add a small helper script to look for a specific element that is injected into the DOM asynchronously and then call LoadNextVideo when it is found.
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
jpbro
Perhaps the "data" loads asynchronously after the main document has finished loading? You might need to add a small helper script to look for a specific element that is injected into the DOM asynchronously and then call LoadNextVideo when it is found.
I'm not very proficient in js and don't know how to wait for data asynchronously
Code:
Do
Wait 1000
Debug.Print flag & "....."
If WV.jsProp("document.querySelector('[class=""videotitle""]').innerText") = "ok" Then
Debug.Print "we can se the title of the video?now run LoadNextVideo "
WV.jsRunAsync "LoadNextVideo" '
Exit Do
End If
Loop
Still no data is available
-
Re: VB6 WebView2-Binding (Edge-Chromium)
I know Olaf has already advised a way to pull http-only cookies in #440 like below
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
However, some modern websites (cannot share link) are using different ways to set secure cookies. Hence, they're not accessible the way Olaf recommended in #440. So I tried by directly accessing browser's cookies using following code:
Code:
WV.CallDevToolsProtocolMethod "Network.getAllCookies", "{}"
Problem is that CallDevToolsProtocolMethod does not return anything. So just cannot receive response which I need. So, is there a workaround I could receive response from CallDevToolsProtocolMethod method or an alternate but solid way to pull all the cookies (including http-only ones).
Thankyou so much!
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Well the underlying call does return something, through an async event completed interface, the problem with closed source wrappers is you're going to have trouble getting it since the author has vanished. Might be able to figure out a way to get a pointer to the underlying ICoreWebView2 interface to call it yourself
Code:
Interface ICoreWebView2 Extends IUnknown
...
Sub CallDevToolsProtocolMethod(ByVal methodName As LongPtr, ByVal parametersAsJson As LongPtr, ByVal handler As ICoreWebView2CallDevToolsProtocolMethodCompletedHandler)
Interface ICoreWebView2CallDevToolsProtocolMethodCompletedHandler Extends IUnknown
Sub Invoke(ByVal errorCode As Long /* HRESULT */, ByVal result As LongPtr /* LPWSTR */)
End Interface
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
BilalAhmed
I
However, some modern websites (cannot share link) are using different ways to set secure cookies. Hence, they're not accessible the way Olaf recommended in #440. So I tried by directly accessing browser's cookies using following code:
Code:
WV.CallDevToolsProtocolMethod "Network.getAllCookies", "{}"
Problem is that CallDevToolsProtocolMethod does not return anything. So just cannot receive response which I need. So, is there a workaround I could receive response from CallDevToolsProtocolMethod method or an alternate but solid way to pull all the cookies (including http-only ones).
Thankyou so much!
If you add the following code to your project:
Code:
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)
Debug.Print ReqURI, ReqMethod, RespStatus, RespReasonPhrase, RespHeaders.SerializeToJSONString
End Sub
And then call WV.CallDevToolsProtocolMethod "Network.getAllCookies", "{}" do you see any of the cookie data you are looking for in the Immediate window?
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Thank you jpbro, but if you could read my original message, you will notice that I have already tried this event. So to answer your question, unfortunately that doesnt work for me!
Thank you so much!!!
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Didn't know if you tried it with WV.CallDevToolsProtocolMethod "Network.getAllCookies", "{}", because I see the event fires multiple times and returns a lot of data when calling it against some example sites, but obviously I can't test with your site since you are unable to provide it. Hoped one or more of the firings would include your special Cookie(s).
-
Re: VB6 WebView2-Binding (Edge-Chromium)
My guess is that WV.CallDevToolsProtocolMethod "Network.getAllCookies", "{}" invokes JSAsyncResult event (only a guess, not really sure). But it doesnt bring anything to "WebResourceResponseReceived" and I think reason is obvious, WebResourceResponseReceived takes care only top level post/get/put/patch requests and listens to them. Whereas CallDevToolsProtocolMethod performs a low level operations and talks directly to the browser (Like selenium does). You're seeing so many calls being fired because several analytics softwares and some JS based sites keep refreshing data on the backend and, that is not possible without making a get/post etc.. requests which WebResourceResponseReceived event captures.
So to 100% be sure, I carefully tested your code but, without luck!
Thankyou so much!
-
Re: VB6 WebView2-Binding (Edge-Chromium)
The method RC6 is wrapping here is ICoreWebView2 -> Sub CallDevToolsProtocolMethod(ByVal methodName As LongPtr, ByVal parametersAsJson As LongPtr, ByVal handler As ICoreWebView2CallDevToolsProtocolMethodCompletedHandler)
The results are returned to your implementation of ICoreWebView2CallDevToolsProtocolMethodCompletedHandler. RC6 does not look to have a wrapper for that, though I haven't looked too thoroughly-- see if a name like that exists in the events.
Failing that, see if RC6 allows you to get a pointer to its internal ICoreWebView2 interface; if you can get such a pointer, you can use oleexp.tlb for the interfaces to invoke the command manually to your own implementation of the completion handler.
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Okay Faflone,
You really sound logical but, unfortunately could not get a hold on anything you recommended. I also tried to see if WV exposes somthing by following 3 functions
Code:
Private Sub GetWebView2Pointer()
Dim rawPtr As Long
Dim WVPtr As Long
Dim possibleVTablePtr As Long
' Step 1: Get pointer to the WV object
WVPtr = ObjPtr(WV)
' Step 2: Read the first 4/8 bytes at the object's address
' This may be the vtable or a pointer to internal struct
CopyMemory possibleVTablePtr, ByVal WVPtr, LenB(rawPtr)
' Print it for inspection
Debug.Print "WV ObjPtr = &H" & Hex$(WVPtr)
Debug.Print "First value at WV (possible vtable/internal struct) = &H" & Hex$(possibleVTablePtr)
' Try also to read 2nd level indirection if necessary:
Dim possibleWebView2Ptr As Long
CopyMemory possibleWebView2Ptr, ByVal possibleVTablePtr, LenB(rawPtr)
Debug.Print "Value pointed by 1st value = &H" & Hex$(possibleWebView2Ptr)
End Sub
Private Sub ScanWVMemory()
Dim baseAddr As Long
baseAddr = ObjPtr(WV)
Dim i As Long
Dim Value As Long
Debug.Print "Scanning memory starting at &H" & Hex$(baseAddr)
For i = 0 To 60 Step 4
CopyMemory Value, ByVal (baseAddr + i), 4
Debug.Print "Offset +" & Hex$(i) & ": &H" & Hex$(Value)
Next i
End Sub
Private Sub DumpWVStrings()
Dim baseAddr As Long
baseAddr = ObjPtr(WV)
Dim addr As Long
Dim tmpStr As String
Dim i As Long
For i = 0 To 200 Step 4
CopyMemory addr, ByVal baseAddr + i, 4
If addr > &H10000 And addr < &H7FFFFFFF Then
On Error Resume Next
tmpStr = Space$(200)
CopyMemory ByVal StrPtr(tmpStr), ByVal addr, 200
Debug.Print "Offset +" & Hex(i) & ": "; Left$(tmpStr, 100)
End If
Next i
End Sub
But this failed too. All it returned (especially "DumpWVStrings") just garbage :(
So probably Olaf may be able to help?
Thankyou so much!
Quote:
Originally Posted by
fafalone
The method RC6 is wrapping here is ICoreWebView2 -> Sub CallDevToolsProtocolMethod(ByVal methodName As LongPtr, ByVal parametersAsJson As LongPtr, ByVal handler As ICoreWebView2CallDevToolsProtocolMethodCompletedHandler)
The results are returned to your implementation of ICoreWebView2CallDevToolsProtocolMethodCompletedHandler. RC6 does not look to have a wrapper for that, though I haven't looked too thoroughly-- see if a name like that exists in the events.
Failing that, see if RC6 allows you to get a pointer to its internal ICoreWebView2 interface; if you can get such a pointer, you can use oleexp.tlb for the interfaces to invoke the command manually to your own implementation of the completion handler.
-
Re: VB6 WebView2-Binding (Edge-Chromium)
If you're looking for an alternative, there's always twinBasic. It comes with an open source(-ish?) WebView2 implementation on top of a closed-source language/compiler that's mostly VB6 compatible. It's getting more compatible by the day and it only costs $35 USD/month, forever. Sure, it’s also a one-man show, but the "one man" is still really active compared to the other "one man", and this time it's different...If either you or he runs out of money, the whole thing just stops working completely ;)
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Yeah it doesn't seem a method was included to get the pointer that you need, leaving only options not worth the trouble. Might want to use the twinBASIC WebView2 control; if you're not ready to switch to tB I've wrapped it in an ActiveX control that works in VB6/VBA/etc. It comes with an event to receive the results of the call you're looking for by default with no need for modification. Switching to that will be easier than trying to dig out the pointer.
---
Quote:
If you're looking for an alternative, there's always twinBasic. It comes with an open source(-ish?) WebView2 implementation on top of a closed-source language/compiler that's mostly VB6 compatible. It's getting more compatible by the day and it only costs $35 USD/month, forever. Sure, it’s also a one-man show, but the "one man" is still really active compared to the other "one man", and this time it's different...If either you or he runs out of money, the whole thing just stops working completely
Maybe I missed the sarcasm but the idea either your code or the tB IDE/compiler just 'stops working completely' because either side runs out of money is absurdly false. There's a free community edition where the only limitation is a splash screen on x64 binaries, and no LLVM optimization (barely any of it implemented yet). As the "free" suggests, this costs $0 per month, not $35 per month. If you do get a premium subscription then stop paying, it just reverts to the community edition. Nothing stops working. And your binaries stay as is, there's no license checks in your code; an exe built with an active subscription will remain splashscreen free forever. If Wayne runs out of money, worst case is tB stays as it is now, already far ahead of VB6 in features and complete enough you can work around bugs and unimplemented parts. And that's if it happens soon before tB leaves Beta. Once it hits v1.0 the source goes into escrow to be released if abandoned.
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
fafalone
Yeah it doesn't seem a method was included to get the pointer that you need, leaving only options not worth the trouble. Might want to use the twinBASIC WebView2 control; if you're not ready to switch to tB I've
wrapped it in an ActiveX control that works in VB6/VBA/etc. It comes with an event to receive the results of the call you're looking for by default with no need for modification. Switching to that will be easier than trying to dig out the pointer.
---
Maybe I missed the sarcasm but the idea either your code or the tB IDE/compiler just 'stops working completely' because either side runs out of money is absurdly false. There's a free community edition where the only limitation is a splash screen on x64 binaries, and no LLVM optimization (barely any of it implemented yet). As the "free" suggests, this costs $0 per month, not $35 per month. If you do get a premium subscription then stop paying, it just reverts to the community edition. Nothing stops working. And your binaries stay as is, there's no license checks in your code; an exe built with an active subscription will remain splashscreen free forever. If Wayne runs out of money, worst case is tB stays as it is now, already far ahead of VB6 in features and complete enough you can work around bugs and unimplemented parts. And that's if it happens soon before tB leaves Beta. Once it hits v1.0 the source goes into escrow to be released if abandoned.
Ahhh...
you may be right your proposal Fafalone. But the problem under discussion is a smaller part of a large project (though very important). So it may take ages to port all the project and its dependencies in TB. Though I need the solution real quick but, I think at this moment, I should wait for Olaf's response with the hopes that he will come back soon.
Thankyou so much!
-
Re: VB6 WebView2-Binding (Edge-Chromium)
The control I posted is built in tB but for VB6. It compiles an ocx control you'd use in VB6 like any other.
If you wanted to move the entire project to tB... The code should continue to work as is; tB is backwards compatible with VB6, there are no major rewrites like moving to another language. Ocx controls/dlls your project uses will work too. At most you might need to work around some bugs and a handful of missing capabilities; the only thing to actually rewrite is if you use VB internals hacks, which can be replaced with something simpler e.g. if you have a self-subclass think, tB supports AddressOf on class members so you'd just need a simple SetWindowSubclass call.
Olaf hasn't been heard from in months now so the odds he'll return soon and quickly make a new RC6 version with the feature you want aren't great.
-
Re: VB6 WebView2-Binding (Edge-Chromium)
Quote:
Originally Posted by
fafalone
Maybe I missed the sarcasm but the idea either your code or the tB IDE/compiler just 'stops working completely' because either side runs out of money is absurdly false. There's a free community edition where the only limitation is a splash screen on x64 binaries, and no LLVM optimization (barely any of it implemented yet). As the "free" suggests, this costs $0 per month, not $35 per month. If you do get a premium subscription then stop paying, it just reverts to the community edition. Nothing stops working. And your binaries stay as is, there's no license checks in your code; an exe built with an active subscription will remain splashscreen free forever. If Wayne runs out of money, worst case is tB stays as it is now, already far ahead of VB6 in features and complete enough you can work around bugs and unimplemented parts. And that's if it happens soon before tB leaves Beta. Once it hits v1.0 the source goes into escrow to be released if abandoned.
You did miss some sarcasm ;)
That said, unless I've misunderstood something, you can't build new stuff, fix old stuff, or release updates unless you keep paying the monthly fee indefinitely. A splash screen might be fine for hobby projects, but not much else.
If Wayne runs out of money tomorrow, does the tB IDE keep running at your current license level forever, or are you out of luck?
Quote:
Originally Posted by
fafalone
Once it hits v1.0 the source goes into escrow to be released if abandoned.
That's the promise, but there's no way to know if it will actually be kept, nor if it will be able to be independently verified should it ever come into play (again, unless I've missed something).
For the record, I've had a yearly pro subscription to tB since the first or second month it was offered, and I've "bought Wayne a coffee" every month since that option was added too. I've been a financial supporter of tB from early on, and I genuinely believe it's the best shot we've ever had at true VB6 successor.
But I also think it's a risky proposition for non-hobbyist development at this stage. And if we're being intellectually honest, the same arguments that have been/are being used against RC6 can and should be applied to tB as well.