Comfy-Org / Comfy-Org/ComfyUI-Manager
[Desktop] Provide a supported native directory-picker API for custom nodes/extensions
- Dominant language
- Python
- Stars
- 16.1k
- Forks
- 2.5k
- Avg merge
- 5d 4h
- Merged PRs (30d)
- 13
Description
### Description
I am developing a ComfyUI custom node which needs to allow the user to select a filesystem directory for saving generated assets.
The node is called Production Slate V4 and is intended for production workflow management. It creates a project/scene directory structure and saves rendered images directly to the selected filesystem location.
I have been testing this under ComfyUI Desktop on Windows 11.
The problem is that browser-based directory selection and the current window.__comfyDesktop2 bridge do not appear to provide a suitable documented API for a custom node to obtain a normal filesystem path from a native folder picker.
I believe ComfyUI Desktop should provide a supported, narrowly scoped native directory-picker API for custom node JavaScript extensions.
I am not suggesting that arbitrary Electron filesystem APIs should be exposed to custom nodes. A restricted API which opens the native directory-selection dialog and returns the user-selected path would provide the required functionality while maintaining a sensible security boundary.
### Environment
Operating system: Windows 11
ComfyUI: 0.33.1
ComfyUI Desktop: Desktop installation
Python: 3.12.9
PyTorch: 2.10.0+cu130
GPU: NVIDIA GeForce RTX 4060 Ti 16GB
Frontend: ComfyUI Desktop frontend
The ComfyUI startup configuration includes:
```
--feature-flag show_signin_button=true
--base-directory C:\Users\colin\Documents\ComfyUI
--user-directory C:\Users\colin\Documents\ComfyUI\user
--database-url sqlite:///C:\Users\colin\Documents\ComfyUI\user\comfyui.db
--port 8000
--enable-manager
--extra-model-paths-config C:\Users\colin\AppData\Roaming\Comfy Desktop\shared_model_paths.yaml
--input-directory C:\Users\colin\Documents\ComfyUI\input
--output-directory C:\Users\colin\Documents\ComfyUI\output
```
### Expected behaviour
A custom-node JavaScript extension should have a supported way to do something equivalent to:
`const selectedPath = await nativeDirectoryPicker();`
where:
1. The user clicks a Browse button supplied by the custom node.
2. ComfyUI Desktop opens the normal native operating-system folder picker.
3. The user selects a directory.
4. The native picker returns the selected filesystem path.
5. The custom node can place that path into its node widget.
For example:
```
Browse
↓
Windows native folder picker
↓
F:\AI_Films
↓
output_root = F:\AI_Films
```
The Python backend can then use the path normally.
### Actual behaviour
The current window.__comfyDesktop2 object is available to custom-node JavaScript, but it does not expose a directory-picker function.
I tested the object and obtained the following available functions/objects:
```
isRemote
openModelAccessPage
downloadModel
downloadAsset
pauseDownload
resumeDownload
cancelDownload
onDownloadProgress
reportTheme
openTerminal
Terminal
Logs
Telemetry
```
There is no:
`showDirectoryPicker`
or equivalent filesystem directory-selection function.
Our diagnostic therefore reports:
```
__comfyDesktop2 FOUND
showDirectoryPicker() is NOT available.
Investigation
```
### Investigation
I initially attempted to use the browser API:
`window.showDirectoryPicker()`
However, this does not provide the same useful result for this application as a native Desktop API returning a normal filesystem path.
I then investigated whether ComfyUI Desktop exposes a native Electron bridge.
window.__comfyDesktop2 is present, confirming that the Desktop host bridge is available.
However, showDirectoryPicker() is not part of the exposed bridge.
Interestingly, the current Comfy Desktop source appears to contain a native directory-picker implementation internally.
The current Desktop source contains:
```
showDirectoryPicker: (): Promise => {
return ipcRenderer.invoke(IPC_CHANNELS.SHOW_DIRECTORY_PICKER);
},
```
and the Desktop constants contain:
`SHOW_DIRECTORY_PICKER: 'show-directory-picker'`
This suggests that the native capability exists within the Desktop application but is not currently exposed through the window.__comfyDesktop2 interface available to custom-node extensions.
### Why this matters for custom nodes
There are many legitimate uses for a native directory picker in custom nodes, including:
- output directory selection
- project directory selection
- batch processing directories
- asset libraries
- dataset locations
- video/image production workflows
- external model or resource locations
- project management tools
For example, my Production Slate node currently needs to create:
```
F:\AI_Films
└── Working Title
└── SC001
├── TKR_SC001_SH001A_260814_001.png
├── TKR_SC001_SH001A_260814_002.png
└── ...
```
The user should be able to select F:\AI_Films using a normal native folder-selection dialog rather than having to manually type the path.
### Security consideration
I understand that exposing Electron APIs directly to arbitrary custom-node JavaScript would have significant security implications.
I am not proposing that arbitrary filesystem APIs be exposed.
In fact, I think the restricted bridge approach is preferable.
A dedicated API such as:
`window.__comfyDesktop2.showDirectoryPicker()`
which:
- opens a native folder-selection dialog,
- requires explicit user interaction,
- returns only the path selected by the user,
- provides no arbitrary filesystem read/write capability,
would seem to provide a reasonable security boundary.
This would also avoid custom nodes attempting to access undocumented or private Electron functionality.
### Reproduction
A minimal reproduction is:
1. Create a custom-node JavaScript extension
Add a button to a custom node.
2. Attempt to access the Desktop bridge
```
const desktop = window.__comfyDesktop2;
console.log(desktop);
```
This succeeds.
3. Attempt to access the directory picker
`console.log(typeof desktop.showDirectoryPicker);
`
Result:
`undefined`
4. Diagnostic result
```
__comfyDesktop2 FOUND
showDirectoryPicker() is NOT available.
```
### Additional testing
I also tested the possibility of using:
`window.electronAPI`
but the expected Electron API was not exposed in the current Desktop environment.
The current window.__comfyDesktop2 bridge was therefore investigated instead.
During this investigation I was able to establish that the Desktop application's internal native directory-picker functionality exists, but it is not exposed through the bridge available to the custom-node frontend.
### Question / requested feature
Could ComfyUI Desktop expose a documented, supported native directory-picker API through the current Desktop bridge?
Something along the lines of:
`const path = await window.__comfyDesktop2.showDirectoryPicker();
`
would solve this cleanly.
If there is already a supported API for this purpose, could it be documented for custom-node/extension developers?
If the capability is deliberately not exposed for security reasons, could you advise what the recommended mechanism is for a custom node that legitimately needs the user to select an external filesystem directory?
### Relevant architectural context
I found the current ComfyUI frontend Desktop-parity discussion, which states that ComfyUI Desktop hosts the normal localhost frontend and exposes host functionality through server feature flags and window.__comfyDesktop2, and that native functionality should check the actual bridge/API capability.
This seems particularly relevant to this request because the native directory-picker capability appears to exist internally in Desktop, while the equivalent capability is not currently available to custom-node JavaScript.
Additional information
This is being encountered while developing a production-oriented custom node, rather than attempting to circumvent the ComfyUI filesystem security model.
The node already works correctly when supplied with a filesystem path manually. The only missing piece is a convenient and supported way for the user to select that path using the native Desktop UI.
I would be happy to provide the minimal custom-node test code used to reproduce this if required.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by tracing the existing internal showDirectoryPicker implementation and IPC_CHANNELS.SHOW_DIRECTORY_PICKER, then compare them with the window.__comfyDesktop2 bridge exposed to custom-node JavaScript. Done means a documented, supported directory-picker entry point is available with the requested security boundary, and the reproduction confirms it returns the user-selected path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- electron, javascript
- Domain
- api, desktop, security
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100