Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. FileSystemObserver
  4. FileSystemObserver()

FileSystemObserver: FileSystemObserver() constructor

Experimental:This is anexperimental technology
Check theBrowser 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.

TheFileSystemObserver() constructor creates a newFileSystemObserver object instance.

Syntax

js
new FileSystemObserver(callback)

Parameters

callback

A user-defined callback function that will be called when the observer has observed a change in the file system entry it has been asked to observe (viaFileSystemObserver.observe()). The callback function will be passed the following two parameters:

records

An array ofFileSystemChangeRecord objects that contain details of all the observed changes.

observer

A reference to the currentFileSystemObserver object, which is made available in case, for example, you want to stop observations after the current records have been received using theFileSystemObserver.disconnect() method.

Return value

A newFileSystemObserver object.

Examples

Note:For a complete working example, check outFile System Observer Demo (source code).

Initializing aFileSystemObserver

Before you can start observing file or directory changes, you need to initialize aFileSystemObserver to handle the observations:

js
const observer = new FileSystemObserver(callback);

The callback function body can be specified to return and process file change observations in any way you want:

js
const callback = (records, observer) => {  for (const record of records) {    console.log("Change detected:", record);    const reportContent = `Change observed to ${record.changedHandle.kind} ${record.changedHandle.name}. Type: ${record.type}.`;    sendReport(reportContent); // Some kind of user-defined reporting function  }  observer.disconnect();};

Specifications

Not currently part of a specification. Seehttps://github.com/whatwg/fs/pull/165 for the relevant specification PR.

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2026 Movatter.jp