electron: [Bug]: Missing permissions dialog for FileSystem API.

Preflight Checklist

Electron Version

12.0.0

What operating system are you using?

Ubuntu

Operating System Version

Linux meerkat 5.8.0-7642-generic #47~1614007149~20.10~82fb226-Ubuntu SMP Tue Feb 23 02:59:01 UTC x86_64 x86_64 x86_64 GNU/Linux

What arch are you using?

x64

Last Known Working Electron version

n/a

Expected Behavior

When using the File System Access API, attempting to write to a file using the FileSystemWritableFileStream API should cause a permission prompt to pop up that the user can accept or deny.

In Electron’s case, it should probably trigger the setPermissionRequestHandler handler with a permission set to something like filesystem and a path to the file being requested.

Actual Behavior

When invoking fileHandle.createWritable(), the following error gets thrown:

Uncaught DOMException: The request is not allowed by the user agent or the platform in the current context.

Testcase Gist URL

https://github.com/RangerMauve/electron-filesystem-prompt-example

Continuation of #23608

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 18
  • Comments: 38 (6 by maintainers)

Commits related to this issue

Most upvoted comments

This issue is still relevant!

Just commenting so that the team knows another person would like to see the File System Access API to be supported by electron.

Hello from Electron 25.0.1. Not stale. 😃

I also need support for the File System Access API (aka Native File System API). However, we don’t need the permissions dialogue to show, since we have File Access in Electron apps. We simply need the system to grant access automatically to read the filesystem if we have the file or directory handle (which can be serialized to IndexedDB and re-used across app launches)

Making some progress:

Screenshot 2024-02-22 at 5 28 26 PM

Hey folks - i’ve opened a draft PR. Feedback welcome.

Just commenting so that the team knows another person would like to see the File System Access API to be supported by electron. Not only do I need to complicate my code base by having BOTH Electrons API and File System Access API, but Electrons dialog API does not provide an easy way to create a Writable File Stream as the File System Access API does. I am able to use the File System Access API for saving/creating a new file, but I get permissions issues when I try to use the filesystem handler that gets returned.

Hoping for support in the future!

I tried Electron 16.0.4 version in my mac: 12.0.1, Must add below line to enable the experimental feature

app.commandLine.appendSwitch("enable-experimental-web-platform-features");

then the permission will alway be true (won’t prompt the window)

This is still an issue in Electron 20

Still an isssu in 23+

I’ve just tested with 15.3.0 on Windows 11, and the bug is still unresolved. You can use the File System Access API to open and read the contents of a directory, and to pick a single file, and that all works well, but as soon as you try to use the filesystem handle that you serialized to indexedDB, the access is denied and no verify prompt is issued.

The way NWJS does it is simply always to return true when you run fileHandle.queryPermissions(). No prompt is shown, access is simply granted. The beauty of this is that you don’t need to code special use of Node APIs, you can simply code once, and it’ll work both in a PWA and in Electron, with the latter acting the same way as if you had used Node APIs.

The only workaround is to use Node APIs to get the path to a file or folder, and store that instead of the fileSystemHandle. But this is clunky.

It’s good to know! Unfortunately for me, I already worked around this by using Electron APIs, complicating my codebase when I was hoping to simplify it. I’ll definitely look to revert at some point to the File System Access API: it’s much better IMHO.

Still an issue on v13 (13.1.9) and v14 (14.0.0), tested on Windows 10

@ckerr Can you kindly add 15-x-y label to this issue, and also add platform/windows or platform/all, because it relates to a Chromium API that is not properly supported and the issue is present on Windows and Linux at least (I confirm the bug persists on both OS’s with 15.3.0).

Not a solution, just a workaround: it’s possible to write your own polyfill for showSaveFilePicker using ipc and Node’s fs API – a simple example in https://gist.github.com/zbynek/f0d3bca71db9cbfd9ec30873ab04a45e .

Leaving another comment because I’ve been credited twice now for the workaround which @altjz mentioned here: https://github.com/electron/electron/issues/28422#issuecomment-987504138. Can’t believe this API is still locked behind experimental web platform features after all this time.

I only need to be able to read files. @RayDawn’s tip above, to use app.commandLine.appendSwitch("enable-experimental-web-platform-features"); works very well for my purpose. Obviously it would be good if someone else could verify whether this also enables writing to picked files (and re-using a serialized file handle). There is no permissions dialogue, by the way, it simply returns permission granted as if the user had given permission. It works (for reading) on picked files and picked folders.

I tried Electron 16.0.4 version in my mac: 12.0.1, Must add below line to enable the experimental feature

app.commandLine.appendSwitch("enable-experimental-web-platform-features");

then the permission will alway be true (won’t prompt the window)

Holy hell this was a lifesaver. I’ve been searching for what feels like ages, I was beginning to think I was the only person having this problem.

To add to this: Verified that this is still a problem on Electron version 17.0.0, platform is macOS.