W3cubDocs

/Web APIs

FileSystemHandle: requestPermission() method

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

Note: This feature is available in Web Workers.

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The requestPermission() method of the FileSystemHandle interface requests read or readwrite permissions for the file handle.

Syntax

requestPermission(descriptor)

Parameters

descriptor Optional

An object which specifies the permission mode to query for. Options are as follows:

'mode' Optional

Can be either 'read', 'write', or 'readwrite'.

Return value

A Promise that resolves with PermissionStatus.state which is one of 'granted', 'denied' or 'prompt'. It may also reject with one of the exceptions below.

Exceptions

TypeError

Thrown if no parameter is specified or the mode is not that of 'read', 'write', or 'readwrite'

SecurityError DOMException

Thrown in one of the following cases:

  • The method was called in a context that's not same-origin as the top-level context (i.e., a cross-origin iframe).
  • There was no transient user activation such as a button press. This includes when the handle is in a non-Window context which cannot consume user activation, such as a worker.

Security

Transient user activation is required. The user has to interact with the page or a UI element in order for this feature to work.

Examples

The following asynchronous function requests permissions if they have not been granted.

// fileHandle is a FileSystemFileHandle
// withWrite is a boolean set to true if write

async function verifyPermission(fileHandle, withWrite) {
  const opts = {};
  if (withWrite) {
    opts.mode = "readwrite";
  }

  // Check if we already have permission, if so, return true.
  if ((await fileHandle.queryPermission(opts)) === "granted") {
    return true;
  }

  // Request permission to the file, if the user grants permission, return true.
  if ((await fileHandle.requestPermission(opts)) === "granted") {
    return true;
  }

  // The user did not grant permission, return false.
  return false;
}

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Opera Safari Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet WebView Android WebView on iOS
requestPermission 86 86 No 72 No 109 No 74 No 21.0 109 No

See also

© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/FileSystemHandle/requestPermission