Session
Implements
Index
Constructors
constructor
Session configuration.
Parameters
options: SessionOptions = {}
Returns Session
Properties
readonlyid
readonlyuserData
Accessors
cookieJar
Returns CookieJar
createdAt
Returns Date
errorScore
Returns number
errorScoreDecrement
Returns number
expiresAt
Returns Date
fingerprint
Returns undefined | SessionFingerprint
Parameters
fingerprint: undefined | SessionFingerprint
Returns void
maxErrorScore
Returns number
maxUsageCount
Returns number
proxyInfo
Returns undefined | ProxyInfo
retired
trueonceretire()has been called. Retirement is terminal: a retired session is never picked by the pool and cannot be revived viamarkGood().Returns boolean
usageCount
Returns number
Methods
getCookieString
Returns cookies saved with the session in the typical key1=value1; key2=value2 format, ready to be used in a cookie header or elsewhere.
Parameters
url: string
Returns Promise<string>
Represents
Cookieheader.
getState
Gets session state for persistence in KeyValueStore.
Returns SessionState
Represents session internal state.
isBlocked
Indicates whether the session is blocked. Session is blocked once it reaches the
maxErrorScore.Returns boolean
isExpired
Indicates whether the session is expired. Session expiration is determined by the
maxAgeSecs. Once the session is older thancreatedAt + maxAgeSecsthe session is considered expired.Returns boolean
isMaxUsageCountReached
Indicates whether the session is used maximum number of times. Session maximum usage count can be changed by
maxUsageCountparameter.Returns boolean
isUsable
Indicates whether the session can be used for next requests. Session is usable when it is not retired, not expired, not blocked and the maximum usage count has not be reached.
Returns boolean
markBad
Increases usage and error count. Should be used when the session has been used unsuccessfully. For example because of timeouts.
Returns void
markGood
This method should be called after a successful session usage. It increases
usageCountand potentially lowers theerrorScoreby theerrorScoreDecrement.Returns void
retire
Permanently retires the session —
isUsable()will returnfalsefrom here on, and nomarkGood()/markBad()can revive it. Callingretire()again is a no-op.Use this when you're confident the session itself is the problem (e.g. a
403response). For transient external failures (such as5XXresponses), usemarkBad()instead.Returns void
setCookie
Sets a cookie within this session for the specific URL.
Parameters
rawCookie: string
url: string
Returns Promise<void>
Sessions are used to store information such as cookies and can be used for generating fingerprints and proxy sessions. You can imagine each session as a specific user, with its own cookies, IP (via proxy) and potentially a unique browser fingerprint. Session internal state can be enriched with custom user data for example some authorization tokens and specific headers in general.