shripalsoni04 / nativescript-webview-interface

Plugin for bi-directional communication between webView and android/ios
MIT License
89 stars 35 forks source link

Cannot read property 'emit' of undefined #48

Closed pollyolly closed 4 years ago

pollyolly commented 5 years ago

"Uncaught TypeError: Cannot read property 'emit' of undefined",

Inside the html file.

I tried to include it this way based on the instruction.

I badly need this plugin for my project. Please help.

pollyolly commented 5 years ago

Fixed:

I added {from: "www/**"} in webpack config. It seems adding .html is not sufficient.

Ot92 commented 4 years ago

Having the same problem, browser recognises window.nsWebViewInterface on desktop but through the webview, it's undefined.

Where exactly do you add the line below in Nativescript webpack?

{from: "www/**"}

ghost commented 4 years ago

Having the same problem, browser recognises window.nsWebViewInterface on desktop but through the webview, it's undefined.

Where exactly do you add the line below in Nativescript webpack?

{from: "www/**"}

in webpack.config.js

ghost commented 4 years ago

but for me even adding this wont help,

I can run this.oWebViewInterface.on( 'onStateChange', eventData => {} )

and it works, but not .emit nor .callJSFunction wont work for me.

Android 10 | NS 7

I get this error: TypeError: Cannot read property 'sdkVersion' of undefined

to solve this problem I changed the plug-in ( file: index.android.js ) a bit:

line 2 from const platformModule = require("platform"); to const platformModule = require("@nativescript/core");

and

line 79 from if (platformModule.device.sdkVersion >= 19) { to if (platformModule.Device.sdkVersion >= 19) {