session
The main-process session module in Bunmaska: a default session with a process-wide User-Agent override and (macOS) website-data clearing.
In Electron, session is the kitchen sink for cookies, cache, proxy, permissions, network interception and more. In Bunmaska it is currently a much smaller thing: a single default session that owns a process-wide User-Agent override and can clear the default data store. That is the honest extent of it today - no partitions, no cookie jar, no proxy, no webRequest.
Process: Main
The module exposes one object, session, whose only property is defaultSession. There is no constructor and no factory (fromPartition / fromPath are not implemented), so every window shares the one default session.
import { app, session } from 'bunmaska';
app.whenReady().then(() => {
console.log(session.defaultSession.getUserAgent()); // '' until you set one
});
Properties
session.defaultSession
A Session object - the app’s single default session. Unlike Electron, this is the only session Bunmaska gives you; there is no per-partition or per-path session yet.
import { session } from 'bunmaska';
const ses = session.defaultSession;
ses.setUserAgent('MyApp/1.0');
Class: Session
A Session is not constructed directly - you reach it through session.defaultSession. It carries the User-Agent override and the data-clearing call.
ses.getUserAgent()
getUserAgent(): string
Returns the session’s User-Agent override, or '' when none has been set. An empty string means the underlying platform WebKit default User-Agent is used.
import { session } from 'bunmaska';
const ua = session.defaultSession.getUserAgent();
console.log(ua === '' ? 'using WebKit default' : ua);
ses.setUserAgent(userAgent)
setUserAgent(userAgent: string): void
Sets a process-wide default User-Agent. The important nuance: this is applied by every BrowserWindow created after this call, at construction time, before its first navigation. Windows that already exist keep their current User-Agent - to change a live one, use webContents.setUserAgent(ua).
Note this is narrower than Electron’s setUserAgent(userAgent[, acceptLanguages]): there is no acceptLanguages parameter.
import { app, BrowserWindow, session } from 'bunmaska';
app.whenReady().then(() => {
// Set the default BEFORE creating windows that should use it.
session.defaultSession.setUserAgent('MyApp/1.0 (compatible)');
const win = new BrowserWindow({ width: 800, height: 600 });
win.loadURL('https://example.com'); // request goes out with MyApp/1.0
// Override a live window's UA directly on its web contents:
win.webContents.setUserAgent('MyApp/1.0 (special page)');
});
ses.clearStorageData()
clearStorageData(): Promise<void> macOS
Clears all of the default data store’s website data - cache, cookies, local and session storage, IndexedDB, and the rest - and resolves when the clear completes.
This is the all-or-nothing form. Bunmaska does not yet accept Electron’s options argument (origin / storages), so you cannot scope the clear to a specific origin or storage type; it wipes everything.
Platform: wired on macOS only. On Linux it currently rejects with an UnsupportedPlatformError (WebKitWebsiteDataManager clearing is a follow-up).
import { session } from 'bunmaska';
async function signOut() {
// macOS: clears cache, cookies, localStorage, IndexedDB, etc.
await session.defaultSession.clearStorageData();
}
Not in Bunmaska (yet)
The default session is deliberately minimal right now. Compared to Electron’s session module, the following are not implemented:
session.fromPartition()/session.fromPath()- no partitioned or path-based sessions; there is onlydefaultSession. Thecacheoption andpersist:semantics don’t exist.ses.clearStorageData(options)- theoriginandstoragesscoping options are ignored/absent; only the full wipe exists. And it’s macOS-only - Linux rejects.- Cookies (
ses.cookies) - noCookiesobject for getting/setting/removing individual cookies. - Cache (
ses.getCacheSize(),ses.clearCache()) - no granular cache inspection or HTTP-cache-only clear (useclearStorageData()to nuke everything on macOS). - Proxy (
ses.setProxy(),ses.resolveProxy(),ses.forceReloadProxyConfig()) - no proxy configuration. - Network interception (
ses.webRequest,ses.protocol,ses.fetch()) - no request interception, custom protocols, or main-process fetch. - Permissions (
ses.setPermissionRequestHandler(),ses.setPermissionCheckHandler(),ses.setDisplayMediaRequestHandler()) - no permission plumbing. - Device access (
ses.setDevicePermissionHandler(),ses.setBluetoothPairingHandler(),select-hid-device/select-serial-port/select-usb-deviceevents) - not present. - Downloads (
ses.downloadURL(),ses.setDownloadPath(), thewill-downloadevent) - no download management. - Networking knobs (
ses.enableNetworkEmulation(),ses.setCertificateVerifyProc(),ses.setSSLConfig(),ses.resolveHost(),ses.allowNTLMCredentialsForDomains(),ses.preconnect(),ses.closeAllConnections()) - none implemented. - Extensions (
ses.loadExtension(), theextension-loaded/extension-ready/extension-unloadedevents) - no extension support. - Spellcheck (
ses.setSpellCheckerLanguages()and thespellcheck-dictionary-*events) - not implemented. acceptLanguagesargument tosetUserAgent- only the User-Agent string is honored.- Events - the
Sessionclass emits no events at all yet (nowill-download, no device events, etc.).
If your app only needs a custom User-Agent and a “clear everything” button (on macOS), the current surface covers it. Anything cookie-, proxy-, permission-, or interception-shaped is still on the roadmap.