Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editorial review: Document FileSystemObserver #38270

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

chrisdavidmills
Copy link
Contributor

@chrisdavidmills chrisdavidmills commented Feb 21, 2025

Description

Chrome 133 supports the FileSystemObserver interface, which allows you to observe changes to the underlying file system via a standard observer mechanism.

This PR adds documentation for the new functionality, which mainly consists of new reference pages for the new interface.

Note that the feature is currently non-standard (see whatwg/fs#165), although it should be added to the spec soon. I have currently documented it as such.

Motivation

Additional details

See the relevant ChromeStatus entry for data: https://chromestatus.com/feature/4622243656630272

Relevant blog post: https://developer.chrome.com/blog/file-system-observer#start_observing_a_file_or_directory

Related issues and pull requests

Related BCD: mdn/browser-compat-data#25986

@chrisdavidmills chrisdavidmills requested review from a team as code owners February 21, 2025 14:48
@chrisdavidmills chrisdavidmills requested review from sideshowbarker and pepelsbey and removed request for a team February 21, 2025 14:48
@github-actions github-actions bot added Content:WebAPI Web API docs size/m [PR only] 51-500 LoC changed labels Feb 21, 2025
Copy link
Contributor

github-actions bot commented Feb 21, 2025

Preview URLs (6 pages)
Flaws (6)

Note! 5 documents with no flaws that don't need to be listed. 🎉

URL: /en-US/docs/Web/API/File_System_API
Title: File System API
Flaw count: 6

  • broken_links:
    • /en-US/docs/Web/API/window/showOpenFilePicker is ill cased
    • /en-US/docs/Web/API/window/showDirectoryPicker is ill cased
    • /en-US/docs/Web/API/window/postMessage is ill cased
  • macros:
    • Macro produces link /en-US/docs/Web/API/window/showOpenFilePicker which is a redirect
    • Macro produces link /en-US/docs/Web/API/window/showDirectoryPicker which is a redirect
    • Macro produces link /en-US/docs/Web/API/window/postMessage which is a redirect
External URLs (14)

URL: /en-US/docs/Web/API/FileSystemChangeRecord
Title: FileSystemChangeRecord


URL: /en-US/docs/Web/API/FileSystemObserver
Title: FileSystemObserver


URL: /en-US/docs/Web/API/FileSystemObserver/observe
Title: FileSystemObserver: observe() method


URL: /en-US/docs/Web/API/FileSystemObserver/FileSystemObserver
Title: FileSystemObserver: FileSystemObserver() constructor


URL: /en-US/docs/Web/API/FileSystemObserver/disconnect
Title: FileSystemObserver: disconnect() method

(comment last updated: 2025-02-25 11:20:06)

@chrisdavidmills chrisdavidmills changed the title Document FileSystemObserver Technical review: Document FileSystemObserver Feb 21, 2025
Copy link
Contributor

@tomayac tomayac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great. Left a bunch of suggestions.

@chrisdavidmills
Copy link
Contributor Author

@tomayac thanks for the review! I think I've answered everything. Let me know if you feel this needs anything else, or give me an LGTM if you are happy with it.

@chrisdavidmills chrisdavidmills changed the title Technical review: Document FileSystemObserver Editorial review: Document FileSystemObserver Feb 24, 2025
@wbamberg wbamberg requested review from wbamberg and removed request for tomayac February 24, 2025 16:39
Comment on lines 30 to 32
#### `FileSystemChangeRecord` structure

`FileSystemChangeRecord` objects have the following structure:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there are really two ways of dealing with dictionaries:

  1. document them inline as anonymous objects (so under the records bullet above say something like "an array of objects contain details of all the observed changes. Each object has the following properties:"
  2. document them in separate pages, like we do for example with https://developer.mozilla.org/en-US/docs/Web/API/RequestInit.

Because this is quite a complex object it might be worth going with (2) here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I've given it a go. My next commit now contains a new FileSystemChangeRecord page, which is included in the sidebar and linked to from the appropriate places.

### 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 tasked to observe (via {{domxref("FileSystemObserver.observe()")}}). The callback function body can be specified to return and process file change observations in any way you want, however, it always includes the following two parameters:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- : A user-defined callback function that will be called when the observer has observed a change in the file system entry it has been tasked to observe (via {{domxref("FileSystemObserver.observe()")}}). The callback function body can be specified to return and process file change observations in any way you want, however, it always includes the following two parameters:
- : 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 (via {{domxref("FileSystemObserver.observe()")}}). The callback function will be passed following two parameters:

Subjective I suppose but surely it's obvious that you can implement the callback however you like?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I've implemented this change in my next commit, with a small tweak.

}
```

or a {{domxref("FileSystemSyncAccessHandle")}} for the OPFS:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As before this reads like you're duplicating the syntax description.

I would say, for example, something like:

Once a FileSystemObserver instance is available, you can start observing changes to a file system entry.

You can observe a file or a directory in the user-visible file system, for example by asking the user to select a file or directory using window.showSaveFilePicker() or window.showDirectoryPicker():

(example)

You can also observe a file in the OPFS:

(example)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call; I've updated this as suggested

### Parameters

- `handle`
- : The handle of the file system entry representing the file or directory to observe. This can be a {{domxref("FileSystemFileHandle")}} or {{domxref("FileSystemDirectoryHandle")}} for the user-observable file system and the [Origin Private File System](/en-US/docs/Web/API/File_System_API/Origin_private_file_system) (OPFS), or a {{domxref("FileSystemSyncAccessHandle")}} for the OPFS.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as before:

Suggested change
- : The handle of the file system entry representing the file or directory to observe. This can be a {{domxref("FileSystemFileHandle")}} or {{domxref("FileSystemDirectoryHandle")}} for the user-observable file system and the [Origin Private File System](/en-US/docs/Web/API/File_System_API/Origin_private_file_system) (OPFS), or a {{domxref("FileSystemSyncAccessHandle")}} for the OPFS.
- : The handle of the file system entry representing the file or directory to observe.
- For the user-observable file system, this can be a {{domxref("FileSystemFileHandle")}} or a {{domxref("FileSystemDirectoryHandle")}}.
- For the [Origin Private File System](/en-US/docs/Web/API/File_System_API/Origin_private_file_system) (OPFS), it can be or a a {{domxref("FileSystemFileHandle")}}, a {{domxref("FileSystemDirectoryHandle")}}, or a {{domxref("FileSystemSyncAccessHandle")}}.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated


### Observe a file or directory

Assuming a `FileSystemObserver` instance is available, you can start observing changes to a file system entry by calling the `observe()` method on it, passing it the handle of the entry to observe. This can be a {{domxref("FileSystemFileHandle")}} or {{domxref("FileSystemDirectoryHandle")}} for the user-observable file system and the [Origin Private File System](/en-US/docs/Web/API/File_System_API/Origin_private_file_system) (OPFS):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As before, I think explaining the different use cases is more helpful in an example than duplicating the types you can pass.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated, same as the other page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:WebAPI Web API docs size/m [PR only] 51-500 LoC changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants