[Feature Request]: Add an event when opening file open dialog from <input type="file" />
- Dominant language
- C++
- Stars
- 123k
- Forks
- 17.5k
- Avg merge
- 14h 28m
- Merged PRs (30d)
- 870
Description
### Preflight Checklist
- [X] I have read the [Contributing Guidelines](https://github.com/electron/electron/blob/main/CONTRIBUTING.md) for this project.
- [X] I agree to follow the [Code of Conduct](https://github.com/electron/electron/blob/main/CODE_OF_CONDUCT.md) that this project adheres to.
- [X] I have searched the [issue tracker](https://www.github.com/electron/electron/issues) for a feature request that matches the one I want to file, without success.
### Problem Description
We are building a secure browser using electron for kiosk devices.
We would like to customize the behavior of file inputs (``).
Indeed, we do not want public users to access the filesystem when using a public kiosk device.
### Proposed Solution
A good way to customize this behavior would be to trigger a new event (eg: `select-file`) when users click on a file input. This event would accept a callback with the selected file.
It allows us to create a custom secured UI for file selection.
Exemple:
```javascript
webContents.on("select-file", (details, callback) => {
// details.accept
// details.multiple
// details.directory
// ...
showCustomUI(details)
.then((selectedFilePath) => callback(selectedFilePath));
});
```
### Alternatives Considered
We tried using a preload script that scans and overrides file inputs but we can't set the file input value manually...
**Edit:**
We were able to set file inputs using debugger (https://github.com/electron/electron/issues/749#issuecomment-1026721073). However, there is a lot of special cases where websites create custom UI for file inputs. I think the only stable and reliable way is to implement a new event.
### Additional Information
We are using `` so this event should be handled correctly in this environment.
Contributor guide
Assessment
This issue has not been assessed yet.