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.