I'm trying to port my existing SPA web app to Electron in order to make it a desktop app, working fully offline from executable. This app is meant to store user's data in file system (in a directory chosen by user) and I use FileSystem API to access it.
I want user to choose target directory once and after he chooses one, directory should be opened automatically at app startup.
In order to do this I save directory handle in IndexedDB, the same way like it's shown here Storing file handles or directory handles in IndexedDB, I queryPermission
and when it does not return "granted", I use requestPermission
to restore it.
In the browser it seems to be working fine. There is an option "Allow on every visit" and when I check it, I can close the browser, enter my website again and my app automatically loads data from remembered directory just like I wanted.
This doesn't seem to work the same way in Electron app. Every time I open it, it prevents me from accessing directory:
SecurityError: Failed to execute 'requestPermission' on 'FileSystemHandle': User activation is required to request permissions.
If permission cannot be acquired, my app shows a button that lets user try again and when he click this button, requestPermission
is called again and this time it works: directory is being loaded (even without requiring user to choose directory again from filepicker).
So this shows that my app stores directory handle correctly and it correctly requests to regain access to it, but Electron requires manual user interaction (or: "user gesture") to do it.
My question is: Can I regain permission directory without user gesture in Electron? Is there some equivalent of "Allow on every visit" checkbox in Electron (which is missing now, as no address bar is visible in my app)?
This is a known issue in Electron JS. The support for persistent permissions is not yet implemented in Electron. Prior to version 30, it was possible to bypass the permissions by enabling experimental features using the switch - enable-experimental-web-platform-features
. But now it is not possible.
So, at the moment you have two options:
enable-experimental-web-platform-features
.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With