Get to know MDN better
This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2023.
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
Note: This feature is only available in Dedicated Web Workers.
The createSyncAccessHandle() method of the FileSystemFileHandle interface returns a Promise which resolves to a FileSystemSyncAccessHandle object that can be used to synchronously read from and write to a file. The synchronous nature of this method brings performance advantages, but it is only usable inside dedicated Web Workers for files within the origin private file system.
Creating a FileSystemSyncAccessHandle takes an exclusive lock on the file associated with the file handle. This prevents the creation of further FileSystemSyncAccessHandles or FileSystemWritableFileStreams for the file until the existing access handle is closed.
An object with the following properties:
mode OptionalA string specifying the locking mode for the access handle. The default value is "readwrite". Possible values are:
"read-only"Multiple FileSystemSyncAccessHandle objects can be opened simultaneously on a file (for example when using the same app in multiple tabs), provided they are all opened in "read-only" mode. Once opened, read-like methods can be called on the handles — read(), getSize(), and close().
"readwrite"Only one FileSystemSyncAccessHandle object can be opened on a file. Attempting to open subsequent handles before the first handle is closed results in a NoModificationAllowedError exception being thrown. Once opened, any available method can be called on the handle.
"readwrite-unsafe"Multiple FileSystemSyncAccessHandle objects can be opened simultaneously on a file, provided they are all opened in "readwrite-unsafe" mode. Once opened, any available method can be called on the handles.
A Promise which resolves to a FileSystemSyncAccessHandle object.
Thrown if the PermissionStatus.state for the handle is not granted in readwrite mode.
InvalidStateError DOMExceptionThrown if the FileSystemSyncAccessHandle object does not represent a file in the origin private file system.
NotFoundError DOMExceptionThrown if current entry is not found.
NoModificationAllowedError DOMExceptionThrown if the browser is not able to acquire a lock on the file associated with the file handle. This could be because mode is set to readwrite and an attempt is made to open multiple handles simultaneously.
The following asynchronous event handler function is contained inside a Web Worker. The snippet inside it creates a synchronous file access handle.
Our createSyncAccessHandle() mode test example (see the source code) provides an <input> field to enter text into, and two buttons — one to write entered text to the end of a file in the origin private file system, and one to empty the file when it becomes too full.
Try exploring the demo above, with the browser developer console open so you can see what is happening. If you try opening the demo in multiple browser tabs, you will find that multiple handles can be opened at once to write to the file at the same time. This is because mode: "readwrite-unsafe" is set on the createSyncAccessHandle() calls.
Below we'll explore the code.
The two <button> elements and text <input> field look like this:
The main thread JavaScript inside the HTML file is shown below. We grab references to the write text button, empty file button, and text input field, then we create a new web worker using the Worker() constructor. We then define two functions and set them as event handlers on the buttons:
The worker JavaScript is shown below.
First, we run a function called initOPFS() that gets a reference to the OPFS root using StorageManager.getDirectory(), creates a file and returns its handle using FileSystemDirectoryHandle.getFileHandle(), and then returns a FileSystemSyncAccessHandle using createSyncAccessHandle(). This call includes the mode: "readwrite-unsafe" property, allowing multiple handles to access the same file simultaneously.
Inside the worker's message event handler function, we first get the size of the file using getSize(). We then check to see whether the data sent in the message includes a command property value of "empty". If so, we empty the file using truncate() with a value of 0, and update the file size contained in the size variable.
If the message data is something else, we:
| File System # api-filesystemfilehandle-createsyncaccesshandle |
Enable JavaScript to view this browser compatibility table.
This page was last modified on Jul 4, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.