Eval doesn't appear to work
leaanthony opened this issue · 3 comments
Just tried using it on master branch and it didn't appear to work. Rolled back to previous commit, and it still doesn't appear to do anything. Here is the code I'm using to test it:
func main() {
debug := true
w := webview2.New(debug)
if w == nil {
log.Fatalln("Failed to load webview.")
}
defer w.Destroy()
w.SetTitle("Minimal webview example")
w.SetSize(800, 600, webview2.HintFixed)
w.Navigate("https://en.m.wikipedia.org/wiki/Main_Page")
go func() {
runtime.LockOSThread()
for i:=0; i<10; i++ {
time.Sleep(3 * time.Second)
w.Eval("console.log('test');")
}
}()
w.Run()
}
I'm also checking the error variable returned by the ExecuteScript
vtable call and that says the script was executed successfully. Opening up the dev console indicates it's not getting excuted. Tried locking to main thread but that didn't work. Looking at my cgo version suggests we are doing all the right things in this call. I'm stumped!
This needs some investigation. I think Eval
works, at least to the same degree it did in webview/webview, but I recall there being some trickiness to it. I’m busy at the moment so I’ll try to remember to check this out maybe closer to the weekend.
My bad on this. I should have been using the Dispatch()
method rather than runtime.LockOSThread
.
Ah; this is a good example of where the webview/webview
API could be improved. Worth thinking about…