-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
WebViewAssetLoader: Application private path Raw File access at JavaScript using XMLHttpRequest fails. #1329
Comments
Facing similiar issue when using an absolute file url: lFileUrl = 'file:///data/user/0/com.company.stub/files/myfolder/IMG-20210826-204423558thumb.jpg'
xhr.open("GET", lFileUrl, true);
xhr.onload = function() {
console.log('loaded');
}
try {
xhr.send();
} catch (e) {
console.error(e);
} Error message on console:
Solution could be to provide something similar to Prototype Implementation: async function resolveLocalFileSystemURL(uri){
return new Promise(function (resolve, reject) {
window.resolveLocalFileSystemURL(uri, resolve, (cause) => {
if (cause.code == FileError.NOT_FOUND_ERR)
resolve(null);
else reject({cause, uri, message: "cannot resolve local file system url"})
});
});
}
async function convertFilePath(uri){
if(uri.startsWith('file://'){
const resolved = await this.utils.resolveLocalFileSystemURL(uri);
uri = resolved.toInternalURL().replace("cdvfile://localhost/", "https://" + location.host + "/");
}
return uri;
}
lFileUrl = await convertFilePath('file:///data/user/0/com.company.stub/files/myfolder/IMG-20210826-204423558thumb.jpg');
xhr.open("GET", lFileUrl, true);
xhr.onload = function() {
console.log('loaded');
}
try {
xhr.send();
} catch (e) {
console.error(e);
} Error message in chrome debugger network panel: Looks like https://github.com/apache/cordova-android/blob/015db819aed3f35892d2b6035781ea4bd752149d/framework/src/org/apache/cordova/engine/SystemWebViewClient.java is missing a https://developer.android.com/reference/androidx/webkit/WebViewAssetLoader.InternalStoragePathHandler to make |
Is there any workaround for this or do we need to set |
1) Image residing in Application private path.
lFileUrl =data/user/0/com.company.stub/files/myfolder/IMG-20210826-204423558thumb.jpg
2)XMLHttpRequest request done from javascript level in cordova based android app.
var xhr = new XMLHttpRequest();
xhr.open("GET", lFileUrl, true);
xhr.responseType = "blob";
xhr.onload = function(e) {
try {
}
3)WebResourceResponse shouldInterceptRequest called.
2021-08-26 20:44:34.534 32333-4065/com.company.stub D/SystemWebViewClient: shouldInterceptRequest request.getUrl(): https://localhost/data/user/0/com.company.stub/files/myfolder/IMG-20210826-204423558thumb.jpg
cordova-android/framework/src/org/apache/cordova/engine/SystemWebViewClient.java
Line 423 in 015db81
4)File not found exception seen as its searching in "www/"
cordova-android/framework/src/org/apache/cordova/engine/SystemWebViewClient.java
Line 112 in 015db81
2021-08-26 20:44:34.537 32333-4065/com.company.stub E/SystemWebViewClient: www/data/user/0/com.company.stub/files/myfolder/IMG-20210826-204423558thumb.jpg
### What is expected to happen?
1)private File access should be pass.
https://developer.android.com/reference/androidx/webkit/WebViewAssetLoader.InternalStoragePathHandler
### What does actually happen?
File not found exception seen as WebViewAssetLoader.InternalStoragePathHandler is not handled. Suggest how to handle raw file access.
## Information
https://bugs.chromium.org/p/chromium/issues/detail?id=1101250
Below change works.
cordova-android/framework/src/org/apache/cordova/engine/SystemWebViewClient.java
Line 95 in 015db81
### Version information
Cordova: Android 10.1.0
device : android 11
app targetsdk : 30 .
Note: if
<preference name="AndroidInsecureFileModeEnabled" value="true" />
everything works fine.The text was updated successfully, but these errors were encountered: