cordova-plugin-ionic-webview: convertFileSrc - ERROR TypeError: Object(...) is not a function
In a component I’m trying to convert a file src string.
import { WebView } from '@ionic-native/ionic-webview/ngx';
// ...
constructor(
protected webView: WebView
) {}
// ...
protected fixURL(url: string): string {
if (this.platform.is('cordova')) {
return this.webView.convertFileSrc(url);
} else {
return url;
}
}
// ...
The problem is, that this.webView.convertFileSrc(url) throws this error:

Version:
- cordova-plugin-ionic-webview: 2.1.4
- @ionic-native/ionic-webview: ^5.0.0-beta.21
Ionic Info:
Ionic:
ionic (Ionic CLI) : 4.2.1 (/Users/tmuecksch/.npm-global/lib/node_modules/ionic) Ionic Framework : ionic-angular 3.9.2 @ionic/app-scripts : 3.1.11
Cordova:
cordova (Cordova CLI) : 8.1.2 (cordova-lib@8.1.1) Cordova Platforms : android 7.1.1, ios 4.5.5 Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 2.1.4, (and 19 other plugins)
System:
ios-deploy : 2.0.0 NodeJS : v10.11.0 (/usr/local/bin/node) npm : 6.4.1 OS : macOS Xcode : Xcode 10.0 Build version 10A255
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 5
- Comments: 28 (3 by maintainers)
I have the same issue.
When I use the following it works fine:
@leiamac I’ve upgraded
cordova-plugin-ionic-webviewto Version3.1.1and@ionic-native/ionic-webviewto version^5.0.0-beta.21This is my code for converting and sanitizing image urls:
(Don’t forget the imports)
I’ve been able to workaround this, by copying the
convertFileSrcmethod from the following file to my component class and using it instead of the WebView Wrapper:https://github.com/ionic-team/cordova-plugin-ionic-webview/blob/master/src/www/util.js
Strange 😮
If using angular you have to tell it to trust ionic scheme with dom sanitizer, there is an example in the comments