Code: Select all
g := Gui()
g.Show(Format("w{} h{}", A_ScreenWidth * 0.6, A_ScreenHeight * 0.6))
wv := WebView2.create(g.Hwnd)
nav_sync := SyncHandler()
exec_sync := SyncHandler((args) => OutputDebug(StrGet(args[2])))
wv.CoreWebView2.add_NavigationCompleted(nav_sync)
wv.CoreWebView2.Navigate("https://sso.hhs.state.ma.us")
nav_sync.wait()
wv.CoreWebView2.ExecuteScript(
"document.getElementById('loginForm').submit()",
exec_sync
)
class SyncHandler extends WebView2.Handler {
__New(cb := 0) {
this.obj := SyncHandler.CompletedEventHandler()
this.obj.cb := cb
super.__New(this.obj, 3)
}
wait() {
o := this.obj
while !o.status
Sleep(10)
o.status := 0, Sleep(100)
}
class CompletedEventHandler {
status := 0, cb := 0
call(handler, args*) {
if this.cb
(this.cb)(args)
this.status := 1
}
}
}
Thank you.