Integration · JavaScript

Puppeteer

Chromium through a proxy server, with authentication handled on the page.

Install

terminal
npm install puppeteer

Example

browse.mjs
import puppeteer from "puppeteer";

const browser = await puppeteer.launch({ args: ["--proxy-server=http://GATEWAY_HOST:PORT"] });
const page = await browser.newPage();
await page.authenticate({ username: "USERNAME", password: "PASSWORD" });
await page.goto("https://httpbin.org/ip");
console.log(await page.evaluate(() => document.body.innerText));
await browser.close();

Replace USERNAME, PASSWORD, GATEWAY_HOST and PORT with the values in your dashboard. Never commit them.

Notes

  • Chromium does not accept credentials inside --proxy-server, which is why authenticate() is used.

Common errors

407 Proxy Authentication RequiredCause. Credentials missing, mistyped, or not URL-encoded.
Fix. Percent-encode special characters in the username and password, or pass credentials separately from the URL where the client allows it.
Timeouts on first requestCause. Wrong gateway host or port, or an outbound firewall rule on your side.
Fix. Copy host and port from the dashboard entry for your product and test with curl first.

Next: measure it on your real target.