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.

run.jsjavascript
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" },
// });

5ステップで設定

  1. 1Install the client with npm install playwright.
  2. 2Pass a proxy object (server, username, password) to chromium.launch().
  3. 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.
  4. 4Open a page and navigate to an IP echo endpoint to verify the exit IP.
  5. 5Move the proxy onto newContext() when you need separate IPs across parallel work.

Playwrightのプロキシに関する質問

認証からローテーションまで、PlaywrightをMurphy経由で使うためのポイントをまとめました。

Playwright用の認証情報を取得

ターゲットに合ったネットワークを選びましょう。高速で安定したセッションにはISPプロキシ、厳しいボット対策には幅広いIPを持つレジデンシャルプロキシ。