Docs/API reference

Session · Node.js

Own shared request defaults, connection pools, per-host pacing and retry settings.

Download .md
Developers8 min read28 sections
Source reference · Match your SDK version. Availability and known issues
In this guide

Purpose and lifecycle

Create one session per site or authentication identity and pass it to related operations. Configuration setters return the same session. Settings are held in the Rust engine.

Set authentication and response-cache middleware before the first fetch. A clone copies request configuration but starts independent pools, metrics and middleware. It does not inherit installed auth/cache layers.

Cookies are explicitly configured request defaults, not a browser cookie jar. They have no domain, path or expiry attributes and Set-Cookie responses are not automatically persisted.

Python retry and cookie-management methods are in development source and are not included in the existing alpha.2 package; they require a later release or a matching source build.

Definition and availability

Source snapshot: 1.0.0-alpha.3. Package export. Declared in source; this is not a runtime test result.

Signatures and source locations are generated from the SDK wrappers. Clean snapshots link to the recorded commit. Modified snapshots link to main, which may differ; file hashes identify the local inputs.

export class Session
typescript1 lines · copy-ready

Usage example

Use a matching source build. Where a snippet uses page, obtain it with the Page example first. Example URLs illustrate API shape; they are not promised datasets.

import { Session, Page } from 'crawlingo';

const session = new Session().rateLimit(2).timeout(30)
  .retries(3).retryDelay(1).retryBackoff(2)
  .cookies({ locale: 'en' });
const page = await Page.create('https://example.com/', { session });
console.log(page.status, session.getCookies());
session.deleteCookie('locale').clearCookies();
typescript8 lines · copy-ready

Members

MemberKindReturn / value typeSource status
innerpropertyJsSessionPresent in source
constructormethodSessionPresent in source
fromConfigstatic methodSessionPresent in source
headersmethodthisPresent in source
cookiesmethodthisPresent in source
getCookiesmethodRecord<string, string>Present in source
deleteCookiemethodthisPresent in source
clearCookiesmethodthisPresent in source
retriesmethodthisPresent in source
retryBackoffmethodthisPresent in source
retryDelaymethodthisPresent in source
proxymethodthisPresent in source
rateLimitmethodthisPresent in source
autoMatchmethodthisPresent in source
timeoutmethodthisPresent in source
fingerprintPathmethodthisPresent in source
fetcherTiermethodthisPresent in source
browserProfilemethodthisPresent in source
autoMatchWeightsmethodthisPresent in source
proxyPoolmethodthisPresent in source
proxyProvidermethodthisPresent in source
clonemethodSessionPresent in source
destroymethodvoidPresent in source

inner

Native interop handle. Prefer the documented wrapper methods; bypassing them can bypass validation and typed error conversion.

Returns / value: JsSession.

public readonly inner: JsSession;
typescript1 lines · copy-ready

constructor()

Create an empty session with a 30-second request timeout, standard HTTP transport and no pacing limit. No request is sent by construction.

Returns / value: Session.

constructor(inner?: JsSession): Session
typescript1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
innerJsSession | undefinedOptionalExisting native handle for wrapper interop; not a URL or plain data object.

fromConfig()

Load TOML or JSON, apply CRAWLINGO_* environment overrides and validate configuration. Omit the path to load defaults plus environment only. Explicit setters applied afterward override loaded settings.

Returns / value: Session.

fromConfig(path?: string): Session
typescript1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
pathstring | undefinedOptionalFilesystem path relative to the process working directory unless absolute.

headers()

Replace the entire default header map. Node Page.create merges its request headers over this map. Authentication headers apply to every request using this session.

Returns / value: this.

headers(headers: Record<string, string>): this
typescript1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
headersRecord<string, string>RequiredHeader names and values; avoid sharing credentials across unrelated sites.

cookies()

Replace the entire explicit cookie map. Use a different session for another authentication identity.

Returns / value: this.

cookies(cookies: Record<string, string>): this
typescript1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
cookiesRecord<string, string>RequiredExplicit cookie-name/value defaults.

getCookies()

Return a snapshot of configured cookies. Mutating the returned object does not mutate the session.

Returns / value: Record<string, string>.

getCookies(): Record<string, string>
typescript1 lines · copy-ready

clearCookies()

Remove all explicit cookie defaults. This does not clear an independently supplied Cookie header.

Returns / value: this.

clearCookies(): this
typescript1 lines · copy-ready

retries()

Set additional attempts after the initial request. 0 means one attempt. Integers 0–4294967295 are accepted. Default Page/Dataset/Crawl/Job retry count is 3; downloader/sitemap defaults can differ until explicitly set.

Returns / value: this.

retries(count: number): this
typescript1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
countnumberRequiredCount of additional retries after the initial attempt.

retryBackoff()

Set a finite exponential multiplier >= 1. Delay for retry n starts at base × factor^n, capped by policy. Default factor is 2. In development source, Retry-After in seconds or HTTP-date form takes precedence when enabled; older releases support seconds only. Changes affect subsequent dispatches without rebuilding pools.

Returns / value: this.

retryBackoff(factor: number): this
typescript1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
factornumberRequiredFinite multiplier, at least 1.

retryDelay()

Set initial backoff in whole seconds, from 0 to 86400. The default policy uses 500 ms; use shared configuration for fractional-second timing. Computed delay is capped at max(configured maximum, initial delay).

Returns / value: this.

retryDelay(seconds: number): this
typescript1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
secondsnumberRequiredTime in seconds; see the method-specific range and timing semantics.

proxy()

Set a static proxy URL. A static proxy takes priority over the rotation pool. HTTP(S) and supported SOCKS proxy behavior depends on the compiled HTTP client.

Returns / value: this.

proxy(proxyUrl: string): this
typescript1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
proxyUrlstringRequiredProxy endpoint URL accepted by the compiled HTTP transport.

rateLimit()

Set the shared per-host request rate in requests per second. 0 disables configured pacing. This is not a global limit across separate sessions or machines.

Returns / value: this.

rateLimit(requestsPerSecond: number): this
typescript1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
requestsPerSecondnumberRequiredPer-host rate for the shared session.

autoMatch()

Enable heuristic CSS fingerprint recovery for the Dataset builder. It does not enable selector recovery in DatasetJob or execute JavaScript.

Returns / value: this.

autoMatch(enabled: boolean): this
typescript1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
enabledbooleanRequiredEnable or disable this behavior.

timeout()

Set the per-attempt timeout in seconds. Total time can exceed it because of retries, backoff and rate-limit waits.

Returns / value: this.

timeout(seconds: number): this
typescript1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
secondsnumberRequiredTime in seconds; see the method-specific range and timing semantics.

fingerprintPath()

Select the local directory used for lazily opened fingerprint storage. Keep one coherent identity/history for a selector; a new path has no recovery history.

Returns / value: this.

fingerprintPath(path: string): this
typescript1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
pathstringRequiredFilesystem path relative to the process working directory unless absolute.

fetcherTier()

Node exposes standard and stealthy HTTP tiers. Python can request browser only when its native build includes the browser feature and local Chromium is available. Stealth emulation does not guarantee access.

Returns / value: this.

fetcherTier(tier: "standard" | "stealthy"): this
typescript1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
tier"standard" | "stealthy"RequiredTransport mode supported by this binding and native build.

browserProfile()

Choose a supported HTTP impersonation profile: chrome, firefox or safari. A profile changes transport emulation; it does not launch a browser.

Returns / value: this.

browserProfile(profile: "chrome" | "firefox" | "safari"): this
typescript1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
profile"chrome" | "firefox" | "safari"RequiredHTTP impersonation profile; this does not launch a browser.

autoMatchWeights()

Set scoring weights used by the heuristic matcher. Similarity scores are not calibrated probabilities; validate recovered field values.

Returns / value: this.

autoMatchWeights(weights: Record<string, number>): this
typescript1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
weightsRecord<string, number>RequiredNamed heuristic matching weights. Review extracted values after changing scores.

proxyPool()

Replace the pool of proxy URLs used in round-robin order when no static proxy is set. This is configuration, not a proxy health-check service.

Returns / value: this.

proxyPool(proxies: string[]): this
typescript1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
proxiesstring[]RequiredProxy URL list used when no static proxy is configured.

proxyProvider()

Fetch proxy entries from the configured provider endpoint. The Node binding currently discards a provider-fetch error; do not treat this setter returning as proof that proxies were loaded.

Returns / value: this.

proxyProvider(url: string | null): this
typescript1 lines · copy-ready
ParameterTypeRequired / defaultMeaning
urlstring | nullRequiredHTTP(S) source URL; verify the target is appropriate for your application.

clone()

Return an independent session with copied defaults and retry settings. Cookie changes on the clone do not affect the original. Middleware is not cloned.

Returns / value: Session.

clone(): Session
typescript1 lines · copy-ready

destroy()

Clear selected native state and drop cached managers when no operation retains them. This is cleanup, not cancellation of running jobs. Await owned work before cleanup.

Returns / value: void.

destroy(): void
typescript1 lines · copy-ready

Errors and operational limits

Node retry setters reject invalid numbers with RangeError. Native configuration failures use CrawlingoError; Python session methods can propagate native RuntimeError or ValueError directly. Do not assume identical exception translation across bindings.

Source availability, package publication and runtime validation are separate facts. These pages describe the source snapshot, not a claim that all platforms or every API path have passed production acceptance.