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

[Bug]: showItemInFolder hangs macOS Finder for about a minute #38540

Open
3 tasks done
nesvet opened this issue Jun 1, 2023 · 10 comments
Open
3 tasks done

[Bug]: showItemInFolder hangs macOS Finder for about a minute #38540

nesvet opened this issue Jun 1, 2023 · 10 comments
Labels
29-x-y 30-x-y 31-x-y bug 🪲 component/shell has-repro-gist Issue can be reproduced with code at https://gist.github.com/ platform/macOS status/confirmed A maintainer reproduced the bug or agreed with the feature

Comments

@nesvet
Copy link
Contributor

nesvet commented Jun 1, 2023

Preflight Checklist

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

@nesvet nesvet added the bug 🪲 label Jun 1, 2023
@jkleinsc jkleinsc added the blocked/need-repro Needs a test case to reproduce the bug label Jun 5, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Jun 5, 2023

Hello @nesvet. Thanks for reporting this and helping to make Electron better!

Would it be possible for you to make a standalone testcase with only the code necessary to reproduce the issue? For example, Electron Fiddle is a great tool for making small test cases and makes it easy to publish your test case to a gist that Electron maintainers can use.

Stand-alone test cases make fixing issues go more smoothly: it ensure everyone's looking at the same issue, it removes all unnecessary variables from the equation, and it can also provide the basis for automated regression tests.

Now adding the blocked/need-repro label for this reason. After you make a test case, please link to it in a followup comment. This issue will be closed in 10 days if the above is not addressed.

@jkleinsc
Copy link
Contributor

jkleinsc commented Jun 5, 2023

@nesvet As documented here: https://www.electronjs.org/docs/latest/api/shell, shell is only available in a non-sandboxed renderer. If you are seeing this issue in a non-sandboxed renderer please provide a gist testcase.

@github-actions github-actions bot removed the blocked/need-repro Needs a test case to reproduce the bug label Jun 5, 2023
@nesvet
Copy link
Contributor Author

nesvet commented Jun 5, 2023

@jkleinsc jkleinsc added has-repro-gist Issue can be reproduced with code at https://gist.github.com/ 25-x-y labels Jun 6, 2023
@codebytere
Copy link
Member

Looks like this happened here: v25.0.0-nightly.20230330...v25.0.0-nightly.20230331 - likely 3fa0397

@mifi
Copy link
Contributor

mifi commented Nov 1, 2023

Having the same problem

Simple test case:

// index.js
const electron = require('electron');

electron.app.whenReady().then(() => {
  const mainWindow = new electron.BrowserWindow({
    webPreferences: {
      contextIsolation: false,
      nodeIntegration: true,
    },
  });

  mainWindow.loadURL('data:text/html;charset=utf-8,<html></html>');
});
  1. Run npx electron index.js
  2. Open developer tools
  3. Type into devtools window.require('electron').shell.showItemInFolder('/Users')
  4. Observe that Finder has frozen
  5. Close the electron app's window
  6. Observe that Finder now responds and shows the requested item in its folder

mifi/lossless-cut#1762

@rvion
Copy link

rvion commented Nov 18, 2023

This feels like a pretty serious bug. Is there a workaround in the meantime ?

@mifi
Copy link
Contributor

mifi commented Nov 18, 2023

Maybe to disable nodeIntegration

@KevinHughes
Copy link

Here's my workaround, which runs AppleScript behind the scenes:

showItemInFolder(path) {
    let script = `
        set thePath to POSIX file "${path}" as string
        tell application "Finder" to reveal thePath
        tell application "Finder" to activate
    `;
    let process = require('child_process');
    let result = process.execSync("/usr/bin/osascript -", {
        input: script
    });
}

@KishanBagaria
Copy link
Contributor

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.

@KevinHughes
Copy link

KevinHughes commented Nov 18, 2023

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.

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:

const { ipcMain, shell } = require('electron');
ipcMain.on('showItemInFolder', function(event, fullPath) {
    shell.showItemInFolder(fullPath);
});

In renderer:

const { ipcRenderer } = require('electron');
ipcRenderer.send('showItemInFolder', fullPath);

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
29-x-y 30-x-y 31-x-y bug 🪲 component/shell has-repro-gist Issue can be reproduced with code at https://gist.github.com/ platform/macOS status/confirmed A maintainer reproduced the bug or agreed with the feature
Projects
Status: 👍 Does Not Block Stable
Status: 👍 Does Not Block Stable
Status: Unsorted Items
Development

No branches or pull requests

7 participants