gree / unity-webview

zlib License
2.28k stars 686 forks source link

CORS Error Encountered In Android While Fetching Local File in Webview #1107

Open trohit08 opened 2 days ago

trohit08 commented 2 days ago

Recently in Android we are facing a CORS error while trying to fetch a local image in the webview via a Javascript file. This image gets downloaded from server at the very first instance of opening our application. Later while opening the webview from within the app, the image gets loaded from persistent datapath of Android. The following error was observed when we inspected the webview:

"Fetch API cannot load file://{path to file}. URL scheme "file" is not supported."

Need help fixing this.

KojiNakamaru commented 2 days ago

As the error message describes, it is not supported for security reasons.

cf. https://chromium.googlesource.com/chromium/src/+/HEAD/android_webview/docs/cors-and-webview-api.md#setallowfileaccessfromfileurls