webview / webview

Tiny cross-platform webview library for C/C++. Uses WebKit (GTK/Cocoa) and Edge WebView2 (Windows).
MIT License
12.66k stars 951 forks source link

Navigating before running with my Javascript files results in an error (but running before navigating does not) #523

Open patarapolw opened 3 years ago

patarapolw commented 3 years ago

What OS are you using (uname -a, or Windows version)?

Linux polv-xu15 5.4.0-62-generic #70-Ubuntu SMP Tue Jan 12 12:45:47 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Xubuntu / Xfce

What programming language are you using (C/C++/Go/Rust)?

What did you expect to see and what you saw instead?

The UI partially loads, except for the part that requires window.speechSynthesis or window.Audio.

Also, in the terminal.

http://localhost:35594/js/chunk-vendors.ec036da9.js:23:21114: CONSOLE ERROR ReferenceError: Can't find variable: speechSynthesis

Confusingly, Right click > Reload fixes the problem.

So, I tried this temporary fix.

    debug := true
    w := webview.New(debug)
    w.SetTitle("Minimal webview example")
    w.SetSize(800, 600, webview.HintNone)

    go func() {
        time.Sleep(10 * time.Millisecond)
        w.Dispatch(func() {
            w.Navigate(url)
        })
    }()

    w.Run()
wusyong commented 3 years ago

I also got this issue months ago. It turns out microsoft's webview2 have some certain ordering regarding https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.controls.webview.navigationstarting?view=winrt-19041#remarks Contents including js eval should be done before navigation complete.