Skip to content

[Feature Request]: Enable Application Window Restoration #37494

Description

@ericdrobinson

Preflight Checklist

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 VirtualDesktopManager which 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 NSWindow state 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:

The implementations of these features can be seen in the following change lists:

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:

  1. Use BrowserWindow APIs. The APIs do not provide any way to control Virtual Desktop/Space assignment.
  2. 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:

  1. "I restarted my computer and my previously open applications automatically restore to the setup I had before rebooting."
  2. "I restarted my application to install an update."
  3. "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:

Activity

  1. ShivamPandey00 commented on Mar 5, 2023

    @ShivamPandey00

    Hey @ericdrobinson ,
    I would like to work on this issue.

  2. ShivamPandey00 commented on Mar 5, 2023

    @ShivamPandey00

    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.

  3. ericdrobinson commented on Apr 10, 2023

    @ericdrobinson
    Author

    @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).

  4. ericdrobinson commented on Oct 11, 2023

    @ericdrobinson
    Author

    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 (main is 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.

  5. ericdrobinson commented on Oct 11, 2023

    @ericdrobinson
    Author

    @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 😕

  6. Ige-fi commented on Dec 19, 2023

    @Ige-fi

    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.

  7. T-256 commented on Nov 7, 2025

    @T-256

    I have similar issue and it's annoying each time I restart OS and try to load my last workflow:

  8. drbenvincent commented on Mar 20, 2026

    @drbenvincent

    Bump. This is becoming a real workflow headache and time sync

  9. hdlnii commented on Jul 2, 2026

    @hdlnii

    this is so painful for the everyday workflow

  10. Ige-fi commented on Jul 2, 2026

    @Ige-fi

    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. :)

  11. 0xdevalias commented on Sep 18, 2026

    @0xdevalias

    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:

    This package (electron-osx-spaces) is designed for cases where the app's window lifecycle makes it impossible to participate in NSWindowRestoration — for example, when window creation is driven by application-level logic (restoring a session, parsing command-line arguments, etc.) rather than by AppKit's restoration cycle.

    For apps that can hand window creation over to the NSWindowRestoration flow, electron-osx-restorable-state provides exactly that — it uses the official NSWindowRestoration API and doesn't require any private API workarounds, so it's Mac App Store compatible as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions