electron / electron/electron

[Feature Request]: Add an event when opening file open dialog from <input type="file" />

Open
#32,671 11 comments 1 reaction 0 assignees View on GitHub
enhancement :sparkles:
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.