Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS error Failed to load resource: unsupported URL #246

Open
dpsa-dev opened this issue Apr 23, 2020 · 6 comments
Open

iOS error Failed to load resource: unsupported URL #246

dpsa-dev opened this issue Apr 23, 2020 · 6 comments

Comments

@dpsa-dev
Copy link

Hi guys

Great plugin but since the change to WKWebview this plugin has stopped working for me. I've switched to v2.1.1 which is working fine on Android. I'm using Cordova with the following plugins
"cordova-plugin-wkwebview-engine": "1.2.1",
"cordova-plugin-wkwebview-file-xhr": "2.1.4"
The following noted from the console indicates the file is downloaded/stored correctly but when fetching it it fails.

[Log] INFO: Download complete: file:///Users/shadow4768/Library/Developer/CoreSimulator/Devices/3965C47C-7718-48C3-82ED-DF9A2CCB3989/data/Containers/Data/Application/3BFC0F90-F7D4-4DFA-8648-0F440929F835/Library/NoCloud/imgcache/5b1950b1ee383f3fdd0e51bf84dfdbd505006d79 (cordova.js, line 1540)
[Log] INFO: Cached file size: 37161 (cordova.js, line 1540)
[Log] INFO: current size: 2533404 (cordova.js, line 1540)
[Log] INFO: com.apple.MobileBackup metadata set (cordova.js, line 1540)
[Log] INFO: File getdocument?documentid=41623&width=300 loaded from cache (cordova.js, line 1540)
[Error] Failed to load resource: unsupported URL cdvfile://localhost/library-nosync/imgcache/91c59e590d88a60c252d8281aa165be35a7d5798

Any ideas how I could get around this issue would be greatly appreciated.

@dpsa-dev
Copy link
Author

I updated the following method for what it is worth and its working on my emulator, hopefully its fixed ..Im not sure why I have to change this other than cdvfile:/ path no longer supported in WKWebview

  Helpers.EntryGetURL = function (entry) {
    // toURL for html5, toURI for cordova 1.x
    //return (typeof entry.toURL === 'function' ? Helpers.EntryToURL(entry) : entry.toURI());

    if (device_platform.toLowerCase() == "ios") {
      if (window.indexedDB) {
        //NEW webview
            
        //console.log(JSON.stringify(entry));
        //{"isFile":true,"isDirectory":false,"name":"83bc7ed2261bb38faecc78e21929622437b65572","fullPath":"/imgcache/83bc7ed2261bb38faecc78e21929622437b65572","filesystem":"<FileSystem: library-nosync>","nativeURL":"file:///Users/shadow4768/Library/Developer/CoreSimulator/Devices/3965C47C-7718-48C3-82ED-DF9A2CCB3989/data/Containers/Data/Application/CDD19007-1BE8-49B8-A591-E57D90202BD7/Library/NoCloud/imgcache/83bc7ed2261bb38faecc78e21929622437b65572"}

        var normalizedUrl = entry.nativeURL;
        return normalizedUrl;

        //console.log('[SystemService]', 'iOS', 'WKWebView');
      } else {
        return (typeof entry.toURL === 'function' ? Helpers.EntryToURL(entry) : entry.toURI()); //OLD webview use existing solution
        //console.log('[SystemService]', 'iOS', 'UIWebView');
      }
    } else {
      return (typeof entry.toURL === 'function' ? Helpers.EntryToURL(entry) : entry.toURI()); //Android webview use existing solution
    }
  }

@thomeijken
Copy link

Hi,
I'm experiencing the same issue. I see that issues 247 and 248 are mentioned, however those both relate to ionic. The fix that is added in Helpers.EntryGetURL is also specific for ionic and does not do anything when you're using plain cordova.

The change that @dpsa-dev provided works for me. So the trick is to return entry.nativeURL from the Helpers.EntryGetURL in this specific case. Hope this helps in creating the right fix.

@shadow476z
Copy link

Hi there, bad news about the above fix is that it didnt work an actual device/only on emulators. A path related issue appeared and it seemed apparent that it was a iOS restriction on the specific path. I didn't find a fix for this so for me this is still not working on WKWebview. If you do find a solution please let me know.

@thomeijken
Copy link

thomeijken commented Jun 12, 2020

@shadow476z , The solution above works for me (also on an actual device) when I load the images from the cacheUrl asynchronously with a XMLHTTPRequest.
However, when I use the cacheUrl to load the images using <img src="{cachUrl}"> they will only work on the simulator.

Since most of my images are loaded asynchronously, I will stick to that for now, while awaiting a more general solution..

@gearp
Copy link

gearp commented Jun 23, 2020

It didn't work for me. I'm getting : "Not allowed to load local resource: file:///var/mobile/Containers/Dat....". I'm using Cordova-ios 6.0.0. Have you faced this issue as well ?

@iljaverba00
Copy link

Frends, you have solution by this question?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants