Skip to main content

Function: createImpersonatingTransport()

createImpersonatingTransport(opts?): Transport

Defined in: src/core/transport.ts:347

A transport that impersonates a real browser's TLS / HTTP-2 fingerprint, for hosts that silently stall non-browser clients (stats.nba.com, stats.wnba.com). Backed by the optional peer dependency impit — npm install impit. If it is not installed, every call rejects with TransportUnavailableError.

Parameters​

opts?​

Options; default {}.

browser?​

string

impit browser profile ("chrome" default, "firefox", "chrome142", …).

proxyUrl?​

string

HTTP / HTTPS / SOCKS proxy URL, passed to impit as proxyUrl.

Returns​

Transport

A Transport that lazily creates one impit client on its first call and reuses it; the body is decoded per responseType as axiosTransport does, and set-cookie values are joined with "\n".

Throws​

TransportUnavailableError (from the returned transport) when impit cannot be imported; its cause is the import error. The failure is not cached, so a call after npm install impit succeeds.

Throws​

SdvError (from the returned transport) when the impit client cannot be constructed, e.g. an unknown browser profile; the message is redacted.

Throws​

Error (from the returned transport) a sanitized copy (safeCause) of impit's error on a network failure or timeout.

Example​

import sdv, { configure, createImpersonatingTransport } from 'sportsdataverse';

configure({
transport: {
nba_stats: createImpersonatingTransport({ browser: 'chrome' }),
wnba_stats: createImpersonatingTransport({ proxyUrl: process.env.HTTPS_PROXY }),
},
});
const rows = await sdv.nba.nbaStatsLeaguedashplayerstats({ leagueId: '00' });

Remarks​

impit is an optional peer dependency: nothing in sportsdataverse imports it statically. A plain-object body is sent as JSON with Content-Type: application/json unless the request sets a content-type; a string / URLSearchParams body is sent as-is. Like every transport it resolves for any HTTP status and leaves retry / auth / classification to request().