native script: WebView Interface plugin unable to find local resource

435 Views Asked by At

I am using webViewInterface plugin in nativescript 8 with webpack v5 I am trying to launch local downloaded file ex. video, audio, HTML files

I am able to download those files but while running that file with the help of webview I am getting

file not found

error

chromium: [INFO:CONSOLE(1)] "Uncaught TypeError: Cannot read property '_onNativeEvent' of undefined", source: chrome-error://chromewebdata/

In NativeScript, by default, the tilde (~) marks the app root folder (note the App and not the Project!). So if my file is located in <project-name>/app/index.html then I need to set a path like this ~/index.html.

this was working fine with natviescript v6 but after upgrading to nativescript v8 it broke.

can anyone please help???

2

There are 2 best solutions below

2
David On

The app folder is read-only on iOS (at least, on real devices, not necessarily on emulators). You'll need to download the files to either the temp or documents folder and then access from there.

As a reference, see my own struggle with this issue.

1
Vilcoyote On

OK i have what seems to be the same issue. In my case when i migrated from nativescript 7 to 8 the webpack.config.ts was cleaned up. In there was something useful that copied all my webview files.

I added some code to my webpack.config.js and now it seems to work "src" is the folder containing my webview folder.

const webpack = require("@nativescript/webpack");

module.exports = (env) => {
webpack.init(env);


webpack.Utils.addCopyRule({
    from: 'webviews/**',
    context : 'src'
})

return webpack.resolveConfig();

};

The doc I used.

NS 8 : https://docs.nativescript.org/webpack.html#adding-a-copy-rule

Previous plugin used : https://webpack.js.org/plugins/copy-webpack-plugin/