Tích hợp proxy với Playwright
Playwright has first-class proxy support, so there is no extension trick or separate authenticate call. Pass a proxy object with server, username and password to launch(), and it applies across Chromium, Firefox and WebKit. You can also set the proxy per context when different pages need different IPs.
import { chromium } from "playwright";
const browser = await chromium.launch({
proxy: {
// Residential gateway, or "http://IP:PORT" for one of your ISP proxies.
server: "http://gw-eu.murphyproxies.com:8888",
username: "USERNAME",
password: "PASSWORD",
},
});
const page = await browser.newPage();
await page.goto("https://httpbin.org/ip");
console.log(await page.textContent("body"));
await browser.close();
// Per-context proxy (e.g. a US exit in one context, an ISP IP in another):
// const context = await browser.newContext({
// proxy: { server: "http://gw-usa.murphyproxies.com:8888",
// username: "USERNAME", password: "PASSWORD" },
// });Cài đặt trong 5 bước
- 1Install the client with npm install playwright.
- 2Pass a proxy object (server, username, password) to chromium.launch().
- 3Point server at http://gw-eu.murphyproxies.com:8888 (another gw- region, port 7777 on Private 2, or http://IP:PORT for an ISP proxy) with the credentials from your dashboard.
- 4Open a page and navigate to an IP echo endpoint to verify the exit IP.
- 5Move the proxy onto newContext() when you need separate IPs across parallel work.
Câu hỏi về proxy cho Playwright
Mọi điều bạn cần để định tuyến Playwright qua Murphy, từ xác thực đến xoay vòng IP.
Yes. Unlike Puppeteer, Playwright accepts username and password directly in the proxy option, so you do not need a separate authenticate step or a helper extension. It works identically across Chromium, Firefox and WebKit.
Yes. Pass a proxy object to browser.newContext() and that context uses its own IP while others keep the launch-level proxy. This is handy for testing several countries, or mixing a residential gateway with one of your ISP IPs, in one run.
Playwright accepts socks5:// servers, but Chromium cannot authenticate to a SOCKS5 proxy with a username and password. Use the HTTP scheme for authenticated Chromium sessions, which carries HTTPS sites as well.
Nhận thông tin đăng nhập cho Playwright
Chọn mạng lưới hợp với mục tiêu của bạn. Proxy ISP cho phiên nhanh và ổn định, proxy dân cư cho nguồn IP đa dạng trước các hệ thống chống bot khắt khe.