Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: emit an event when accessing restricted path in File System Access API #42993

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
docs: fix doc
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
  • Loading branch information
trop[bot] and codebytere authored Jul 22, 2024
commit dec22ce6f699e73a39f19a28f03a5c402fbe72c9
19 changes: 14 additions & 5 deletions docs/api/session.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ Returns:
* `isDirectory` boolean - Whether or not the path is a directory.
* `path` string - The blocked path attempting to be accessed.
* `callback` Function
* `action` string - Can be one of `block`, `tryAgain`, or `allow`.
* `action` string - The action to take as a result of the restricted path access attempt.
* `block` - This will block the access request and trigger an `AbortError`.
* `tryAgain` - This will open a new file picker and allow the user to choose another path.
* `allow` - This will allow `path` to be accessed despite restricted status.

```js
const { app, dialog, BrowserWindow, session } = require('electron')
Expand All @@ -166,13 +169,19 @@ async function createWindow () {
session.defaultSession.on('file-system-access-restricted', async (e, details, callback) => {
const { origin, path } = details
const { response } = await dialog.showMessageBox({
message: `${origin} can't open ${path} because it contains system files`,
message: `Are you sure you want ${origin} to open restricted path ${path}?`,
title: 'File System Access Restricted',
buttons: ['Choose a different folder', 'Cancel'],
cancelId: 1
buttons: ['Choose a different folder', 'Allow', 'Cancel'],
cancelId: 2
})

callback(response === 1)
if (response === 0) {
callback('tryAgain')
} else if (response === 1) {
callback('allow')
} else {
callback('block')
}
})

mainWindow.webContents.executeJavaScript(`
Expand Down