Seamless proxy integration for Puppeteer and Playwright with automatic rotation, health checking, and per-page proxy assignment.
- Per-page proxy assignment -- route each page or context through a different proxy
- Automatic rotation -- round-robin, random, or sticky (per-domain) strategies
- Health checking -- periodic checks with automatic failure tracking
- Dead proxy removal -- configurable auto-removal after consecutive failures
- Full auth support -- HTTP, HTTPS, SOCKS4, and SOCKS5 with username/password
- Puppeteer -- uses proxy-chain for transparent proxy relay
- Playwright -- leverages native per-context proxy configuration
- Zero config -- sensible defaults, fully customisable
npm install puppeteer-proxy-pluginInstall the browser automation library you need (or both):
# For Puppeteer
npm install puppeteer
# For Playwright
npm install playwrightimport puppeteer from 'puppeteer';
import { PuppeteerProxyPlugin } from 'puppeteer-proxy-plugin';
const plugin = new PuppeteerProxyPlugin({
proxies: [
'http://user:pass@proxy1.example.com:8080',
'http://user:pass@proxy2.example.com:8080',
],
rotationStrategy: 'round-robin',
});
const browser = await plugin.launch(puppeteer, { headless: true });
// Each page gets the next proxy in rotation
const page1 = await plugin.getPage(browser);
await page1.goto('https://httpbin.org/ip');
const page2 = await plugin.getPage(browser);
await page2.goto('https://httpbin.org/ip');
await plugin.close(browser);import { chromium } from 'playwright';
import { PlaywrightProxyPlugin } from 'puppeteer-proxy-plugin';
const plugin = new PlaywrightProxyPlugin({
proxies: [
'http://user:pass@proxy1.example.com:8080',
'http://user:pass@proxy2.example.com:8080',
],
rotationStrategy: 'round-robin',
});
const browser = await plugin.launch(chromium, { headless: true });
// Each context is completely isolated with its own proxy
const { context, page } = await plugin.getContext(browser);
await page.goto('https://httpbin.org/ip');
await context.close();
await plugin.close(browser);Cycle through proxies in sequential order. Best for even load distribution.
const plugin = new PuppeteerProxyPlugin({
proxies: myProxies,
rotationStrategy: 'round-robin',
});Pick a random proxy on each request. Good for unpredictable patterns.
const plugin = new PuppeteerProxyPlugin({
proxies: myProxies,
rotationStrategy: 'random',
});Pin each domain to a consistent proxy. Ideal for maintaining sessions.
const plugin = new PuppeteerProxyPlugin({
proxies: myProxies,
rotationStrategy: 'sticky',
});
// Same domain always routes through the same proxy
const page = await plugin.getPage(browser, { stickyKey: 'github.com' });const rotation = plugin.getRotation();
rotation.setStrategy('random');The pool automatically monitors proxy health with configurable intervals.
const plugin = new PuppeteerProxyPlugin({
proxies: myProxies,
healthCheck: true,
healthCheckInterval: 30000, // 30 seconds
healthCheckTimeout: 10000, // 10 second timeout
maxFailures: 3, // mark dead after 3 consecutive failures
autoRemoveDead: true, // remove dead proxies automatically
});const pool = plugin.getPool();
// Report success with latency
pool.reportSuccess(proxy, 250);
// Report failure (increments failure counter)
pool.reportFailure(proxy);
// Check stats
const stats = pool.getStats();
console.log(stats);
// { total: 5, healthy: 3, degraded: 1, dead: 1, averageLatency: 180 }const pool = plugin.getPool();
// Add proxies at runtime
pool.addProxy('http://user:pass@new-proxy.example.com:8080');
// Remove a proxy
pool.removeProxy('http://user:pass@old-proxy.example.com:8080');All of these formats are supported:
host:port
user:pass@host:port
http://host:port
http://user:pass@host:port
https://user:pass@host:port
socks4://user:pass@host:port
socks5://user:pass@host:port
Or use the object format:
{
host: '1.2.3.4',
port: 8080,
protocol: 'http',
username: 'user',
password: 'pass',
label: 'US East',
country: 'US',
}| Class | Description |
|---|---|
PuppeteerProxyPlugin |
Puppeteer integration with proxy-chain relay for per-page proxies |
PlaywrightProxyPlugin |
Playwright integration using native per-context proxy support |
ProxyPool |
Managed proxy pool with health checking and failure tracking |
RotationEngine |
Proxy selection engine with pluggable strategies |
| Method | Returns | Description |
|---|---|---|
launch(puppeteer, options?) |
Promise<Browser> |
Launch a browser with proxy configured |
getPage(browser, options?) |
Promise<Page> |
Get a new page with rotated proxy |
close(browser) |
Promise<void> |
Close browser and clean up relay servers |
getPool() |
ProxyPool |
Access the underlying proxy pool |
getRotation() |
RotationEngine |
Access the rotation engine |
| Method | Returns | Description |
|---|---|---|
launch(browserType, options?) |
Promise<Browser> |
Launch a browser |
getContext(browser, options?) |
Promise<{context, page}> |
Get a new context + page with proxy |
getPage(browser, options?) |
Promise<Page> |
Shorthand for getContext (returns page only) |
close(browser) |
Promise<void> |
Close browser and stop health checks |
getPool() |
ProxyPool |
Access the underlying proxy pool |
getRotation() |
RotationEngine |
Access the rotation engine |
| Method | Returns | Description |
|---|---|---|
addProxy(proxy) |
void |
Add a proxy to the pool |
removeProxy(proxy) |
boolean |
Remove a proxy from the pool |
getProxies() |
ProxyConfig[] |
Get all proxies |
getAvailable() |
ProxyConfig[] |
Get healthy and degraded proxies |
getState(proxy) |
ProxyState |
Get internal state for a proxy |
getStats() |
PoolStats |
Get aggregate pool statistics |
reportSuccess(proxy, latencyMs?) |
void |
Report a successful request |
reportFailure(proxy) |
void |
Report a failed request |
start() |
Promise<void> |
Start the health-check loop |
stop() |
void |
Stop the health-check loop |
size |
number |
Number of proxies in the pool |
| Method | Returns | Description |
|---|---|---|
getNext(stickyKey?) |
ProxyConfig | null |
Get the next proxy based on strategy |
getStrategy() |
RotationStrategy |
Get the current strategy |
setStrategy(strategy) |
void |
Change strategy at runtime |
clearSticky() |
void |
Clear all sticky mappings |
removeStickyKey(key) |
boolean |
Remove a specific sticky mapping |
stickySize |
number |
Number of active sticky mappings |
| Function | Returns | Description |
|---|---|---|
parseProxyUrl(url) |
ProxyConfig |
Parse a proxy URL string into a config object |
buildProxyUrl(config) |
string |
Build a proxy URL string from a config object |
normalizeProxy(proxy) |
ProxyConfig |
Normalize a string or config to ProxyConfig |
| Type | Description |
|---|---|
ProxyConfig |
Proxy server configuration (host, port, protocol, auth) |
ProxyPoolOptions |
Options for pool initialisation |
ProxyState |
Internal runtime state for a pooled proxy |
PoolStats |
Aggregate pool statistics |
RotationStrategy |
'round-robin' | 'random' | 'sticky' |
PageOptions |
Per-page/context proxy options |
PuppeteerPluginOptions |
Puppeteer plugin configuration |
PlaywrightPluginOptions |
Playwright plugin configuration |
See the examples/ directory:
puppeteer-basic.ts-- Puppeteer with proxy rotationplaywright-basic.ts-- Playwright with proxy rotationrotation.ts-- All rotation strategies demonstrated
Built by BirdProxies -- Premium Proxy Provider