Repository navigation
fix(browser): let pages use files picked, saved or dropped through File System Access - #32970
Conversation
…Access Electron reads every File System Access grant from the session's check handler, which denied fileSystem, so picked, saved and dropped handles were all refused. Routed pages stay denied: another machine can script them. Fixes #25750
69dd768 to
9d8a927
Compare
|
No actionable comments were generated in the recent review.
|
ELI5
Web apps that open a folder or save a file through the browser's File System Access API (
showDirectoryPicker(),showOpenFilePicker(),showSaveFilePicker(), dragging a file onto the page) didn't work in Orca's browser. The dialog opened, but Orca refused the page access to whatever you picked. Now the file or folder you choose works, like in Chrome.What Changed
showDirectoryPicker()opened the folder dialog, then rejected withAbortError: The user aborted a request.Files fromshowOpenFilePicker()/showSaveFilePicker()were unusable. A dropped file'sgetAsFileSystemHandle()handle reportedread=deniedandgetFile()threwNotAllowedError. Dropping or picking a blocked system folder (home,~/Library) left the promise pending forever.AbortError, and the browser pane shows Orca's existing notice: "… asked for access to your files or folders, and Orca denied it."How it works: Electron doesn't use Chromium's own File System Access grants once an app installs a permission check handler. Every grant's status comes from that handler (
PermissionGrantImpl::GetStatus()in Electron'sfile_system_access_permission_context.cc). Orca's browser session policy said no tofileSystem, so every handle was refused, including the ones Chromium grants itself for open, save and drop. The browser session policy (browser-session-partition-policies.ts) now grantsfileSystem. It also answers Electron'sfile-system-access-restrictedevent withdeny, because a request with no listener never finishes.Why
The policy is the only layer that decides this, and Electron gives it a single yes or no for each grant, so the fix is there.
Design
fileSystemin both the request and check handlers on browsing partitions. Picking or dropping is the user's consent. Chromium still blocks pickers in cross-origin iframes, requires a user gesture to open a picker, and applies its blocklist of system folders.fileSystemAccess: falsefrominstallBrowserRoutePartitionPolicies). Those are SSH-routed tabs and client-hosted pages of a paired runtime. Another machine can script them: an SSH host can runbrowser.eval. A page there could reuse a handle saved in IndexedDB to read or write files on this desktop. This follows the existing rule that stops SSH-driven pages from downloading into this desktop.denyand the existing denial notice. Doc-preview partitions get a silentdeny, so a drop on a preview can't hang.GetStatus()only returns granted or denied, never "ask". SorequestPermission()andcreateWritable()never reach the request handler. A save-picker write grant also looks the same as one for an opened file. Denying writes would breakshowSaveFilePicker().tryAgainfor blocked folders. Electron reopens the picker with no explanation, and it means nothing for drops.Page.fileChooserOpened→dialog.showOpenDialogbridge, as [Bug]: Embedded browser file inputs never open a native file picker (ChatGPT / any site) #15621 suggested. It isn't needed, see below.Open questions for Kelvin
Linked Issue
Fixes #25750
#15621 (
<input type=file>never opens a dialog) doesn't reproduce on current main. In a hidden dev build, a real CDP click on<input type=file>opened the native macOS open panel; I saw its window appear and the input fired neitherchangenorcancelwhile it was open. The issue blamed the debugger that the old anti-detection script attached to every guest, and #18749 removed that script. Nothing here changes it, so I left it unlinked. It can be closed.Visual Proof
Drag and drop, recorded in a hidden dev build. Each video drops a file, then a folder, then
~/Library. A native picker dialog can't be recorded without showing a window on my desktop. The pickers go through the same grant check as drops (see Testing).Light: before
before-drop-light.mp4
Light: after
after-drop-light.mp4
Dark: before
before-drop-dark.mp4
Dark: after
after-drop-dark.mp4
Testing
On macOS, in a hidden dev build, with a local test page and real CDP input:
<input type=file>andshowDirectoryPicker(): on main the native panel opens (checked forsingleand the directory picker;multiple,accept=andwebkitdirectorytake the same chooser path). This PR doesn't touch how the dialog opens, only what the page may do with the pick.NotAllowedError.~/Librarynow ends in an immediateAbortErrorplus the notice. Before, it was pending forever.I couldn't run a full pick through the native panel. It opens as a sheet, and the sheet brings the hidden window onto the screen even after
app.hide(). The pickers use the sameGetStatus()check as drops, so the drop results cover them. A quick manual check would still help: on a visible build, clickshowDirectoryPicker()andshowSaveFilePicker()on any FSA demo page.Two tests in
browser-session-partition-policies.test.ts. One checks that browsing partitions grantfileSystemand route partitions (through the real route installer) deny it with a notice. The other checks that blocked folders getdeny, with a notice on browsing partitions and none on doc previews. Both fail with main's policy, and removing the route option fails the first.Locally:
pnpm tc:node,check:code-quality:changed,check:react-doctor:changed, and the focused tests. Full CI only runs once this leaves draft.AI Disclosure
Review
Agent skill upstream boundary
Notes
<input type=file>and is out of scope.Page.fileChooserOpened) and the phone to upload what the user picks. That's a separate feature.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)