skpm / sketch-module-web-view

A sketch module for creating an complex UI with a webview
MIT License
289 stars 62 forks source link

webUI.eval('someJSFunction()') does nothing #18

Closed bildlich closed 7 years ago

bildlich commented 7 years ago

I'm referring to the "executing JS on the webview from the plugin" example.

I run the above command after creating a WebUI instance. Nothing happens. The someJSFunction() doesn't exist on the web view but I'd expect some kind of error à la someJSFunction() is not a function. This appears neither in the plugin log (viewed with skpm log -f) nor in the Safari Web Inspector panes.

Where do I view the web error logs? When creating someJSFunction, how do I add it to the web view?

import WebUI from 'sketch-module-web-view'

const options = {
  identifier: 'unique.id', // to reuse the UI
  x: 0,
  y: 0,
  width: 240,
  height: 180,
  background: NSColor.whiteColor(),
  onlyShowCloseButton: false,
  title: 'My ui 3',
  hideTitleBar: false,
  shouldKeepAround: true,
  frameLoadDelegate: { // https://developer.apple.com/reference/webkit/webframeloaddelegate?language=objc
    'webView:didFinishLoadForFrame:': function (webView, webFrame) {
      context.document.showMessage('UI loaded!')
      WebUI.clear()
    }
  },
  uiDelegate: {}, // https://developer.apple.com/reference/webkit/webuidelegate?language=objc
  onPanelClose: function () {
    // Stuff
  }
}

const webUI = new WebUI(context, 'test.html', options)
const res = webUI.eval('someJSFunction()')
mathieudutour commented 7 years ago

It does do something. Just add the JS function in your HTML

mathieudutour commented 7 years ago

You can check the skpm/with-webview repo, there is an example