Skip to main content
Back to blog

NOVEMBER 28, 2026

Electron Session Partitions: One App, Many Logins

An Electron app can hold many logins to the same site at once, each with its own cookies, storage and cache. The mechanism is the session partition. Here is how partitions work, the choices you have to make, and the mistakes that let one account leak into another.

By Umar Abdullah · Chromium & Browser Development

Light cover reading "One app, many logins" beside three browser panes, each an Electron session partition with its own cookies, storage and cache
November 28, 20268 min read

Short answer

In Electron, every page runs inside a session, and a session owns that page's cookies, cache, storage, proxy settings and permission handlers. A partition is the name that selects the session. Give each profile its own partition and you can show three logins to the same site in one window, with no cookies, storage or cache shared between them. Most leaks come from two mistakes: a view left on the default session, and security handlers registered on only one session.

What does a session own?

Electron's session documentation describes the module in one line: "Manage browser sessions, cookies, cache, proxy settings, etc." In practice a session is the unit of isolation for everything a website stores or negotiates:

  • cookies, local storage, IndexedDB, service workers and the HTTP cache
  • the proxy configuration
  • the user agent string
  • permission handlers, which decide whether a page may use notifications, the camera and similar features
  • the web request hooks, custom protocols and registered preload scripts

Each of these is set or cleared through the session object, not the window. That is the fact to hold on to. Two views in the same session share all of it. Two views in different sessions get separate copies.

How do partitions work?

You get a session by naming it. The rules are short, and they are all in the documentation for session.fromPartition.

  • Same name, same session. "When there is an existing Session with the same partition, it will be returned; otherwise a new Session instance will be created with options."
  • The persist: prefix decides whether data survives. A partition that starts with persist: uses "a persistent session available to all pages in the app with the same partition." Without the prefix, the page uses an in-memory session.
  • Empty means default. "If the partition is empty then default session of the app will be returned."
  • Options are fixed at creation. "There is no way to change the options of an existing Session object."

There is also session.fromPath, which creates a session from an absolute folder path instead of a name.

To attach a session to a page, set it in the page's web preferences, either as a partition string or as a session object. If you pass both, the documentation says session is preferred. If you pass neither, you get the default session.

The following sketch is ours, written against those documented APIs. It puts two profiles side by side in one window.

const { app, BaseWindow, WebContentsView, session } = require('electron')

function createProfileView(profileId) {
  const partition = `persist:profile-${profileId}`
  const ses = session.fromPartition(partition)

  // Handlers belong to the session, so set them for every profile.
  ses.setPermissionRequestHandler((webContents, permission, callback) => {
    callback(false)
  })

  return new WebContentsView({ webPreferences: { partition } })
}

app.whenReady().then(() => {
  const win = new BaseWindow({ width: 1600, height: 900 })
  const left = createProfileView('a')
  const right = createProfileView('b')
  win.contentView.addChildView(left)
  win.contentView.addChildView(right)
  left.setBounds({ x: 0, y: 0, width: 800, height: 900 })
  right.setBounds({ x: 800, y: 0, width: 800, height: 900 })
})

Each view can now be logged in to the same site as a different user.

Diagram of an Electron app with a default session for its own interface and two profile sessions and a guest session selected by partition name, each holding its own cookies, storage, cache and permission handlers
Diagram of an Electron app with a default session for its own interface and two profile sessions and a guest session selected by partition name, each holding its own cookies, storage, cache and permission handlers

Which kind of session should each part of the app use?

Kind How you get it Data survives restart Use it for
Default session No partition set Yes Your own app interface only
In-memory partition A name without the persist prefix No Guest or one-off sessions, previews, tests
Persistent partition A name starting with persist: Yes A user profile or account that should stay signed in
Session from a path fromPath with an absolute folder Not stated in the page we read; test it When you need to choose where profile data lives

The first three rows follow the documentation directly. The "use it for" column is our recommendation.

Ship faster with senior engineers

Direct collaboration, AI-augmented delivery, and no agency markup.

Get in touch

What this looked like on a real browser

We built this kind of isolation for Matchups, a sports platform whose users work across multiple screens and multiple accounts at once. The requirement was several browser sessions running at the same time, each with its own cookies, storage, login state and active tabs, and no bleeding between screens. Each workflow got its own sandboxed profile with separate credentials, browsing state and cache.

That requirement is why the product is built on Electron. Electron let us implement session isolation at the application layer, with control over how profiles are created, stored and managed. The trade-off, as we said in the case study, is a larger application footprint. The case study does not go into which APIs were used, and this post is not a description of that codebase; the requirement is what matters here.

Two pieces of general design advice for a product like this. A profile is a product concept, not only a storage detail: users create and switch profiles, so the mapping from profile to session has to be something your app owns and stores. And a profile can span more than one view or screen, so the same session must be reachable from each of them.

Five mistakes that leak one account into another

These come from reading the documentation closely and from building a product of this shape. The framing is ours.

1. Something is still on the default session. Any window or view your code creates without a partition lands in the default session. A login window, a new-tab page or an OAuth window built in a different part of the main process will quietly share cookies with everything else there. Our rule: only your own interface may use it. For popups that a page opens itself, the documentation we read does not say which session they get, so test that case.

2. Handlers are set on one session only. Electron's security guide tells you to use a permission request handler "in all sessions that load remote content", and it explains why: "By default, Electron will automatically approve all permission requests unless the developer has manually configured a custom handler." Handlers are set per session, so as we read the API, one set on the default session does not cover persist:profile-b. The same goes for web request hooks and anything else configured on the session. Create every profile session through one function that applies the full set.

3. Partition names are built from loose strings. Because a new name silently creates a new session, a typo or an unnormalised value gives you a fresh empty profile, and the user appears to be logged out. Because the same name returns the same session, two profiles that collide on a name share a login. Generate names from a stable internal ID, never from user-typed text.

4. The persist: prefix is missing. The session works perfectly until the app restarts, and then every login is gone. If you want to check at runtime, a session can report whether it is persistent.

5. Deleting a profile leaves its data behind. Removing a profile from your own database does not remove its cookies. Clear the session's storage and cache. For a persistent session we also remove the folder it exposes as its storage path, once its views are closed; the documentation does not describe that step, so test it on each platform. Until the data is gone, a profile that reuses that name gets the same session back, old login included.

What partitions do not give you

A partition separates what a site stores. It does not change what a site can observe about the machine: the same screen, the same fonts and graphics hardware, the same network address. Two accounts in two partitions keep separate cookies and still come from what looks like one device. If your product needs accounts that cannot be linked that way, you are solving a different problem, which we describe in what isolated fingerprinting requires at the browser level.

Partitions also do not replace the rest of Electron's security model. Context isolation, the sandbox and a narrow preload bridge still apply to every view, in every session. We covered those in where the real Electron vulnerabilities are.

A checklist for multi-account Electron apps

  • Decide what a profile is in your product, and store the profile-to-partition mapping yourself.
  • Derive partition names from a stable ID, with the persist: prefix where logins should survive.
  • Create sessions in one place, and apply permission handlers, request hooks, proxy and user agent there.
  • Keep the default session for your own interface. Search the code for any window or view created without a partition.
  • Check which session popups and login windows end up in, and pass the opener's session explicitly to any window you create yourself.
  • Test isolation directly: sign in to the same site in two profiles, restart, and check both are still the right user.
  • Test deletion: remove a profile, create a new one, and confirm it starts signed out.
  • Write down what partitions do not isolate, so nobody promises unlinkable accounts by accident.
  • If you are weighing Electron against other shells for a product like this, our comparison of Electron, Tauri, Qt and native covers the wider trade-offs. Electron apps like this are part of our desktop app development work.

    Sources: Electron documentation in the electron/electron repository as of 28 November 2026: session, WebPreferences, WebContentsView and the security guide. Details about Matchups are from our published case study.

    COMMON QUESTIONS

    Straight answers.

    Eight questions we get on every first call. If yours isn't here, it'll be the first thing we cover.

    It is a name that selects a session. A session holds a page's cookies, cache, storage, proxy settings and permission handlers. Pages created with the same partition string share one session, and pages with different strings are kept apart. An empty partition means the app's default session.
    It makes the session persistent. Electron's documentation says a partition that starts with persist: uses a persistent session, and one without the prefix uses an in-memory session, which it also calls temporary. In practice, logins in an in-memory session do not outlive the app.
    Yes. Give both the same partition string, or pass both the same session object. Electron's documentation says that by assigning the same partition, multiple pages can share the same session. That is how one profile can span several windows or screens.
    Clear that profile's session only. A session has its own methods to clear storage data and cache. To remove a profile completely, we also delete the folder the session reports as its storage path, after its views are closed. The documentation does not describe that last step, so test it.
    No. A partition separates stored data such as cookies and local storage. It does not change what the device looks like to a site: the same screen, fonts, graphics hardware and network address. Stopping that kind of linking is a different and harder problem that we cover in a separate post.
    That is our recommendation: keep the default session for your own interface and give every profile that loads remote sites its own partition. Then nothing a website stores can end up beside your app's own data, and a view created without a partition is easy to spot.
    No. A partition is a web preference, so it applies to windows and to WebContentsView, which displays web content as a view inside a window. Several views with different partitions can sit side by side in one window.

    Ready to Build Something Amazing?

    Let's discuss your project and see how we can help you achieve your goals with quality software at fair pricing.