GoogleChromeLabs / browser-fs-access

File System Access API with legacy fallback in the browser
https://googlechromelabs.github.io/browser-fs-access/demo/
Apache License 2.0
1.37k stars 82 forks source link

Get confusing mime type results with Chrome and mac OS #143

Closed gplanansky closed 1 year ago

gplanansky commented 1 year ago

On macOS using Chrome, hence the File Access API, there is a confused mapping between specified acceptable mime types and the files actually offered by the the pop-up file selector dialog.

Reproduce: MacOS Ventura 13.4.1 Chrome: Version 114.0.5735.198 (Official Build) (arm64) browser-fs-access version: 0.34.1

Using the browser-fs-access-main/demo:

  1. download the github dist: https://github.com/GoogleChromeLabs/browser-fs-acces/sarchive/refs/heads/main.zip

  2. tweak script.mjs to s.t. the "Open Image or Text Files" button is configured the more restrictive "text/plain" mime type:

$ diff script.mjs script.mjs.orig 
116c116
<           mimeTypes: ['text/plain'],
---
>           mimeTypes: ['text/*'],
  1. serve on localhost: "python -m http.server"
  2. in chrome: http://localhost:9000/browser-fs-access-main/demo/
Screenshot 2023-06-29 at 3 05 25 PM
  1. select the "Open Image or Text Files" button.
  2. in the pop up file selector dialog: Show Options --> Format "Text Files"
Screenshot 2023-06-29 at 3 05 52 PM

You can see that while the macOS selector window indicates various file types, it offers (un-greyed) files it indicates are not plain text; does not offer some files it indicates are plain text. And identifies some files as plain text which have .latex and .geojson extensions.

Am I missing something about how this should work? A value of the File System Access API is the proffered means to configure acceptable file types, but the above result will confuse users. In which case it would be better to accept all files at the pop up selector and deal with wrong choices after the fact. thanks

tomayac commented 1 year ago

This is (unfortunately) working as intended. macOS has some very interesting design choices, for example, you can't QuickView some plain text files, even if the OS knows the contents is purely textual. The file picker dialog inherits these choices. I would try to list the extensions you expect your app to handle, as this seems to be a more reliable way to make the file picker do what you want.