Repository navigation
Description
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 feature request that matches the one I want to file, without success.
Problem Description
Electron based applications fail to restore their windows to their user-assigned Virtual Desktop [Windows 10/11] or Space [macOS].
Unfortunately, this isn't something that Electron users can address in their application implementations. This is due to the fact that OS APIs do not [universally] exist to enable such direct management:
- Microsoft provides the
VirtualDesktopManagerwhich supports a very limited set of APIs (so limited, in fact, that there does not appear to be a way to enumerate the user's current set of available Desktops). - Apple explains their own process in their Mac App Programming Guide which amounts to "conform to some protocols and
NSWindowstate will be saved on application shutdown/restored on application startup".
(I haven't looked into Linux window manager APIs...)
Regardless, Microsoft and Apple provide enough APIs for applications to save and restore their "Virtual Desktop"/"Space" assignment on application restart. While Microsoft's APIs appear to be usable at any point in the application's life cycle, Apple's APIs are very much tied to the implementation of the NSWindow.
Electron's upstream Chromium does properly support session restoration with Virtual Desktop / Space assignments for its windows. The bugs that tracked these features are as follows:
- Windows: https://bugs.chromium.org/p/chromium/issues/detail?id=873414
- macOS: https://bugs.chromium.org/p/chromium/issues/detail?id=74812
The implementations of these features can be seen in the following change lists:
- Windows: https://chromium-review.googlesource.com/c/chromium/src/+/1570246
- macOS: https://chromium-review.googlesource.com/c/chromium/src/+/1808708
These are clearly implemented in drastically different ways. The macOS implementation is most directly (and clearly) tied to Chromium's concept of "session restoration".
Current versions of Electron do not provide any ability to tap into Chromium's window restoration capabilities (or provide their own mechanism). Applications currently have to rely on APIs provided by the BrowserWindow class and that class does not (and cannot) provide the APIs necessary to support this feature.
Proposed Solution
I would like Electron to provide an option wherein an Electron application developer can specify that they would like the windows of an application to be restored on next start. This option should handle window Virtual Desktop/Space reassignment. I expect that APIs may be necessary to enable applications to "rehydrate" the restored windows with serialized application state.
Unfortunately, my personal experience with Electron application session restoration is insufficient to propose anything more than the high level ask above. Perhaps @bpasero might chime in - he seems like someone who may be sufficiently steeped in the complexities of window/state restoration to be able to suggest a solution or improved list of requirements for a solution.
Alternatives Considered
The alternatives considered are as follows:
- Use
BrowserWindowAPIs. The APIs do not provide any way to control Virtual Desktop/Space assignment. - Wait for a separate set of "Workspace APIs". These APIs are not yet implemented. Moreover, the proposed set of APIs aren't currently feasible given the available set of APIs provided by the host OSes themselves (importantly, none of them are available on macOS).
These approaches are both at the level of "we can pass this off to Electron application developers". Unfortunately, due to the nature of how Virtual Desktop/Space systems work this needs to be something that is handled internally.
Additional Information
I should also explain that there are several scenarios that end users expect this feature:
- "I restarted my computer and my previously open applications automatically restore to the setup I had before rebooting."
- "I restarted my application to install an update."
- "I exited my application, went to lunch, came back, and re-opened my application."
Notably, Apple only explains that they support restoration when the computer restarts and applications are reopened. The other two scenarios aren't officially handled. That said, the Chromium developers were able to identify an approach that enables Chromium itself to restart (e.g. during an update) and restore windows to their previously assigned Spaces. This feature mostly works when quitting/starting Chrome normally (case 3 above), though this may require setting a custom preference.
It appears that the Windows APIs also operate on a "best effort" basis wherein if the ID of the Virtual Desktop targeted for restoration doesn't exist anymore, the window is moved instead to the active Virtual Desktop.
Related issues:
- Electron
- Provide a mechanism for macOS apps to restore themselves to their original Spaces #10124 - This was closed as being considered out of scope for the roadmap at the time. At the time the upstream Chromium project had also not yet implemented the feature.
- Remember Desktop No. on app restart in macOS #15211 - This was closed with the suggestion that app developers should handle it. That is unfortunately not possible.
- Add workspace API #5362 - This issue targets providing an API within Electron itself to manage Virtual Desktop/Space assignments. Of the four bullet points in this issue, only three are potentially doable in Windows and none are doable on macOS.
- VS Code
- VS Code should restore windows to their original spaces when possible microsoft/vscode#979 - This was closed because the upstream issue (#10124) was closed.
- VSCode does not preserve original virtual desktop placement when restoring windows (Windows, macOS) microsoft/vscode#88257 - Automatically closed due to lacking enough votes.
- Windows: support to restore windows to virtual desktops microsoft/vscode#116358 - Automatically closed due to lacking enough votes.
- Relaunching VSCode forgets what macOS Desktop each window belongs to microsoft/vscode#123517
- Support virtual desktops on windows microsoft/vscode#138936 - Automatically closed due to lacking enough votes.
- VSCode windows not staying in their respective virtual desktops on app restart microsoft/vscode#146915
- Support virtual desktops on windows microsoft/vscode#152869
Activity
ShivamPandey00 commentedon Mar 5, 2023
Hey @ericdrobinson ,
I would like to work on this issue.
ShivamPandey00 commentedon Mar 5, 2023
My proposed solution is to add a new option in Electron's API which allows the developers to specify that they want the windows of their application to be restored on next start. This option should handle window Virtual Desktop/Space reassignment.
To implement this, we will need to add new APIs to allow applications to "rehydrate" the restored windows with serialized application state. We will also need to modify the codebase to tap into Chromium's window restoration capabilities, which are already implemented in Chromium for both Windows and macOS.
By leveraging Chromium's existing implementation, we can ensure that our solution is robust and reliable. Additionally, by adding this new feature to Electron's API, we can make it easy for developers to implement session restoration with Virtual Desktop / Space assignments in their applications.
ericdrobinson commentedon Apr 10, 2023
@CoderDeadpool Are you planning on doing the legwork to develop out a solution to this issue? Or was your goal rather to outline a proposal and leave it at that?
I fear that it may be a bit ambiguous and I want to make sure that the status is clear for anyone encountering this issue (especially maintainers).
ericdrobinson commentedon Oct 11, 2023
I'd love to be proven wrong, but I think @ShivamPandey00 has abandoned any effort to implement this. While that account does have an Electron Repo fork, there doesn't appear to be any work done to it (
mainis untouched and no branches pushed to GitHub). The "proposed solution" was suspicious from the start as it was mostly a restatement of the writeup I provided in the summary.ericdrobinson commentedon Oct 11, 2023
@codebytere Any chance that this feature request could get some attention? No Electron-based application can properly hook into Virtual Desktop/Spaces settings/assignments unless it's supported within Electron itself 😕
Ige-fi commentedon Dec 19, 2023
I didn’t see it mentioned, so: on Linux distributions, at least GNOME has a virtual desktop feature available (called “workspaces”). I would like to see the restoration also supported there.
T-256 commentedon Nov 7, 2025
I have similar issue and it's annoying each time I restart OS and try to load my last workflow:
drbenvincent commentedon Mar 20, 2026
Bump. This is becoming a real workflow headache and time sync
hdlnii commentedon Jul 2, 2026
this is so painful for the everyday workflow
Ige-fi commentedon Jul 2, 2026
Since it hasn't been mentioned yet, session management support for Wayland has also been widely implemented quite recently:
Which is to say: I hope to see Electron also implement this on Linux. :)
0xdevalias commentedon Sep 18, 2026
I stumbled across these 2 libraries that seem to allow implementing session restoration for electron apps on macOS, with slightly different nuances/constraints; though I haven't deeply looked into them/tried them myself:
A description of the nuances between them from the maintainer (@tnayuki) was:
feat(macos): proof of concept for native spaces restoration via NSWin…
feat(macos): proof of concept for native spaces restoration via NSWin…