createSession()
Create a persistent session context for related requests. Within a session,browser, os, and proxy are fixed at creation time (unless you pass an explicit transport per request).
Signature
Options
BrowserProfile
Default browser fingerprint profile for all session requests.
EmulationOS
Default operating system to emulate.
string
Default proxy URL for all session requests.
number
default:"30000"
Default request timeout in milliseconds.
HeadersInit
Default headers to include in every session request. Can be a
Headers object, plain object, or array of key-value pairs.string
Explicit session identifier. When omitted, a random ID is generated.
boolean
default:"false"
Accept invalid certificates for all session requests. Use only in development.
boolean
default:"false"
Enable extra connection and TLS diagnostics for requests made through this session by default.
Session object
The returnedSession object has:
session.fetch(url, init?)
Make a request using the session context.session.fetch() also accepts request-scoped onRequestEvent and captureDiagnostics options from fetch(). When diagnostics are enabled, inspect response.diagnostics on the returned response.
session.websocket(url, options?)
Open a WebSocket that reuses the session transport and context. Use this after login or any other HTTP flow that sets cookies.session.websocket(...) accepts headers, protocols, and binaryType.
It does not accept browser, os, or proxy because those are owned by the session transport.
protocols values are validated for non-empty unique entries and sent in the Sec-WebSocket-Protocol handshake header.
session.getCookies(url)
Return cookies that would be sent to the given URL (RFC 6265 domain/path matching).string | URL
required
Target URL. Only cookies whose domain and path match this URL are returned.
Record<string, string> — cookie name/value pairs.
session.getAllCookies()
Return every cookie currently stored in the session jar, regardless of URL matching.SessionCookie[] — all cookies in the jar, with scope metadata such as domain, path, sameSite, and expiresAtMs when available.
session.setCookie(name, value, url)
Add a cookie to the session jar, scoped to the domain/path of the given URL.string
required
Cookie name.
string
required
Cookie value.
string | URL
required
URL that determines the cookie’s domain and path scope.
session.setCookies(cookies, url?)
Restore a batch of cookies into the session jar, keeping every attribute. Accepts the output ofgetAllCookies() directly, so a jar can round-trip through JSON.
SessionCookieInit[]
required
Cookies to store. Only
name and value are required; domain, path, secure, httpOnly,
sameSite, and expiresAtMs are applied when present.string | URL
Origin used to scope host-only cookies — those without a
domain. Required whenever the batch
contains one, unless the cookie carries its own url.A cookie with a
domain describes its own scope. A cookie without one is host-only, and the jar
keeps that host as an internal key it never returns, so it is missing from the export. url
supplies it — which means a jar holding host-only cookies from several hosts cannot be
restored from a single url: they would all land on that one host. Set url on the individual
cookie to place each one precisely.expiresAtMs is already in the past are
dropped rather than stored, matching how the jar treats an expired Set-Cookie.