Hello!
Can you explain how to save downloaded web page to local disk?
Printable View
Hello!
Can you explain how to save downloaded web page to local disk?
Not sure, what is meant here...
(there is an interactive right-mouseclick-context-menu in the chromium-engine,
which allows to trigger "Save as..."-commands).
If it's only "plain-text-" or "plain-binary"-saving of a given URL -
then a better suited (more lightweight) helper-object is available via the winhttp 5.1 reference...
Olaf
Olaf:
I was using RC6 version: 6.0.0.9, everything is fine.
Then I upgraded to RC6 version: 6.0.0.10, my program broke.
It was broken when this line of code stopped returning anything:
I have to switch back to 6.0.0.9 and my program works again.Code:WV.jsProp("document.querySelector('input').value")
I notice there are some new features added to cWebView2, perhaps that's where the root of the problem is.
Had to adapt the jsProp-Resolver Method internally (in 6.0.10) due to "security-reasons" -
(the old version was using eval(...) to resolve the jsProp-expression, and that does not work in all cases).
What the new version still supports, is "nested Prop-Expressions" - as for example:
Debug.Print WV.jsProp("window.document.title")
But please note, that the above "nested expression" does not contain any parentheses (which indicate function-calls).
So, it has to be "pure properties" now (since I'm not using eval anymore for jsProp-evaluation internally).
To solve your problem, just add a little helper-function like e.g:
WV.AddScriptToExecuteOnDocumentCreated "function getQSValue(qsExpr){return document.querySelector(qsExpr).value}"
...before loading a document.
This will allow you, to use WV.jsRun(...) instead, to get your values:
Debug.Print WV.jsRun("getQSValue", "input")
HTH
Olaf
I just wanted to BUMP this response again to see if anyone else has successfully tried/done this (making a User Control with WV so that we can have indexed UC with multiple on one form)?
I want to replace about 17 old webbrowser controls in my VB6 program and the form has simply run out of available controls (I guess 256 is the VB6 limit). Most, if not all of them, are "hosted" on a vbalDTabControl (from vbAccelerator.com), which allows me to just set the "panel" property directly to the ucWV (user control WebView) that I created.
The code seems to actually run fine, but only first WV created actually renders anything. The rest look like they are working correctly "under the hood" (when debugging, all events are fired), but only a blue box is rendered on the screen.
Any help would be appreciated.
Thanks for a great control!
Olaf,
Another problem related to .jsRun method.
It seems that .jsRun returns the previous result if the current result is undefined?
For example,
.jsRun(js1) returns 'result of js1' if js1 works.
.jsRun(js2) returns also 'result of js1' if js2 failed.
.jsRun(js3) returns 'result of js3' if js3 works.
I was assuming that .jsRun would return something like NULL when the script fails.
Is there any possible mistake on my side? Or is there anything I don't know about .jsRun?
Thanks
I've fixed that now - returning Empty in case of a js-error (a returned js-null-value maps to VT_Empty in the COM-world).
Have not compiled and re-uploaded yet, but it will come in the next release...
In the interim you have two ways to workaround that:
1) via your own try-catch-block within your self-defined js-Function (to return a null, or an err-string in case of an error)
2) or relying on the existing, internal "try-catch"-mechanism of jsRun/jsProp
.. (which in case of 2) manifests itself in: WV.jsLastError
So, for "critical js-Calls that might fail" (and have no internal try/catch definition),
you can always add an additional line after the WV.jsRun(...) like:
If Len(WV.jsLastError) Then LogOrRaiseThe WV.jsLastError
Olaf
I Olaf.
Do you know why I can't see (and use) the cWebView2 class in Excel?
Attachment 185944
The same happens in other languages (powerbuilder for example), where I have had no problems using other RC6 classes
Regards
Hello Olaf,
First of all thank you very much for a wonderful contribution!!!
Couple of problems I am having:
1. browser.jsProp("document.getElementById('divid').innerHTML") never returns any thing. However browser.jsProp("document.documentElement.innerHTML") returns whole document html and I then have to parse through whole document to find content which I am looking for.
2. Below is my JS Code
var url = 'https://abc.com/page1';
var xhr = new XMLHttpRequest();
xhr.open('POST', url);
xhr.setRequestHeader('accept', 'application/json, text/plain, */*');
xhr.setRequestHeader('Authorization', 'token');
xhr.setRequestHeader('Content-Type', 'application/json;charset=utf-8');
xhr.setRequestHeader('content-length', '0');
xhr.setRequestHeader('Accept-Language', 'en-US,en;q=0.9');
xhr.setRequestHeader('content-type', 'application/json');
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
ret = xhr.responseText; document.getElementById('dvRes').innerHtml = xhr.responseText;
}};
var data = '';
xhr.send(data);
so when I first time do browser.ExecuteScript(MyJSCode) it works well and sets output to the specified div. But, If I have to make another xhr call or even more calls, it never even attempts to make a call (I also check network calls from Dev Tools window). So in a nutshell, it makes only one xhr call and then never goes for 2nd or 3rd one.
Any help or direct guidance will be highly appreciated!!!
Thank you!
Just a few posts above (in #186) both your questions were answered.
Your second question "indirectly" - meaning:
- encapsulate the remote-call in a proper js-helper-function
..e.g. called function RPC(URL, oData){...}
- then add this function using: WV.AddScriptToExecuteOnDocumentCreated <your js-function-string>
- then you can use this function via WV.jsRun("RPC", ...)
Olaf
Dear Olaf,
I have been using Webview2-binding for a long time. Thank you very much for your valuable creation of this library.
After I have downloaded and installed "The vbRichClient-Framework (currently at Version 6.0.10", I am in great trouble.
Although Webview2 perfectly loads the document in the picturebox, in the NavigationCompleted event, IsSuccess is always false while WebErrorStatus=0.
Am I doing something wrong or something has been chaned that I don't know.
Thank you very much for your assistance.
Have just tested this with a WV.Navigate to "https://google.com" -
and the incoming NavigationCompleted-EventParams are: IsSuccess=True, WebErrorStatus=0
In the MS-documentation for the IsSuccess-Param is stated:
...Note that WebView2 will report the navigation as 'unsuccessful' if the load for the navigation did not reach the expected completion for any reason. Such reasons include potentially catastrophic issues such network and certificate issues, but can also be the result of intended actions such as the app canceling a navigation or navigating away before the original navigation completed. Applications should not just rely on this flag, but also consider the reported WebErrorStatus to determine whether the failure is indeed catastrophic in their context.
So, maybe the site you navigate to has an outdated certificate - or undergoes several redirects?
Olaf
Hi Olaf,
RC6 Version 6.0.10 does not return values for html textbox on vb form. It does the same thing for WebView2Demo example as well.
MsgBox WV.jsProp("document.getElementById('txt1').value")
Kind Regards,
Hi Olaf,
is it possible that you offer some sort of error number or exception on calling BindTo method instead of just returning 0 or 1? I have a case of a shutdown of msedgewebview2.exe(s) after they initialize and after they create files/folders in the given user data folder. They just shut down very shortly after starting and the return value of BindTo is 0. I tried every suggestion from WebView2 forums without success, there is no trace of it in event logs, I have no idea how to proceed. I saw that .NET WebView2 library in such situations does return exceptions with meaningful messages, it would be great if you could offer similar information on BindTo errors, thanks.
Olaf
I'm experiencing a problem.
Today, out of nowhere my program suddenly ran into "couldn't initialize Webview2 binding" on startup.
The problem remains after I tried rebooting my pc, recompliling the exe, reinstalling webview2 runtime, running in the IDE, or reresgistering RC6 binaries.
On another PC of mine, there is no problem.
Cannot reproduce the behaviour on my machine -
but nevertheless have uploaded a new RC6-BaseLibs-package -
which now contains the newest version of the MS 'WebView2Loader.dll' -
as well as a slightly changed BindTo-Method, which deals more thouroughly with "compatible-versions"...
Please check it out after downloading the new package (with all Dlls) -
and re-registering RC6.dll
@Bob17
This might help also in your case - though not sure (it's still a "shot into the blue" -
because - as said - cannot reproduce the behaviour).
What helped me in this regard (in the early phases of developing it) was,
to delete the "UserFolder" completely (in case you gave it a specific location) -
or to change the location to a different UserFolder-Path with "full write-rights, and nothing else in it".
HTH
Olaf
Olaf
I'm sorry to say that after registering the new DLLs, the problem remains the same: "couldn't initialize WebView-Binding".
I'm running the Webview2Demo project.
I'm starting to doubt if it's a Win7 thing. Just recently I constantly get notification from Chrome that it will not be updated in Win7 Os.
There is a fixed version Webview2 for downloading. Is it possible to test against this?
Olaf
Good news.
By changing the browserInstallPath of the BindTo method, I've come to the results:
Microsoft.WebView2.FixedVersionRuntime.108.0.1462.46.x64 > couldn't initialize WebView-Binding
Microsoft.WebView2.FixedVersionRuntime.107.0.1418.62.x64 > No errors.
I'm running Win7 Os.
Regards
Hi Olaf,
Calling a vb6 COM dll that has RC6 WebView2 from a .NET application crashes the process (on calling BindTo method) with heap corruption error in ntdll.dll. This is reproducible, I have attached sample code with one c# forms project and one vb6 dll project. Could you please take a look and give some comments on it, maybe you can pinpoint the cause. Thanks!
I'm aware of that problem -
and .NET-compiled (32Bit-x86) Host-Processes are not the only ones who cause it...
There's also VBA (when run from within 32Bit Excel or Access.exe Processes) which has that problem.
I have currently not investigated this deeply - but my assumption is,
that a VB6-compiled 32Bit Host-Exe is initializing the vb6-runtime-dll differently on startup -
(compared to an "isolatedly loaded" VB6-COM-Dll - like the RC6 on different "Host-Exes").
In case of a VB6-compiled Host-exe the RC6-Dll "meets an already initialized vb6-runtime" (on the MainThread) -
and in case of differently compiled Host-exes, the RC6-Dll "has to initialize the vb6-runtime itself".
There is all sorts of other (threading-related things) to consider along with that -
it might be that the hosting Executables where it fails, have initialized their COM(Threads) to "MTA-mode" and not "STA-Mode".
I hesitate to invest much of my time into it - because TwinBasic offers a WebView2-Binding as well (also for VBA).
And ".NETers" have also their own "WebView2-Binding" available in a .NET-based Class-wrapper.
Is there a reason, why you want to use (32Bit only!)-VB6-compiled-COM-Dlls in a .NET-App?
Olaf
Well, I need to support such scenario where web browsing is in the COM dll and the caller is arbitrary application, possibly .NET-based. One interesting detail, if .NET app is based on Framework 3.5 or 4 then the app is not crashing!
A VB6-Host-Exe might help (which encapsulates the whole thing - including the VB6-Form you "BindTo").
You can even make this VB6-Executable an ActiveX-Exe-Project -
with your current "Dll-based Public COM-Class" exposed as a Public Class of the AciveX-Exe -
which is BTW one of the few ways, to make a VB6-Class "consumable" also by 64Bit-Host-Processes.
(remember, you cannot load a VB6-compiled 32Bit COM-Dll into a 64Bit-Process directly -
only Cross-Process-COM-calls between 64Bit-Consumer-Process and a 32Bit-ClassHost-Process allow that feat)
Olaf
Hello Olaf. You are right. By creating an ActiveX-Exe and exposing a cWebView2 wrapper as a public class of the ActiveX-exe I can use WebView2 in my PowerBuilder application without problems (something that directly using RC6 I have not achieved). Not ideal, but at least I have a choice.
Thank you very much!
Hi,
I have the same problem as Resurrected.
So Resurrected seems to solve with 'Microsoft.WebView2.FixedVersionRuntime.107.0.1418.62.x64' but i have not found the installer of this version.
Microsoft publish the latest version only.
Anybody can help me ?
The download for fixed versions is at the bottom-right-corner of this page:
https://developer.microsoft.com/en-u...edge/webview2/
Olaf
Hi Olaf,
Yes i see but it is a CAB.
How to install or use this one ? I'm lost.
Win10 has direct support for unpacking of *.cab-Archives -
otherwise use 7zip?
In any case, you should end up with an unpacked Folder, named:
..\Microsoft.WebView2.FixedVersionRuntime.107.0.1418.62.x86
somewhere on your local harddisk.
Now move that whole Folder to a place you prefer in your filesystem -
and then point the 3rd Param of the BindTo-method to that Directory-Path-(String).
Olaf
Ok Olaf,
Thank you very much and Merry Christmas !
Hello.
Is there a project / template for this so that the WebView2 can also be used as an HTML editor?
Thank you very much and Merry Christmas!
Andreas
Sure ... did you ever try-out:
WV.OpenDevToolsWindow
... after a successful WV.BindTo(...) call?
It's (in the meantime) a full-blown IDE-environment with live-changes in the "View",
as soon as you edit and save *.html and *.css files
(also including support for *.js-Debugging of course).
The DevTools-Window is highly configurable (just play around with it for a day or two) -
and it allows write-interaction with the local FileSystem, once you specify a "trusted root-folder"
(which is usually the root-folder of your "localhost" Webserver-instance - be that NodeJs or IIS or Nginx).
Olaf
Hi Olaf,
My tests:
1 - Windows 7
MicrosoftEdgeWebView2RuntimeInstallerX86 installed on Windows 7.
First try:
WV.BindTo(picWV.hWnd) => "couldn't initialize WebView-Binding"
Second try:
...
P = WV.GetMostRecentInstallPath
(WV.GetMostRecentInstallPath seems to be the right path)
WV.BindTo(picWV.hWnd), , P) => Crash of VB6
and again...
WV.BindTo(picWV.hWnd) => OK it works
2 - Windows 10
No problem it works at anytime !
A solution for Windows 7 ?
GetMostRecentInstallPath gives the path to the "Evergreen-Version" (which the "normal" MS-installer is for).
If you want to work against an older "Fixed-Version" (like the one in your *.cab-download),
you have to set:
P = "C:\some\path\to\my\unpacked\Microsoft.WebView2.FixedVersionRuntime.107.0.1418.62.x86"
and pass that P-StringVariable into the Bind-call.
Olaf
Hi Olaf,
Thank you i'll try.
Regards
Hello
I tested the demo under w7 but I'm getting this error
Attachment 186547
The reason for this was mentioned a few times already in this Codebank-Thread.
(the Event-interface was changed slightly in newer RC6-versions).
Just comment out the Event-Handler you're having problems with completely -
and then "re-select" the EventHandler from the DropDown-ComboBox at the TopRight of the IDEs CodeEditor
(in case you need this specific Event at all)...
I've not yet uploaded a new Demo-Zip, because the cWebView2.cls is still getting enhancements -
and is not yet "entirely finalized" (COM-interface-wise)...
I'll always try my best though, to not break the stuff which is currently "in use and established"...
Olaf
@paliadoyo, Bob17, Resurrected
...or anybody else who previously had problems with loading WebView2 in "other Host-Processes" like:
Excel(32Bit), .NET(32Bit), Powerbuilder(32Bit)
I think I've found (and fixed) something over the Holidays regarding "more robust BindTo/Loading" ...
Please download RC6 version 6.0.12 from the usual place and check with that (after re-registering).
Olaf
Hi Olaf,
RC6 version 6.0.12:
RC6BaseDlls.zip -> HTTP Error 404.0 - Not Found
Regards
Hi again,
If WV.BindTo(picWV.hWnd) = 0 Then MsgBox "couldn't initialize WebView-Binding": Exit Sub
Sorry but the same problem remain: "couldn't initialize WebView-Binding"
Regards
Hi again,
I tested several solutions under Windows 7 but without success.
I confirm that I have no problem under Windows 10.
On the other hand, the source code of Wolf (http://www.ww-a.de/download/WebView2-Demo.zip) works perfectly on Windows 7. However, I could not reproduce the 'BinTo' method of Wolf.
I am disappointed.
Regards
If Wolfgangs code is working (in your VB6-IDE on Win7) -
then you're doing something wrong in your "init-sequence"...
Here's a minimal Demo-Code for an empty Project with a Form1 (and a reference to RC6)
HTHCode:Option Explicit
Private WithEvents WV As cWebView2
Private Sub Form_Load()
Me.Caption = New_c.Version 'just to check, which RC6-Version is in use...
Me.Visible = True 'the FormOrPicBox.hWnd needs to be Visible, before the BindTo-call
Set WV = New_c.WebView2
If WV.BindTo(Me.hWnd) Then
WV.Navigate "https://google.com"
Else
MsgBox "Couldn't bind the WebView to the Form.hWnd"
End If
End Sub
Private Sub Form_Resize() 'ensure full coverage of the Containers ClientArea with the WebView
If Not WV Is Nothing Then WV.SyncSizeToHostWindow
End Sub
Olaf
Olaf thank you very much for trying to help me but it still doesn't work.
I have checked the registry keys (HKLM and HKCU) concerning the runtime and tried different versions of this runtime but nothing changes.
I will resolve to use it under Windows 10 even if I hate Windows 10....
It works like a charm!
As always, thank you very much for your interest and effort in solving our problems.
Regards
Hi Olaf,
Good news !
Now it works fine on Windows 7.
Code:Option Explicit
Private Cairo As cCairo
Private WithEvents WV As cWebView2
Private Sub Form_Load()
Me.Visible = True
Set Cairo = New_c.Cairo
Set WV = New_c.WebView2
Cairo.SetDPIAwareness
If WV.BindTo(Me.hWnd) = 1 Then
Me.Caption = "INIT OK"
WV.Navigate "https://google.com"
Else
MsgBox "Couldn't bind the WebView to the Form.hWnd"
End If
End Sub
Private Sub Form_Resize() 'ensure full coverage of the Containers ClientArea with the WebView
If Not WV Is Nothing Then WV.SyncSizeToHostWindow
End Sub
Hi Olaf,
I wanted to test your BindTo improvements but the vbrichclient.com is having some error 500 problems.
hello Olaf
with currently available versions 108... and 109... of Microsoft.WebView2.FixedVersionRuntime, I have a crash that takes me out of the IDE when calling the BindTo function (WV.BindTo(picWV.hWnd, 8, EdgePath, DataEdgePath, TmpLang) ). I have the same problem when compiling the project
I have no problem with version 103 and I have no problem with the Evergreen version either.
Have you experienced this?
Thank you in advance for your answer
François
On what OS do you encounter this?
Where does EdgePath point to? (a "fixed version")?
Where does DataEdgePath point to? (a truly writable location for this User)?
What happens on this machine, when you call it without any "Extra-Params":
WV.BindTo(picWV.hWnd)
Olaf
OS is Windows 10 an Windows 11 (tested on 4 computers and on several VMs)Quote:
=Schmidt;5592174]On what OS do you encounter this?
C:\ProgramData\OrdoWebView2\Microsoft.WebView2.FixedVersionRuntimeQuote:
Where does EdgePath point to? (a "fixed version")?
If i use C:\Microsoft.WebView2.FixedVersionRuntime that doesn't work either
If in these directories I put version 103.x.x.x of the Webview 2 component, it works perfectly. Newer versions 108.x.x.x and 109.x.x.x do not work
C:\ProgramData\OrdoWebView2\Microsoft.WebView2.FixedVersionRuntime\DataQuote:
Where does DataEdgePath point to? (a truly writable location for this User)?
or
C:\Microsoft.WebView2.FixedVersionRuntime\Data
it works perfectly because it uses the Evergreen version which works perfectly (and it's a 109.x.x.x version !!!)Quote:
What happens on this machine, when you call it without any "Extra-Params":
WV.BindTo(picWV.hWnd)
Does the latest fixed version 109.x.x.x available from MS work on your computers?