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:

bildschirmfoto 2018-10-13 um 09 52 22

Version:

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)

Most upvoted comments

I have the same issue.

When I use the following it works fine:

private win: any = window;
this.win.Ionic.WebView.convertFileSrc();

@leiamac I’ve upgraded cordova-plugin-ionic-webview to Version 3.1.1 and @ionic-native/ionic-webview to version ^5.0.0-beta.21

This is my code for converting and sanitizing image urls:

protected fixURL(url: string): string | SafeUrl {
	if (this.platform.is('cordova')) {
		const win: any = window;
		const fixedURL = win.Ionic.WebView.convertFileSrc(url);

		return this.sanitizer.bypassSecurityTrustUrl(fixedURL);
	} else {
		return url;
	}
}

(Don’t forget the imports)

I’ve been able to workaround this, by copying the convertFileSrc method 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