skpm / sketch-module-web-view

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

Sending a message to the WebView from your plugin command not working #144

Closed janily closed 4 years ago

janily commented 4 years ago

i made a sketch plugin with webview,when sending a message to the WebView from your plugin command,it is not working: my frotend code is

<script>
      window.a = function() {
        console.log('aaa')
      }
    </script>

my plugin code is :

webView.on('did-finish-load', () => {
          console.log('did-finish-load')
          webView.executeJavaScript('a()').then(res => {
            console.log(res)
          })
        })

dev tool console is:

mathieudutour commented 4 years ago

try

webView.executeJavaScript('a()').then(res => {
            console.log(res)
          }).catch(err => console.error(err))

and see what's the error

janily commented 4 years ago

@mathieudutour i try

webView.executeJavaScript('a()').then(res => { console.log(res) }).catch(err => console.error(err))

the console.log is null , my front is vue, i put the global function in the index.html "

janily commented 4 years ago

@mathieudutour i have done the issue.sorry, i misunderstanding the about the Sending a message to the plugin from the WebView.close the issue please.

codynova commented 4 years ago

@janily Can you please describe what was causing your issue? I believe I'm having the same problem.