Skip to main content

Basic proxy usage

Pass the proxy option to route requests through a proxy server:
import { fetch } from 'wreq-js';

const response = await fetch('https://example.com', {
  browser: 'chrome_142',
  proxy: 'http://proxy.example.com:8080',
});

Authenticated proxies

Include credentials in the proxy URL:
const response = await fetch('https://example.com', {
  browser: 'chrome_142',
  proxy: 'http://username:[email protected]:8080',
});

SOCKS proxies

SOCKS5 proxies are also supported:
const response = await fetch('https://example.com', {
  browser: 'chrome_142',
  proxy: 'socks5://proxy.example.com:1080',
});

// With authentication
const response = await fetch('https://example.com', {
  browser: 'chrome_142',
  proxy: 'socks5://user:[email protected]:1080',
});

Proxy rotation

Rotate through a list of proxies for each request:
import { fetch } from 'wreq-js';

const proxies = [
  'http://user:[email protected]:8080',
  'http://user:[email protected]:8080',
  'http://user:[email protected]:8080',
];

function getRandomProxy() {
  return proxies[Math.floor(Math.random() * proxies.length)];
}

// Each request uses a random proxy
for (let i = 0; i < 10; i++) {
  const response = await fetch('https://example.com', {
    browser: 'chrome_142',
    proxy: getRandomProxy(),
  });
  console.log(`Request ${i + 1}: ${response.status}`);
}

Session with proxy

Set a default proxy for all session requests:
import { createSession } from 'wreq-js';

const session = await createSession({
  browser: 'chrome_142',
  proxy: 'http://proxy.example.com:8080',
});

// All requests use the session proxy
await session.fetch('https://example.com/page1');
await session.fetch('https://example.com/page2');

await session.close();

Override session proxy

Override the session’s default proxy for specific requests:
const session = await createSession({
  browser: 'chrome_142',
  proxy: 'http://default-proxy.example.com:8080',
});

// Uses default proxy
await session.fetch('https://example.com');

// Uses different proxy for this request only
await session.fetch('https://example.com/special', {
  proxy: 'http://special-proxy.example.com:8080',
});

await session.close();

Supported proxy types

ProtocolURL FormatNotes
HTTPhttp://host:portStandard HTTP proxy
HTTPShttps://host:portTLS-encrypted proxy connection
SOCKS5socks5://host:portSOCKS5 proxy
SOCKS5hsocks5h://host:portSOCKS5 with remote DNS resolution