Skip to content

File picker allows selecting directories if their name includes a file extension #48081

@jtbandes

Description

@jtbandes

Preflight Checklist

Electron Version

37.2.6

What operating system(s) are you using?

macOS

Operating System Version

macOS 15.5

What arch are you using?

arm64 (including Apple Silicon)

Last Known Working Electron version

No response

Does the issue also appear in Chromium / Google Chrome?

Yes

Expected Behavior

The file picker (<input type=file>, showOpenFilePicker) should not allow selecting directories, only files.

Actual Behavior

The file picker allows selecting directories if they match some of the given file extensions. The directory is exposed to JS as a File / FileSystemFileHandle, but fails to be read.

For example, the following code:

window.showOpenFilePicker({
    multiple: true,
    types: [
      {
        accept: {
          "application/octet-stream": [".foobar"],
        },
      },
    ],
  });

allows choosing directories named with ".foobar" even though they are not files. Trying to read the file fails with an unclear error message.

repro.mov

Testcase Gist URL

https://gist.github.com/jtbandes/98f048be7671b36105e656939c64d633

Additional Information

I have also filed an issue upstream with Chrome at https://issues.chromium.org/issues/438779953

However, I have noticed that Electron already has some custom behavior around file picking of directories (see below), so I am also filing a bug here, in case it makes sense to add any workarounds or patches to Electron.

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions