I got the same error while trying to save a file localy when using
cordova build browser
with Chrome and Edge, but not with Firefox.
Thanks to the former comments I did understand, that cordova.file.dataDirectory
is not supported by platform browser
. After some digging I found out that in Chrome you need to use the webkit functions to access local files.
window.webkitRequestFileSystem(window.PERSISTENT|window.TEMPORARY , [filesize], [ReadWriteFunction]);
However for all other platforms (including Firefox) we can use cordova.file.dataDirectory
. In order to have a code that is applicable for all cases (android, ios, browser (with Chrome and Firefox)) we need to use window.resolveLocalFileSystemURL
or when neccessary window.webkitRequestFileSystem
. With this information the code of the question could be changed to.
// Function when Folder is loaded
successFunction = function(dir){
console.log("got main dir", dir.name);
dir.getFile("catalog.json", {create:true}, function(file) {
console.log("got the file", file);
logOb = file;
});
};
// Function for error
errorFunction = function(error){
console.log(error.message);
console.log(error.name);
}
if(cordova.platformId === 'browser'){
if(typeof window.webkitRequestFileSystem !== 'undefined'){
window.webkitRequestFileSystem(
window.PERSISTENT , // Where to look for
1024*1024, // request max available size ( here 1 MB),
function(dir){ successFunction.apply(this, [dir]); };
function(error){ errorFunction.apply(this, [error]); };
});
}
}
window.resolveLocalFileSystemURL(
cordova.file.dataDirectory,
function(dir){ successFunction.apply(this, [dir]); };
function(error){ errorFunction.apply(this, [error]); };
});
I did not check if the code of the question is running like this.