WebContext: Shared Browser Data and Profile Isolation
WebContext owns the cookie store, disk cache, and storage shared by one or more webviews, enabling profile isolation or data sharing across browser views.
Use this file to discover all available pages before exploring further.
WebContext owns the browser-data layer — cookies, disk cache, local storage, and IndexedDB — used by the webviews associated with it. By sharing a single context across multiple webviews you give them a common session (useful for keeping a user logged in across panels). By creating separate contexts you achieve hard profile isolation, as if each context were an independent browser profile. The Application owns all contexts it creates, but you can also dispose them early when a profile is no longer needed.
Never call new WebContext() directly — it is not supported and will not behave correctly. Always create contexts through app.createWebContext(options).
Path to a persistent directory where the context should store cookies, cache, and other browser data. On Windows this is especially useful when a bundled application cannot write inside Program Files. Omit for an in-memory (non-persistent) session.
Enable WebDriver / automation support on this context. Currently enforced only on Linux. Only one context may allow automation at a time — enabling it on a second context throws. Use only in controlled test environments.
This setting is currently only enforced on Linux. Only one WebContext per application may have automation enabled at a time. Attempting to enable it on a second context while another has it active will throw.
Release the native context immediately. All webviews that were using this context will lose their shared data store — ensure no webviews are actively using the context before disposing it.
Pass the same context instance to multiple createWebview() calls. All webviews sharing the context will use the same cookie store, cache, and storage — logging in on one webview makes that session available in the other.
Create a separate context for each isolated profile. Webviews in different contexts have entirely separate cookie jars, caches, and storage — useful for multi-account UIs or sandboxed content:
// No dataDirectory — all data is lost when the context is disposed.const ephemeral = app.createWebContext();win.createWebview({ url: 'https://example.com', webContext: ephemeral,});
import { resolve } from 'node:path';const persistent = app.createWebContext({ dataDirectory: resolve('./user-profile'),});win.createWebview({ url: 'https://example.com', webContext: persistent,});// Cookies and cache survive restarts.
// Linux only — one automation context at a time.const testContext = app.createWebContext({ allowsAutomation: true,});win.createWebview({ url: 'http://localhost:3000', webContext: testContext, enableDevtools: true,});
A webview created without a webContext option uses a private default context. Pass an explicit WebContext whenever you need to share state or control the data directory.
Keep the WebContext alive for at least as long as every webview that uses it. Disposing a context while webviews are still referencing it results in undefined behaviour.
app.exit() automatically disposes every context created through that application.
Disposal is idempotent — calling dispose() more than once is safe.