How to use a proxy with Crawlee
Crawlee is a Node.js crawling library with HTTP crawlers (Cheerio, JSDOM) and browser crawlers (Playwright, Puppeteer). Proxies are configured once with ProxyConfiguration. This guide shows how to connect it to a residential gateway, tie each Crawlee session to its own sticky IP, target countries per request, and handle proxy errors.
Updated 9 November 2026
Prerequisites
- Node.js 20+ and
npm i crawlee(examples use Crawlee 3.x). For browser crawlers, also installplaywrightand its browsers. - A proxy login from the dashboard under Logins, written as
USERandPASS.
Crawl responsibly: collect public data, keep request rates sensible with maxRequestsPerMinute and maxConcurrency, and follow each site's terms.
Basic HTTP proxy
Pass one gateway URL in proxyUrls. Crawlee normally rotates through a list of proxies, but the gateway already rotates exits, so one URL is enough. proxyInfo in the handler tells you which proxy a request used.
import { CheerioCrawler, ProxyConfiguration } from "crawlee";
const proxyConfiguration = new ProxyConfiguration({
proxyUrls: ["http://USER-cc-us:PASS@gw.hyperproxy.io:8888"],
});
const crawler = new CheerioCrawler({
proxyConfiguration,
async requestHandler({ request, body, proxyInfo, log }) {
log.info(`${request.url} via ${proxyInfo?.hostname}: ${String(body).trim()}`);
},
});
await crawler.run(["https://api.ipify.org"]);Authentication
Credentials go in the proxy URL. Crawlee passes them to its HTTP client, or to the browser's proxy settings for browser crawlers, so you don't need page.authenticate() or extensions. URL-encode special characters in the password.
Rotating vs sticky: map Crawlee sessions to proxy sessions
Without a session option, the gateway gives each new connection a new exit. Crawlee has its own session pool: each session holds cookies and is reused for several requests. Use newUrlFunction to put Crawlee's session id into the username as a proxy session, so cookies and IP always travel together. Session ids may only contain letters and digits, so strip the underscore from Crawlee's ids.
import { CheerioCrawler, ProxyConfiguration } from "crawlee";
const proxyConfiguration = new ProxyConfiguration({
// Crawlee passes its own session id; map it to a hyperproxy session
newUrlFunction: (sessionId) => {
const options = ["cc-us"];
if (sessionId) {
// Crawlee ids look like "session_Ab12Cd34Ef"; keep letters and digits only
options.push(`session-${String(sessionId).replace(/[^a-zA-Z0-9]/g, "")}`, "ttl-30");
}
return `http://USER-${options.join("-")}:PASS@gw.hyperproxy.io:8888`;
},
});
const crawler = new CheerioCrawler({
proxyConfiguration,
useSessionPool: true,
persistCookiesPerSession: true, // cookies and IP stay together
sessionPoolOptions: { maxPoolSize: 20 },
async requestHandler({ request, session, body, log }) {
log.info(`${request.url} session=${session?.id} ip=${String(body).trim()}`);
},
});
await crawler.run(["https://api.ipify.org?a=1", "https://api.ipify.org?a=2", "https://api.ipify.org?a=3"]);When Crawlee retires a session (after errors, too many uses, or a 401, 403 or 429 response), the next session gets a new id and therefore a new IP. Keep ttl at least as long as a session is likely to live, up to 120 minutes.
Browser crawlers and per-request targeting
Browser crawlers open many connections per page, so give them sticky sessions too, otherwise one page can load from several exits. newUrlFunction also receives the request, so you can choose the country from userData.
import { PlaywrightCrawler, ProxyConfiguration } from "crawlee";
const proxyConfiguration = new ProxyConfiguration({
newUrlFunction: (sessionId) =>
`http://USER-cc-de-session-${String(sessionId ?? Date.now()).replace(/[^a-zA-Z0-9]/g, "")}:PASS@gw.hyperproxy.io:8888`,
});
const crawler = new PlaywrightCrawler({
proxyConfiguration,
useSessionPool: true,
persistCookiesPerSession: true,
maxConcurrency: 5,
async requestHandler({ page, request, log }) {
log.info(`${request.url}: ${await page.textContent("body")}`);
},
});
await crawler.run(["https://api.ipify.org"]);Country and city targeting
| Username | Exit |
|---|---|
USER-cc-us | United States |
USER-cc-us-city-new_york | New York |
USER-cc-us-region-california | California |
USER-cc-us-os-android | An Android device in the US |
USER-cont-eu | Anywhere in Europe |
USER-cc-us-city-houston-strict-false | Houston, falling back to the US |
See Targeting for every option.
SOCKS5
Crawlee's HTTP crawlers and browsers are built around HTTP proxies, and browsers don't support authenticated SOCKS5. Use the HTTP endpoint shown here: HTTPS pages are tunneled with CONNECT and stay encrypted end to end.
Concurrency
Crawlee scales concurrency itself based on CPU and memory. Set limits with maxConcurrency and maxRequestsPerMinute, and size the session pool (sessionPoolOptions.maxPoolSize) to how many parallel identities you want. Each pool session uses its own sticky IP.
Error handling and retries
Crawlee retries failed requests (3 times by default) and rotates the session when it detects proxy errors. Retries can't fix every gateway error, though (Errors):
- 407: wrong login, an invalid option, or no balance. Every retry fails the same way, so stop the crawl.
- 404: no exit matches the targeting; widen it or add
strict-false. - 403: the target is not allowed. Note that Crawlee also treats a 403 from the site as a reason to rotate the session.
- 429, 502, 504: let Crawlee retry; a new session means a new exit.
const crawler = new CheerioCrawler({
proxyConfiguration,
maxRequestRetries: 3,
maxRequestsPerMinute: 120,
// runs before each retry
errorHandler({ log }, error) {
if (/\b407\b/.test(error.message)) {
log.error("Proxy auth failed: check login, targeting options and balance");
crawler.stop("proxy authentication failed");
}
},
// runs after the last retry
failedRequestHandler({ request, log }, error) {
log.warning(`Giving up on ${request.url}: ${error.message}`);
},
async requestHandler({ body }) { /* ... */ },
});Verify the exit IP
Crawl https://api.ipify.org as in the examples and log the body. With the session mapping, requests that share a Crawlee session log the same IP; different sessions log different IPs. Add a query string to repeat URLs, since Crawlee de-duplicates requests by URL.
Troubleshooting
- 407 on every request: a session id with an underscore or another invalid character; strip it as shown.
- Only one request runs for repeated URLs: de-duplication; vary the URL or set a
uniqueKey. - Cookies from one IP used on another: enable
persistCookiesPerSessiontogether with session-based proxy URLs. - Browser pages load slowly: lower
maxConcurrencyand block heavy resources with a pre-navigation hook.
FAQ
Do I need tieredProxyUrls?
No. Tiers are for switching between different proxy pools. With one gateway, proxyUrls or newUrlFunction is enough.
Does this work with Crawlee for Python?
The Python version has a similar ProxyConfiguration with proxy_urls. The username format is the same.
Should I use Crawlee or Playwright directly?
Crawlee adds queues, retries, sessions and autoscaling on top of Playwright and Puppeteer. For small scripts, the plain libraries are simpler.
Where are more examples?
See Examples and the Node.js fetch guide.
Try it on your own workload
Sign up with GitHub or Google, create a proxy login and send your first request in a minute.
More proxy integration guides
- Python requests — Rotating and sticky residential proxies with Python requests, including SOCKS5 and retries.
- Python httpx — Sync and async httpx through a residential proxy with the proxy= argument and SOCKS5.
- Python aiohttp — High-concurrency aiohttp requests through rotating or sticky residential IPs.
- Scrapy — Route Scrapy spiders through residential proxies with request.meta and a middleware.
- Playwright — Run Playwright through residential proxies, per browser or per context, with sticky sessions.
- Puppeteer — Launch Puppeteer behind an authenticated residential proxy with page.authenticate.
- Node.js axios — Send axios requests through HTTP and SOCKS5 residential proxies with proxy agents.
- Node.js fetch & undici — Use Node's built-in fetch with undici ProxyAgent or NODE_USE_ENV_PROXY.
- Go net/http — Configure Go's http.Transport for HTTP and SOCKS5 residential proxies.
- curl & SOCKS5 — Use curl with HTTP and SOCKS5 proxies, and test targeting from the command line.