Fetch API cannot load file:///****. URL scheme "file" is not supported. WebView Android

Viewed 1202

I am trying to intercept request using shouldInterceptRequest for WebView in Android. Loaded url contains javascript "fetch" command, that leads to error: "Fetch API cannot load file:///xxxxxx. URL scheme "file" is not supported.".

I have not managed to find why fetch is executed on Windows successfully, but is failing on Android. I know that it is possible to replace fetch by XMLHttpRequest or use polyfill on the web page side, but I want to do modifications only on the Android side.

There is some code to reproduce the error:

evaluateJavascript(
    "(function() {\n" +
    "fetch('file:///xxxxxx')\n" +
    ".then(response => console.log('Success'))\n" +
    ".catch(err => console.log('Fail', err));\n" +
    "})();", null);

also everything is allowed for WebView:

getSettings().setAllowContentAccess(true);
getSettings().setAllowFileAccess(true);
getSettings().setAllowFileAccessFromFileURLs(true);
getSettings().setAppCacheEnabled(true);
getSettings().setDatabaseEnabled(true);
getSettings().setDomStorageEnabled(true);
getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
getSettings().setJavaScriptEnabled(true);
getSettings().setMediaPlaybackRequiresUserGesture(false);
getSettings().setAllowUniversalAccessFromFileURLs(true);

Is it possible to do modifications only on Android side to support "fetch"? How to learn the reason of missing support for Fetch API "file" scheme in Android WebView?

0 Answers
Related