electron: [Bug]: showItemInFolder hangs macOS Finder for about a minute
Preflight Checklist
- I have read the Contributing Guidelines for this project.
- I agree to follow the Code of Conduct that this project adheres to.
- I have searched the issue tracker for a bug report that matches the one I want to file, without success.
Electron Version
25.0.1
What operating system are you using?
macOS
Operating System Version
macOS Ventura 13.4
What arch are you using?
x64
Last Known Working Electron version
24.4.0
Expected Behavior
import { shell } from "electron";
shell.showItemInFolder("/path/to/file.ext");
This should open the folder and highlight the file in it
Actual Behavior
In renderer process it leads to Finder’s “Not Responding” state for about a minute, and then it show the file. Meanwhile in main process it works as expected
Testcase Gist URL
https://gist.github.com/Nesvet/8700b509a57043453b1e6e027cc0c85e
Additional Information
No response
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 9
- Comments: 15 (10 by maintainers)
I see… I’l do this from now on. I’ve disabled remote myself for security reasons so am using IPC, but it’s working great and would consider this issue closed.
The code for those wondering:
In main:
In renderer:
Because it’s easy for devs to miss this even if electron produces security warnings, I’d suggest that electron should throw a top-level error if these kinds of API calls are made in a sandboxed environment, if it doesn’t already.
Yes this is still happening. Calling
showItemInFolderfrom render process hangs Finder, my solution: Use IPC Messages to expose it and call it from main process:handle it in main process:
and call it in render.js or wherever you need it:
If this function no longer works in the renderer and is not intending to be fixed, maybe it should just be removed?
Hey folks, just stumbled across this one as well – I have a non-sandboxed renderer process and other methods in the
shellmodule can be called successfully (eg:require('electron').shell.openPath('...')). It seems this bug is specific toshowItemInFolder, and hangs the Finder for 60s. Until this is fixed, I think calling it from the main process only is the best bet.Sidenote: I’m upgrading an Electron app from v24 => v30 and this is one of the only regressions I’ve found - impressive considering I’m behind 20+ months of updates!
We define the function in main process now and invoke it from renderer. This can be done through https://www.npmjs.com/package/@electron/remote or IPC.