File System Access API

On this page 7

The File System Access API is a browser interface that lets a web page read, write and save files and directories on the user’s local device through handles obtained from native file pickers, with access controlled by explicit user permission. Among Web APIs, it is the one that allows editors, design tools and integrated development environments in the browser to work with real files instead of uploads and downloads.

The API was incubated in the Web Platform Incubator Community Group and shipped in Chromium-based browsers in 2020. Part of the underlying model, the origin private file system, was later standardized in the WHATWG File System specification and is supported by all major engines, while the picker-based access to user files remains limited to Chromium.

How the File System Access API works

The API is built on handles rather than paths. A page never sees or types a file path; instead it calls a picker method, the browser shows the native operating system dialog, and the user’s choice is returned as a FileSystemFileHandle or FileSystemDirectoryHandle object.

Pickers can be opened only in response to a user gesture, such as a click, and only in a secure context served over HTTPS or from localhost. The following table summarizes the main entry points and what each returns.

MethodReturnsTypical use
showOpenFilePicker()Array of file handlesOpen one or more existing documents
showSaveFilePicker()One file handleSave As to a new or chosen file
showDirectoryPicker()Directory handleOpen a project folder
handle.getFile()File objectRead contents as text, stream or buffer
handle.createWritable()Writable file streamWrite and commit changes
dirHandle.values()Async iterator of entriesList files and subfolders
Main methods of the File System Access API

Writing uses a FileSystemWritableFileStream. Data is first written to a temporary swap file, and the original is replaced only when the stream is closed. This design means that an interrupted save does not leave a half-written document, and it gives the browser a point at which to run Safe Browsing checks before the data reaches disk.

Permission model and security safeguards

Security rests on the principle that the user chooses every file or folder the page can touch. Selecting a file in the open picker grants read access; writing requires a separate write permission, which the browser requests in a prompt the first time the page tries to save.

Handles can be stored in IndexedDB so that an application can offer a list of recent files, but permissions do not automatically survive. When a stored handle is used again, the page calls queryPermission() and, if needed, requestPermission(), which triggers a fresh prompt. The table below lists the main safeguards.

SafeguardWhat it preventsHow it is enforced
User activation requiredSilent background accessPickers open only after a click or key press
Secure context onlyInterception of file dataUnavailable on plain HTTP pages
Blocked locationsAccess to system foldersBrowser refuses sensitive directories
Separate write permissionUnnoticed modificationPrompt before the first write
Swap file and checksPartial or malicious writesCommit only when the stream closes
Visible access indicatorForgotten open permissionsIcon in the address bar
Security safeguards built into the API

Browsers also restrict the API in cross-origin iframes and refuse to open the root of the system drive or folders such as the operating system directory. Even so, Mozilla and Apple have argued that granting websites write access to user files carries risks that ordinary users cannot assess, which is why their engines do not implement the pickers.

The origin private file system

The origin private file system, often abbreviated OPFS, is a storage area that belongs to one origin and is invisible to the user in the operating system. It is reached with navigator.storage.getDirectory(), requires no picker and no permission prompt, and counts against the origin’s storage quota.

Its key strength is speed. In a dedicated worker, createSyncAccessHandle() provides synchronous, in-place reads and writes, which makes OPFS a practical backend for WebAssembly databases such as SQLite compiled to the browser. The comparison below separates the two parts of the API.

PropertyUser-visible filesOrigin private file system
Access methodNative pickersnavigator.storage.getDirectory()
User permissionRequired per file or folderNot required
Visible in file managerYesNo
Browser supportChromium-based browsersAll major engines
Synchronous accessNoYes, in workers
Typical useDocument and code editorsDatabases, caches, working files
User-visible files compared with the origin private file system

How it compares with other storage and file options

The API fills a gap that older web file mechanisms could not cover: saving back to the same file. The table below places it among related Web APIs and classic techniques.

OptionCan write to user filesMain limitation
input type fileNoRead-only copy of the selected file
Download linkCreates a new file onlyCannot overwrite the original
File System Access APIYes, after permissionLimited browser support for pickers
IndexedDBNoData stays inside browser storage
Web Storage APINoSmall, synchronous, string-only storage
File and storage options available to web pages

Because support is uneven, production applications use feature detection and fall back to file inputs and downloads when showOpenFilePicker is missing. Small open-source wrapper libraries implement exactly this progressive enhancement pattern.

Practical limitations and common mistakes

  • Calling a picker without a user gesture throws a SecurityError, for example when it runs after an awaited network request.
  • Forgetting to call close() on a writable stream leaves the changes uncommitted in the swap file.
  • Assuming stored handles keep their permission leads to failed saves; always re-check permission on reuse.
  • Treating OPFS as backup storage is risky, because clearing site data deletes it without warning.
  • Writing large files in many tiny chunks is slow; buffer data and write in larger blocks.

Developers should also remember that folder access is recursive. Granting a directory handle exposes every file below it, so applications should ask for the narrowest folder they need and explain why before opening the picker.

Put simply

Normally a website can only take a copy of a file you upload, and it gives back a new copy when you download. It cannot change the original file on your computer.

The File System Access API changes that, but only with your permission. You pick a file or folder in the usual window from your computer, and the website may then open it and save changes back to the same file, much like a desktop program. Without your choice, the site sees nothing.

In practice

A technical writer maintains a documentation project of about 300 Markdown files on a company laptop and uses a browser-based editor instead of an installed program.

She clicks Open folder, chooses the project directory in the system dialog and confirms the prompt. The editor lists the files through the directory handle, and every press of Ctrl+S writes the change straight to disk through a writable stream. The editor stores the handle in IndexedDB, so the next morning one click and one permission prompt reopen the same folder.

Her changes appear immediately in the local Git client, with no upload, download or duplicate files. On a colleague’s browser without picker support, the same editor falls back to file uploads and downloads, which still works but requires saving each file manually.