Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
Non-standard: This feature is not standardized. We do not recommend using non-standard features in production, as they have limited browser support, and may change or be removed. However, they can be a suitable alternative in specific cases where no standard option exists.
The observe() method of the FileSystemObserver interface asks the observer to start observing changes to a given file or directory.
observe(handle) observe(handle, options)
handleThe handle of the file system entry representing the file or directory to observe.
FileSystemFileHandle or a FileSystemDirectoryHandle.FileSystemFileHandle, a FileSystemDirectoryHandle, or a FileSystemSyncAccessHandle.options OptionalAn object specifying options for the observe() call. This can contain the following properties:
recursiveA boolean specifying whether you want to observe changes to a directory recursively. If set to true, changes are observed in the directory itself and all contained subdirectories and files. If set to false, changes are only observed in the directory itself and directly contained files (that is, files in subdirectories are excluded). Defaults to false.
This property has no effect if handle represents a file.
A Promise that resolves to undefined.
NotFoundError DOMException
Thrown if the file or directory represented by handle could not be found.
Assuming a FileSystemObserver instance is available, you can start observing changes to a file system entry by calling observe().
You can observe a file or directory in the user-observable file system or the Origin Private File System (OPFS) by passing a FileSystemFileHandle or FileSystemDirectoryHandle to observe(). Instances of these objects can be returned, for example, when asking the user to select a file or directory using Window.showSaveFilePicker() or Window.showDirectoryPicker():
// Observe a file
async function observeFile() {
const fileHandle = await window.showSaveFilePicker();
await observer.observe(fileHandle);
}
// Observe a directory
async function observeDirectory() {
const directoryHandle = await window.showDirectoryPicker();
await observer.observe(directoryHandle);
}
You can also observe changes to the OPFS by passing a FileSystemSyncAccessHandle to observe():
// Observe an OPFS file system entry
async function observeOPFSFile() {
const root = await navigator.storage.getDirectory();
const draftHandle = await root.getFileHandle("draft.txt", { create: true });
const syncHandle = await draftHandle.createSyncAccessHandle();
await observer.observe(syncHandle);
}
To observe a directory recursively, call observe() with the recursive option set to true:
// Observe a directory recursively
async function observeDirectory() {
const directoryHandle = await window.showDirectoryPicker();
await observer.observe(directoryHandle, { recursive: true });
}
Not currently part of a specification. See https://github.com/whatwg/fs/pull/165 for the relevant specification PR.
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
observe |
133 | 133 | No | 118 | No | No | No | No | No | No | No | No |
© 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/FileSystemObserver/observe