WebView2
Re: 2.0-beta.1 - WebView2
Just pass the function reference directly and you can call it after you've "awaited" it in JS.
-
- Posts: 139
- Joined: 26 Jan 2016, 16:05
Re: 2.0-beta.1 - WebView2
Yes - thanks for pointing that out!
Could anyone help me how to handle the ExecuteScript handler callback?
this code 'works' to execute some js on the page, but ive no idea how to actually use the handler, and say, 'handle' a response or any response data/values.
Could anyone help me how to handle the ExecuteScript handler callback?
this code 'works' to execute some js on the page, but ive no idea how to actually use the handler, and say, 'handle' a response or any response data/values.
Code: Select all
testArr:=['one','two','three']
wv.ExecuteScript("(function () {alert(" JxonEncode(testArr) ");document.getElementById('inputEmail').value})();",myHandler(wv,arg:=0))
return 0
myHandler(wv,arg){
return 0
}
Re: 2.0-beta.1 - WebView2
You’re calling the myHandler function rather than passing it to ExecuteScript. Don’t call it. WebView2 calls your function after it runs the provider code
Re: 2.0-beta.1 - WebView2
@Tre4shunter
ButtonsFromHTML.Bind() is redundant.
And the second parameter type of ExecuteScript is WebView2.handler object.
ButtonsFromHTML.Bind() is redundant.
And the second parameter type of ExecuteScript is WebView2.handler object.
Code: Select all
FormFromHTML(p*) {
static handler := WebView2.Handler(myhandler)
...
wv.ExecuteScript("alert(" JxonEncode(testArr) ")",handler)
return 0
myHandler(handler, errorCode, result){
msgbox(strget(result))
return(0)
}
}
-
- Posts: 139
- Joined: 26 Jan 2016, 16:05
Re: 2.0-beta.1 - WebView2
@thqby ,@kczx3 -
Thanks both for you guidance! Learning alot and quite enjoying playing with this library and V2!!
Thanks both for you guidance! Learning alot and quite enjoying playing with this library and V2!!
-
- Posts: 139
- Joined: 26 Jan 2016, 16:05
Re: 2.0-beta.1 - WebView2
I see the constant is there in WebView2.ahk to disable CORS...but i dont see how to actually implement it.
is this something that isnt possible yet -- im sure i just dont know how to implement it..
https://docs.microsoft.com/en-us/dotnet/api/microsoft.web.webview2.core.corewebview2hostresourceaccesskind?view=webview2-dotnet-1.0.992.28
Im loading a local html file, and have some js which is trying to load some json files.
is this something that isnt possible yet -- im sure i just dont know how to implement it..
https://docs.microsoft.com/en-us/dotnet/api/microsoft.web.webview2.core.corewebview2hostresourceaccesskind?view=webview2-dotnet-1.0.992.28
Im loading a local html file, and have some js which is trying to load some json files.
Re: 2.0-beta.1 - WebView2
ICoreWebView2_3::SetVirtualHostNameToFolderMapping(/* [in] */ LPCWSTR hostName, /* [in] */ LPCWSTR folderPath, /* [in] */ COREWEBVIEW2_HOST_RESOURCE_ACCESS_KIND accessKind)
This method?
Code: Select all
enum COREWEBVIEW2_HOST_RESOURCE_ACCESS_KIND
{
COREWEBVIEW2_HOST_RESOURCE_ACCESS_KIND_DENY = 0,
COREWEBVIEW2_HOST_RESOURCE_ACCESS_KIND_ALLOW = ( COREWEBVIEW2_HOST_RESOURCE_ACCESS_KIND_DENY + 1 ) ,
COREWEBVIEW2_HOST_RESOURCE_ACCESS_KIND_DENY_CORS = ( COREWEBVIEW2_HOST_RESOURCE_ACCESS_KIND_ALLOW + 1 )
} COREWEBVIEW2_HOST_RESOURCE_ACCESS_KIND;
-
- Posts: 139
- Joined: 26 Jan 2016, 16:05
Re: 2.0-beta.1 - WebView2
Yep!
i guess my question is how do i actually -- use it?
i guess my question is how do i actually -- use it?
-
- Posts: 139
- Joined: 26 Jan 2016, 16:05
Re: 2.0-beta.1 - WebView2
Is there a way to 'wait' for the ExecuteScript() call to finish? I'd like to send messages to the page and then return a result, but do it synchronously.
Re: 2.0-beta.1 - WebView2
You 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
Last edited by thqby on 26 Oct 2021, 18:54, edited 1 time in total.
Re: 2.0-beta.1 - WebView2
I don't think there's a way to do ExecuteScript synchronously. You will have to use a callback.
For SetVirtualHostNameToFolderMapping, you just have to pass the third argument as WebView2.HOST_RESOURCE_ACCESS_KIND.DENY.
For SetVirtualHostNameToFolderMapping, you just have to pass the third argument as WebView2.HOST_RESOURCE_ACCESS_KIND.DENY.
Re: 2.0-beta.1 - WebView2
Very nice, thanks for sharing.
On my machine I had multiple runtimes installed and it did not work, to fix it had to pick up the latest, so I removed the break and all worked:
On my machine I had multiple runtimes installed and it did not work, to fix it had to pick up the latest, so I removed the break and all worked:
Code: Select all
if (!edgeruntime) {
loop files "C:\Program Files (x86)\Microsoft\EdgeWebView\Application\*", "D"
if (A_LoopFilePath ~= "\\[\d.]+$") {
edgeruntime := A_LoopFileFullPath
;~ break
}
}
-
- Posts: 139
- Joined: 26 Jan 2016, 16:05
Re: 2.0-beta.1 - WebView2
Hello!
I'm attempting to launch a new 'window' with another Webview2 control in it...but i cant seem to create more than one. I'm sure i need to use the NewWindowRequested method to do this, but i cant seem to make it work properly.
could you point me in the right direction?
Thanks so much again for this class!
[EDIT]
Ended up getting it "working" like so...but I'm certain there's a better, cleaner method.
I'm attempting to launch a new 'window' with another Webview2 control in it...but i cant seem to create more than one. I'm sure i need to use the NewWindowRequested method to do this, but i cant seem to make it work properly.
could you point me in the right direction?
Thanks so much again for this class!
[EDIT]
Ended up getting it "working" like so...but I'm certain there's a better, cleaner method.
Code: Select all
main := Gui('+Resize'), main.MarginX := main.MarginY := 0
main.Title := WBName
main.OnEvent('Size', gui_size)
main.Show(Format('w{} h{}', A_ScreenWidth * 0.6, A_ScreenHeight * 0.6))
svc := Gui(), svc.MarginX := svc.MarginY := 0
svc.OnEvent('Size', gui_size)
;Load WebView2 Interface
If !DirExist(A_Temp "\wv2\")
DirCreate(A_Temp "\wv2\")
wvc := WebView2.create(main.Hwnd, Main_Invoke, 0, A_Temp "\wv2\")
Service()
return
Main_Invoke(wvc){
global
main.GetClientPos(,,&w,&h)
ctl := main.AddText('x0 y25 w' w ' h' (h - 25))
wv := wvc.CoreWebView2
wv.Navigate('file:///' A_ScriptDir '\index.html')
return(wvc)
}
svc_Invoke(wvc1){
global
svc.GetClientPos(,,&w,&h)
ctl1 := main.AddText('x0 y25 w' w ' h' (h - 25))
svc.Show(Format('w{} h{}', A_ScreenWidth * 0.6, A_ScreenHeight * 0.6))
wv1 := wvc1.CoreWebView2
wv1.Navigate('file:///' A_ScriptDir '\service\main.html')
return(wvc1)
}
Service(){
global
wvc1 := WebView2.create(svc.Hwnd, svc_Invoke, 0, A_Temp "\wv2_ss\")
svc.Show(Format('w{} h{}', A_ScreenWidth * 0.6, A_ScreenHeight * 0.6))
}
gui_size(GuiObj, MinMax, Width, Height) {
if (MinMax != -1) {
try ctl.Move(, , Width, Height - 23)
try wvc.Fill()
try ctl1.Move(, , Width, Height - 23)
try wvc1.Fill()
}
}
Re: 2.0-beta.1 - WebView2
Code: Select all
g1 := Gui(), g2 := Gui()
g1.Show('w800 h600')
g2.Show('w800 h600')
wv1 := WebView2.create(g1.Hwnd, main)
wv2 := WebView2.create(g2.Hwnd, main)
main(ww) {
ww.CoreWebView2.Navigate('https://autohotkey.com')
}
NewWindowRequest event is triggered when a link is clicked to bring up a new window.
-
- Posts: 139
- Joined: 26 Jan 2016, 16:05
Re: 2.0-beta.1 - WebView2
Hi @thqby ,
Thanks for clarifying - I think that's what i ended up with, I was just frustrating myself for a bit and I think overcomplicating things.
Again, this library is excellent and thank you very much for assembling what I'm sure was a load of work on your end. I'm endlessly appreciative!
got a paypal or something? I'd definitely donate to you.
-Tre4
------[EDIT]-------
I would also like to add that, although V2 is still in 'Beta' and Webview2 is as well(I think) the current stability and functionality ive had with it is outstanding. I'm in the process of converting over apps ive written over the last several years to use the WV2 interface, and ive not had a single issue that i wasn't able to resolve, or that has stopped me or given me any pause or reasons not to move forward. I feel like I'm beating a dead horse saying how much I love this class/V2 but....I just really think its awesome. Hope more people start digging in!!
Thanks for clarifying - I think that's what i ended up with, I was just frustrating myself for a bit and I think overcomplicating things.
Again, this library is excellent and thank you very much for assembling what I'm sure was a load of work on your end. I'm endlessly appreciative!
got a paypal or something? I'd definitely donate to you.
-Tre4
------[EDIT]-------
I would also like to add that, although V2 is still in 'Beta' and Webview2 is as well(I think) the current stability and functionality ive had with it is outstanding. I'm in the process of converting over apps ive written over the last several years to use the WV2 interface, and ive not had a single issue that i wasn't able to resolve, or that has stopped me or given me any pause or reasons not to move forward. I feel like I'm beating a dead horse saying how much I love this class/V2 but....I just really think its awesome. Hope more people start digging in!!
Re: 2.0-beta.1 - WebView2
@Tre4shunter
The latest version is ready to print pdf.
Paypal is the same as this ID.
The latest version is ready to print pdf.
Paypal is the same as this ID.
Re: 2.0-beta.1 - WebView2
@Tre4shunter
WebView2 is stable now and has been for some time actually.
WebView2 is stable now and has been for some time actually.
Re: 2.0-beta.1 - WebView2
I can't think of an easy way to access host objects such as array, map, etc.
Return to “Scripts and Functions (v2)”
Who is online
Users browsing this forum: metallizer and 37 guests