Proxy Integration
HTTP Client Examples
curl --proxy proxy.capsolver.com:36583 --proxy-user 22F95FA73B206F02-resi-country_AO-rotate_0m-session_Ve27szkSzf:jZseKrJP https://api.ipify.orgBrowser Automation
const {Builder, Browser} = require("selenium-webdriver");
const chrome = require("selenium-webdriver/chrome");
const proxyChain = require("proxy-chain");
(async () => {
const upstreamProxyHost = "proxy.capsolver.com";
const upstreamProxyPort = 36583;
const username = "username";
const password = "password";
const targetUrl = "https://httpbin.org/ip";
const upstreamProxyUrl = `http://${encodeURIComponent(username)}:${encodeURIComponent(password)}@${upstreamProxyHost}:${upstreamProxyPort}`;
let driver;
let localProxyUrl;
try {
localProxyUrl = await proxyChain.anonymizeProxy({
url: upstreamProxyUrl,
});
console.log(`Local proxy: ${localProxyUrl}`);
const options = new chrome.Options().addArguments("--headless=new").addArguments(`--proxy-server=${localProxyUrl}`);
driver = await new Builder().forBrowser(Browser.CHROME).setChromeOptions(options).build();
await driver.get(targetUrl);
console.log(await driver.findElement({css: "body"}).getText());
} catch (error) {
console.error(error.message);
if (error.code === "MODULE_NOT_FOUND" && error.message.includes("selenium-webdriver")) {
console.error("Run: pnpm add selenium-webdriver");
}
if (error.code === "MODULE_NOT_FOUND" && error.message.includes("proxy-chain")) {
console.error("Run: pnpm add proxy-chain");
}
process.exitCode = 1;
} finally {
if (driver) {
await driver.quit();
}
if (localProxyUrl) {
await proxyChain.closeAnonymizedProxy(localProxyUrl, true);
}
}
})();