WebView2
Re: 2.0-beta.1 - WebView2
Here's my history on the topic (along with the real answers by Lexikos) - viewtopic.php?f=82&t=80037&hilit=webview
Re: 2.0-beta.1 - WebView2
I've seen this, but it's not so convenient to use. And it will affect other objects.
Re: 2.0-beta.1 - WebView2
Hi,
I have tried example one and get this error message:
I can just keep going and it works.
I can't find the vercompare function anywhere.
Did I miss something?
I have tried example one and get this error message:
Warning in #include file "C:\Users\xx\Desktop\webview\Lib\WebView2\WebView2.ahk":
This variable appears to never be assigned a value.
Specifically: local VerCompare
Line#
..
031: Loop Files "C:\Program Files (x86)\Microsoft\EdgeWebView\Application\*", "D"
---> 032: If RegExMatch(A_LoopFilePath, '\\([\d.]+)$', &m) && VerCompare(m[1], ver) > 0
033: edgeruntime := A_LoopFileFullPath, ver := m[1]
..
I can just keep going and it works.
I can't find the vercompare function anywhere.
Did I miss something?
Re: 2.0-beta.1 - WebView2
u missed updating to a137 or later
Re: 2.0-beta.1 - WebView2
Oh thanks, the path in my editor still pointed to an old version.
It works now.
It works now.
-
- Posts: 139
- Joined: 26 Jan 2016, 16:05
Re: 2.0-beta.1 - WebView2
thqby wrote: ↑26 Oct 2021, 10:38You can wait a value that changed in asynchronous callback.And I haven't used ICoreWebView2_3::SetVirtualHostNameToFolderMapping method and don't know the application scenario.Code: Select all
wait := 1 web.ExecuteScript(code, handler := WebView2.Handler((*) => wait := 0)) while wait sleep -1
I've tried every which way i can think of to get the above working in order to 'wait', but cant seem to get it right. should the above be a fully functional example, or am i missing something perhaps? in my testing...it just waits forever.
Thanks so much!
Re: 2.0-beta.1 - WebView2
@Tre4shunter
Code: Select all
wait:=1
tset:=(*)=>wait:=0 ; local var
test()
msgbox wait ; 1
outfunc() {
wait:=1
test:=(*)=>wait:=0 ; closure var
test()
msgbox wait ; 0
}
outfunc()
-
- Posts: 139
- Joined: 26 Jan 2016, 16:05
Re: 2.0-beta.1 - WebView2
Hi @thqby -
I am still unable to get the printtopdf function to be a 'blocking' action. Could you possible update your example to reflect that?
Sorry for being dense here
Thanks again for the effort on this.
-tre4
I am still unable to get the printtopdf function to be a 'blocking' action. Could you possible update your example to reflect that?
Sorry for being dense here
Thanks again for the effort on this.
-tre4
Re: 2.0-beta.1 - WebView2
Thank you @thqby for this! I'm just getting started with it.
One thing I like is that on my old PC a WebView2 script can open the local AHK v2 help file (unpacked as .html files) 1-2 seconds faster than the time the Windows bundled CHM viewer hh.exe takes to open AutoHotkey.chm. I will play around more and try customizing things, like filtering text on help pages. Maybe in the future even the official v2 help could move from the old CHM format to WebView2.
One (perhaps confused) question: What browser settings are in use when we use WebView2? Is it whatever is default in Edge for the active user? How do we override that i.e. can we, like what is possible with Chrome.ahk, make single use custom profile with various configurations and use with WebView2?
edit: Found this, will experiment
https://github.com/thqby/ahk2_lib/blob/master/WebView2/WebView2.ahk#L877
https://docs.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2settings?view=webview2-1.0.1054.31
One thing I like is that on my old PC a WebView2 script can open the local AHK v2 help file (unpacked as .html files) 1-2 seconds faster than the time the Windows bundled CHM viewer hh.exe takes to open AutoHotkey.chm. I will play around more and try customizing things, like filtering text on help pages. Maybe in the future even the official v2 help could move from the old CHM format to WebView2.
Code: Select all
#Include WebView2.ahk
main := Gui('+Resize'), main.MarginX := main.MarginY := 0
main.OnEvent('Close', _exit_)
main.Show(Format('w{} h{}', A_ScreenWidth * 0.6, A_ScreenHeight * 0.6))
main.OnEvent('Size', gui_size)
wvc := WebView2.create(main.Hwnd)
wv := wvc.CoreWebView2
;edit to your path to unpacked AutoHotkey.chm files
wv.Navigate('file:///C:/ahk2_chm/docs/AutoHotkey.htm')
;resize wvc with main gui window
gui_size(GuiObj, MinMax, Width, Height) {
if (MinMax != -1) {
try wvc.Fill()
}
}
; release objects on exitapp
_exit_(*) {
global wvc, wv
wvc := wv := 0
ExitApp()
}
edit: Found this, will experiment
https://github.com/thqby/ahk2_lib/blob/master/WebView2/WebView2.ahk#L877
https://docs.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2settings?view=webview2-1.0.1054.31
Re: 2.0-beta.1 - WebView2
@Tre4shunter
I have updated example 4.
I have updated example 4.
Re: 2.0-beta.1 - WebView2
@neogna2
create(hwnd, callback := unset, createdEnvironment := 0, datadir := '', edgeruntime := '', dllPath := 'WebView2Loader.dll')
Do you mean this? datadir user configuration folder
The setting of edge is used by default, RegExReplace(A_AppData, 'Roaming$', 'Local\Microsoft\Edge\User Data')
create(hwnd, callback := unset, createdEnvironment := 0, datadir := '', edgeruntime := '', dllPath := 'WebView2Loader.dll')
Do you mean this? datadir user configuration folder
The setting of edge is used by default, RegExReplace(A_AppData, 'Roaming$', 'Local\Microsoft\Edge\User Data')
Re: 2.0-beta.1 - WebView2
Could anyone give an example on how to send a message BACK to AHK from the webview?
Re: 2.0-beta.1 - WebView2
AddHostObjectToScript, call ahk objects from webview with js.
Re: 2.0-beta.1 - WebView2
Thanks but is there a way to do this without first sending an object, like for example using windowmessage/postmessage?
Re: 2.0-beta.1 - WebView2
The host and the web content can also communicate with each other through the postMessage method. The web content running within a WebView2 control can post to the host through the window.chrome.webview.postMessage method, and the message is handled by any registered ICoreWebView2WebMessageReceivedEventHandler event handler on the host.
Similarly, the host can message the web content through the ICoreWebView2::PostWebMessageAsString or ICoreWebView2::PostWebMessageAsJSON method, and the message is caught by handlers that are added from the window.chrome.webview.addEventListener listener. This communication mechanism allows the web content to use native capabilities by passing messages to ask the host to run native APIs.
Source: https://docs.microsoft.com/en-us/microsoft-edge/webview2/get-started/win32#step-16---communication-between-host-and-web-content
Re: 2.0-beta.1 - WebView2
Hi all..Thank you @thqby
I am puzzled about Webview2 runtime. I'm trying to use Webview2 to help me with setting up ahk app and auto logins.. my environment is restricted that devtools (for automation) )in the edge are disabled..
We have an application that uses WebView2.. However, when I have run WebView2.Ahk I get same message that translates that Webview2 runtime is not installed..
Question.. how is this possible? Upon exploring C:\Program Files (x86)\Microsoft\Edge\Application\100.0.1185.29\ I see that msedgewebview2.exe is included , also updating path line 31 to : C:\Program Files (x86)\Microsoft\Edge\Application\ in WebView2.ahk gives me COM error.
It is possible that working app with WebView2 has a built-in Webview2? or WebView2 is installed in different directory? AM I missing something,?
Thank you.
I am puzzled about Webview2 runtime. I'm trying to use Webview2 to help me with setting up ahk app and auto logins.. my environment is restricted that devtools (for automation) )in the edge are disabled..
We have an application that uses WebView2.. However, when I have run WebView2.Ahk I get same message that translates that Webview2 runtime is not installed..
Question.. how is this possible? Upon exploring C:\Program Files (x86)\Microsoft\Edge\Application\100.0.1185.29\ I see that msedgewebview2.exe is included , also updating path line 31 to : C:\Program Files (x86)\Microsoft\Edge\Application\ in WebView2.ahk gives me COM error.
It is possible that working app with WebView2 has a built-in Webview2? or WebView2 is installed in different directory? AM I missing something,?
Thank you.
Re: 2.0-beta.1 - WebView2
The official version of edge is not available.
You need a beta or dev version of edge or edge runtime to use webview2.
@userXeo1
You need a beta or dev version of edge or edge runtime to use webview2.
@userXeo1
Re: 2.0-beta.1 - WebView2
@thqby Thank you for reply.. Looks like the app had a fixed version of WebView2 runtime installed. So, it didn't work for me until I have specified the path in the script to the WebView2 runtime.
Code: Select all
wvc := WebView2.create(main.Hwnd,,,,'C:\Program Files\xxx\xxx\Microsoft.WebView2.FixedVersionRuntime.98.0.1082.55.x64')
Any suggestions?
Thank you.
Re: 2.0-beta.1 - WebView2
@userXeo1
https://docs.microsoft.com/zh-cn/dotnet ... prerelease
This parameter of CreateCoreWebView2EnvironmentWithOptions is not used by default. And Webview2 has many methods, which can be used without CDP.
https://docs.microsoft.com/zh-cn/dotnet ... prerelease
This parameter of CreateCoreWebView2EnvironmentWithOptions is not used by default. And Webview2 has many methods, which can be used without CDP.
Re: 2.0-beta.1 - WebView2
Thank you for teply. it possible to post an example of wv interacting with external website? Like clicking a button and sending text to a external form (external meaning page was not created by self, eg google.com)