normalizeURL file:///var.. -> http://localhost:8080/var

#1

Hello, I used WKWebView (http://ionicframework.com/docs/wkwebview/)


import { normalizeURL } from 'ionic-angular';

let path = cordova.file.dataDirectory;
console.log('Original: ' + path);

path = normalizeURL(path);
console.log('Fixed: ' + path);

and have result, not like described in manual:

file:///var/mobile/Containers/Data/Application/18438A3A-9ABD-440F-9989-0C009A6CCC8C/Library/NoCloud/

converted to

http://localhost:8080/var/mobile/Containers/Data/Application/18438A3A-9ABD-440F-9989-0C009A6CCC8C/Library/NoCloud/

but as i understand, should be

/var/mobile/Containers/Data/Application/18438A3A-9ABD-440F-9989-0C009A6CCC8C/Library/NoCloud/

1 Like
#2

Sorry for probably silly question, any way to ensure if WKWebView used to render views ?

I had couple vierd bugs related to update to WKWebView, and strange, file:/// still works good.

#3

I am seeing the same thing on iOS. Normalized URL starts with http://localhost:8080 which is then causing me problems later in my code.

#4

And again to this issue.
Example from documentation:

let aaa = "file:///usr/home/dev/app/index.html";
aaa = normalizeURL(aaa);

results “file:///usr/home/dev/app/index.html”

somewhy file:// prefix not removes

and IOS works with file://

#5

@pyav
I am also working with WKWebview, and experiencing the same issue (even if I am removing file:// manually).
Did you find a solution?

There might be something possible with DomSanitizer or cordova-plugin-file.

FYI, you can test if you are running WkWebView with the following code:

// iOS - WKWebView
if (this.platform.is('ios')) {
  if (window.indexedDB) {
    console.log('[SystemService]', 'iOS', 'WKWebView');
  } else {
    console.log('[SystemService]', 'iOS', 'UIWebView');
  }
}

EDIT:
I also tried to add/configure Content-Security-Policy (<meta> in the index.html) & add/configure cordova-plugin-whitelist (<allow-xxx ...> in the config.xml) without any success.

#6

Any solution found for this issue?

#7

You could write your own function in a utils folder:

let toNormalize = "file:///var/mobile/Containers/Data/Application/18438A3A-9ABD-440F-9989-0C009A6CCC8C/Library/NoCloud/"

return toNormalize.split("//", 1)[1]
#8

When you changed the path were you able to get the picture or file? I used the normailzeURL like you did and got the same results. I ended up just sub-stringing it to get what I wanted, but I still get an error when accessing files or pictures… domain=pluginkit code=13 query cancelled userinfo= nslocalizeddescription=query cancelled

#9

I’ve the same problem from the last update of plugin webview
<plugin name="cordova-plugin-ionic-webview" spec="^3.1.1">

normalizeUrl() was replaced by convertFileSrc(). It works well on android real device but fails on iOS for me.
So i’m still stucked (i’m using file plugin to read a local video without issue but when i’m trying to display this video “sanitized” link in a videogular or html5 element, it fails on iOS.

let win: any = window; // hack compilator
let safeURL = win.Ionic.WebView.convertFileSrc('file:///myFile/....');
#10

@lucbonnin I have the same problem using these convertFileSrc URLs and even after adding
ionic: to the index.html content-security-policy meta tag, videos with a src like below will still not play:

ionic://localhost/app_file/var/mobile/Containers/Data/Application/5427DD11-7B0A-44CA-875B-D8CB32829CE2/Documents/Fun/2725.mov

#11

As a work around, i’ve added
<preference name="CordovaWebViewEngine" value="CDVUIWebViewEngine" />

to the config.xml (only for platform iOS). It is a bit ugly i know but i had no other choice except downgrading to webview 1.x and that was ugliest.

I hope @ionic_team will be able to fix this iOS issue soon.

1 Like