Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Execution order on Windows is weird #37

Open
Le0Developer opened this issue Mar 22, 2024 · 2 comments
Open

Execution order on Windows is weird #37

Le0Developer opened this issue Mar 22, 2024 · 2 comments

Comments

@Le0Developer
Copy link

The execution order on Windows is weird.

Example 1

package main

import (
	"fmt"

	webview "github.com/webview/webview_go"
)

func main() {
	view := webview.New(true)
	defer view.Destroy()
	view.SetTitle("Basic Example")
	view.SetSize(480, 320, webview.HintNone)
	view.SetHtml("<script>window.hello()</script>")
	view.Bind("hello", func() {
		fmt.Println("hello from js!")
	})
	view.Run()
}

For some reason the script appears to be executing early, because it can't find the window.hello() binding and errors.
This is not happening on macOS.

Example 2

Also in this example the second view.Init script just doesn't execute at all.

package main

import (
	"fmt"

	webview "github.com/webview/webview_go"
)

func main() {
	view := webview.New(true)
	defer view.Destroy()
	view.SetTitle("Basic Example")
	view.SetSize(480, 320, webview.HintNone)
	view.Init("console.log('init 1', window.hello)")
	view.SetHtml("<script>console.log('js', window.hello);setTimeout(() => console.log('js after 100ms', window.hello), 100)</script>")
	view.Bind("hello", func() {})
	view.Init("console.log('init 2', window.hello)")
	view.Run()
}
Windows macOS
image image

Navigate() also works

The same can be reproduced with Navigate by replacing SetHtml(" with Navigate("data:text/html,.

Window exists before Run()

See this basic example:

package main

import (
	"time"

	webview "github.com/webview/webview_go"
)

func main() {
	view := webview.New(true)
	defer view.Destroy()
	time.Sleep(10 * time.Second)
	view.Run()
}

When running this on macOS the webview appears in the dock but no window is visible for 10s.
However on Windows, a window pops up immediately but it's frozen for 10seconds.

Conclusion

SetHtml/Navigate interact weirdly on Windows. They appear to be starting immediately or earlier than .Run().

@SteffenL
Copy link
Contributor

SteffenL commented Mar 22, 2024

Have you tried to call bind Bind (and Init) before SetHtml?

@Le0Developer
Copy link
Author

Yeah, but I'd expect the behavior to be consistent on all platforms.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants