axios-impersonate-adapter
v1.1.2
Published
Axios adapter for impersonate
Readme
axios-impersonate-adapter
Axios adapter that sends requests through curl-impersonate.
Install
pnpm add axios-impersonate-adapter
# or
npm i axios-impersonate-adapter
# or
yarn add axios-impersonate-adapterQuick Start
import axios from 'axios';
import adapter from 'axios-impersonate-adapter';
const client = axios.create({
adapter,
impersonate: 'chrome146',
});
const res = await client.get('https://example.com', {
params: { q: 'test' },
});
console.log(res.status, res.data);Configuration
The adapter reads these fields from AxiosRequestConfig:
impersonate: browser profile name. If omitted, defaults to the latest bundled stable Chrome profile.timeout: max request time (ms). Mapped tocurl --max-time.maxRedirects:undefined→ follow redirects (--location)number→ follow redirects with a limit (--location --max-redirs <n>)
proxy:protocol: defaulthttphost: hostname or URLport: optional portauth:{ username, password? }→--proxy-user
headers: merged with the impersonate defaults.- If the request only has axios default
Accept(application/json, text/plain, */*), the adapter removes it so the impersonate defaultAcceptcan apply.
- If the request only has axios default
jar: Atough-cookieCookieJarinstance.
Cookie Support
The adapter supports cookie persistence via tough-cookie.
import axios from 'axios';
import { CookieJar } from 'tough-cookie';
import adapter from 'axios-impersonate-adapter';
const jar = new CookieJar();
const client = axios.create({
adapter,
jar,
});
// Cookies set by this request are stored in `jar`
await client.get('https://example.com/login');
// Cookies from `jar` are sent with this request
await client.get('https://example.com/dashboard');TypeScript
This package augments AxiosRequestConfig with impersonate.
import 'axios-impersonate-adapter';Notes
- The adapter shells out to the bundled
curl-impersonatebinary. https://github.com/lexiforest/curl-impersonate
Roadmap
- ~~Session support (cookie persistence).~~
- Migrate from spawn-based execution to a native implementation.
Development
pnpm build
pnpm lint
pnpm testScripts
pnpm run generate-impersonates: regeneratessrc/impersonate.tsfrom the upstream profiles.pnpm run prepare-submodule: syncs thecurl-impersonatesubmodule to the expected revision.
