Closed siquylee closed 2 years ago
I solved it
Do you want to share the solution for others who might come here? Thanks in advance if you can!
Sharing a possible solution in here in case anyone else encounters this.
This error message is displayed when the browser loses file access permissions (in my case it was due to a page refresh - trying to access a previously stored file handle). I encountered it when calling fileHandle.getFile()
, but it might happen under other circumstances - like in the OPs case (fileSave).
The solution is to re-grant file permissions like below:
// The return values are optional, but you can use them for tracking permission state
async function hasPermission(fileHandle) {
if ((await fileHandle.queryPermission()) === "granted") return true; // Permission already granted
if ((await fileHandle.requestPermission()) === "granted") return true; // Prompt user for permission
return false; // Permission denied
}
async function loadFileFromHandle(fileHandle) {
const permitted = await hasPermission(fileHandle);
return premitted ? fileHandle.getFile() : null;
}
fileSave works fine with Google Chrome but it threw an exception DOMException: The request is not allowed by the user agent or the platform in the current context when I ran with Microsoft Edge. Please advise.