Use Proxies with Playwright

In this article, you will learn how to set up residential and mobile proxies for testing automation in Playwright.

  1. To use Playwright and set up a proxy, paste this code example:
     const playwright = require('@playwright/test');
    const launchOptions = {
    proxy: {
    server: 'proxy.froxy.com:9000',
    username: 'login',
    password: 'password'
    }
    };
    (async () => {
    const defaultBrowser = await playwright['chromium'].launch({});
    const context = await defaultBrowser.newContext();
    const page = await context.newPage();
    await page.goto('https://froxy.com/api/detect-ip');
    console.log('chromium without proxy:', await page.textContent("*"));
    await defaultBrowser.close();

    for (const browserType of ['chromium', 'firefox', 'webkit']) {
    const browser = await playwright[browserType].launch(launchOptions);
    const context = await browser.newContext();
    const page = await context.newPage();
    try {
    await page.goto('https://froxy.com/api/detect-ip');
    console.log(`${browserType} with proxy:`, await page.textContent("*"));
    } catch (e) {
    console.log(e);
    }
    await browser.close();
    }
    })();
  2.  Please add the proxy configuration to playwright.config.ts.
  3. All server and port information is available in your Froxy Dashboard.
  4. For more information, you can visit the Playwright developer portal.

If you still have any questions about the operation of our service froxy.com, you can ask them in the online chat in the lower right corner of the site or contact support at support@froxy.com.