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

window.external.invoke undefined #236

Open
leaanthony opened this issue Feb 10, 2019 · 6 comments

Comments

@leaanthony
Copy link

commented Feb 10, 2019

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

OSX 10.14.3 (18D42)

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

Go
Apple LLVM version 10.0.0 (clang-1000.11.45.5)

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

window.external.invoke never appears when using Eval from main.

Example:

package main

import (
	"github.com/zserge/webview"
)

func main() {
	w := webview.New(webview.Settings{
		Width:  800,
		Height: 600,
		Title:  "Simple demo",
		Debug:  true,
		URL:    `data:text/html,<html><body><div id="app"></div></body></html>`,
	})

	defer w.Exit()
	w.Dispatch(func() {
		w.Eval("var f = function() { if(window.external && window.external.invoke) { console.log('ready'); } else { console.log('waiting'); setTimeout(f, 10); } }; f();")
	})

	w.Run()
}

This code was written to try and work out why calling window.external.invoke kept failing. Looks like it never appears. The window opens and the console log counter goes up and up:
image

Also, and maybe I should open up a seperate issue, commenting out the URL line means Dispatch now doesn't work and that code is never called.

@martinhoefling

This comment has been minimized.

Copy link

commented Feb 13, 2019

I have the same problem, but I do not even get the debugging tools on OSX. I have set Debug to true. Any ideas?

@leaanthony

This comment has been minimized.

Copy link
Author

commented Feb 21, 2019

Nope. This is a total showstopper for me. The previous webview based code works fine.

@Zouuup

This comment has been minimized.

Copy link

commented Apr 20, 2019

Same issue here, anyone found a workaround?

@jelgblad

This comment has been minimized.

Copy link

commented May 13, 2019

I got around this by calling window.external.invoke after the DOM is ready.

Javascript:

document.addEventListener('DOMContentLoaded', () => {
  try {
    window.external['invoke']('DOMContentLoaded');
  }
  catch(e) {
    console.log(e);
  }
});

Go:

w = webview.New(webview.Settings{
    Title:                  "MyWindow",
    URL:                    guiURL,
    Width:                  windowWidth,
    Height:                 windowHeight,
    ExternalInvokeCallback: handleExternalInvokeCallback,
})

func handleExternalInvokeCallback(w webview.WebView, data string) {
  switch data {
    case "DOMContentLoaded":
      w.Bind("windowController", windowController)
      break
  }
}

Can't say I like it, but it works...

@leaanthony

This comment has been minimized.

Copy link
Author

commented May 13, 2019

Thanks for this! I will try it.

@sylflo

This comment has been minimized.

Copy link

commented Jun 17, 2019

I had a problem after validating a form the solution was to use this
https://webkitgtk.org/reference/webkit2gtk/stable/WebKitUserContentManager.html#webkit-user-content-manager-register-script-message-handler

I called it like this window.webkit.messageHandlers.external.postMessage('');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.