FileSystemHandle: queryPermission() method
The queryPermission()
method of the FileSystemHandle
interface queries the current permission state of the current handle.
Syntax
queryPermission(fileSystemHandlePermissionDescriptor)
Parameters
-
FileSystemHandlePermissionDescriptor Optional
-
An object which specifies the permission mode to query for. Options are as follows:
'mode'
: Can be either 'read'
or 'readwrite'
.
Return value
PermissionStatus.state
which is one of 'granted'
, 'denied'
or 'prompt'
.
If this returns "prompt" the website will have to call requestPermission() before any operations on the handle can be done. If this returns "denied" any operations will reject. Usually handles returned by the local file system handle factories will initially return "granted" for their read permission state. However, other than through the user revoking permission, a handle retrieved from IndexedDB is also likely to return "prompt".
Exceptions
-
TypeError
-
Thrown if mode
is specified with a value other than 'read'
or 'readwrite'
Examples
The following asynchronous function returns true if user has granted read or readwrite permissions to the file handle. Permission is requested if not.
async function verifyPermission(fileHandle, withWrite) {
const opts = {};
if (withWrite) {
opts.mode = "readwrite";
}
if ((await fileHandle.queryPermission(opts)) === "granted") {
return true;
}
if ((await fileHandle.requestPermission(opts)) === "granted") {
return true;
}
return false;
}
Specifications
Browser compatibility
|
Desktop |
Mobile |
|
Chrome |
Edge |
Firefox |
Internet Explorer |
Opera |
Safari |
WebView Android |
Chrome Android |
Firefox for Android |
Opera Android |
Safari on IOS |
Samsung Internet |
queryPermission |
86 |
86 |
No |
No |
72 |
No |
No |
86 |
No |
61 |
No |
14.0 |
See also