Notalib / nativescript-webview-ext

Nativescript plugin with extended WebView functionality
Apache License 2.0
76 stars 37 forks source link

Can't `fetch()` x-local:// resources on iOS. #106

Closed tralves closed 3 years ago

tralves commented 3 years ago

Which platform(s) does your issue occur on?

Please, provide the following version numbers that your issue occurs with:

@nativescript/core: 7.1.4 Runtime(s): iOS 7.2.0

Please, tell us how to recreate the issue in as much detail as possible.

I am adding an .mp3 file resource with registerLocalResource(). Inside the webview, I need to grab the file with fetch:

try {
  response = await fetch('x-local://1086.mp3');
catch(e) { /* log error */ }
const arrayBuffer = await response.arrayBuffer();
...

But fetch throws the error:

x-local://1086.mp3: TypeError: Origin null is not allowed by Access-Control-Allow-Origin.

This code works on Android.

1) Is there anything we can do to the webview to ignore CORS errors?

2) Is there another way to grab the file contents other than fetch?

tralves commented 3 years ago

If anyone needs these fixes while the PR isn't merged, you can use my compiled lib like so

package.json:

"@nota/nativescript-webview-ext": "https://github.com/tralves/nativescript-webview-ext/raw/master/dist/nota-nativescript-webview-ext-7.0.3.tgz",