# How to Use a Playwright Proxy

> Learn to use Playwright proxies in 2025 for web scraping. Avoid IP bans, access geo-restricted content, and master proxy rotation and authentication.

Source: https://www.zenrows.com/blog/playwright-proxy

With websites implementing measures like anti-bots to prevent web scraping, scrapers are often flagged and blocked. This is where [Playwright](/blog/playwright-scraping) proxies come in.

By routing your automated browser traffic through proxy servers, you can effectively avoid IP bans and access geo-restricted content. In this tutorial, you'll learn:

-   [Basic Proxy Implementation](#setting-up-proxy-in-playwright).
-   [Playwright Proxy Authentication](#playwright-proxy-authentication).
-   [How to Rotate Proxies in Playwright](#rotating-proxies).
-   [How to Choose the Best Proxies](#choosing-the-best-proxies).

Ready to enhance your web scraping capabilities? Let's dive in!

## Quick Answer: Setting Up a Proxy in Playwright
In this section, you'll learn how to set up proxies in Playwright, where to get the proxies from, and how to authenticate them.

To demonstrate proxy implementation, you'll create a simple script that accesses [HTTPBin](https://httpbin.io/ip), a service that returns the IP address of the client making the request. This will help us verify if the proxy is working correctly.

> **Skip the blocks.** [Try Zenrows free](/) and get clean web data without the anti-bot fight.

To follow along in this tutorial, install the Playwright Python library using the `pip` command:

```nginx
pip install playwright
```

Then, install the necessary browsers using the `install` command.

```nginx
playwright install
```

Next, grab a free proxy from the [Free Proxy List](https://free-proxy-list.net/) website.

Here's the basic setup for using a proxy with Playwright:

<!-- scraper.py -->
```python
from playwright.async_api import async_playwright
import asyncio

async def main():
    async with async_playwright() as playwright:
        # configure browser with proxy
        browser = await playwright.chromium.launch(
            proxy={
                "server": "38.165.231.59:8080",
            },
        )
        context = await browser.new_context()
        page = await context.new_page()

        await page.goto("https://httpbin.io/ip")
        html_content = await page.content()
        print(html_content)

        await context.close()
        await browser.close()

asyncio.run(main())
```

You'll get the following output on running this script:

```json
{
  "origin": "38.165.231.59"
}
```

Bingo! The result above is the IP address of our free proxy. Now you know how to set up a Playwright proxy.

> **Note**
>
> While this example uses a free proxy for demonstration purposes, free proxies are generally unreliable and short-lived. They often suffer from poor performance, frequent downtime, and potential security risks. Later in this article, we'll explore more reliable proxy solutions for production environments.

### Playwright Proxy Authentication
Some proxy providers, particularly the ones offering premium proxies, require authentication to access their servers.

Add the necessary credentials as parameters in the `launch()` method to authenticate a Playwright proxy. Here's an example:

```python
browser = await playwright.chromium.launch(
    proxy={
        "server": "<PROXY_IP_ADDRESS>:<PROXY_PORT>",
        "username": "<YOUR_USERNAME>",
        "password": "<YOUR_PASSWORD>",
    },
)
```

Now your Playwright scraper looks like this:

<!-- scraper.py -->
```python
from playwright.async_api import async_playwright
import asyncio


async def main():
    async with async_playwright() as playwright:
        browser = await playwright.chromium.launch(
            proxy={
                "server": "<PROXY_IP_ADDRESS>:<PROXY_PORT>",
                "username": "<YOUR_USERNAME>",
                "password": "<YOUR_PASSWORD>",
            },
        )
        context = await browser.new_context()
        page = await context.new_page()

        await page.goto("https://httpbin.io/ip")
        html_content = await page.content()
        print(html_content)

        await context.close()
        await browser.close()


asyncio.run(main())
```

## Rotating Proxies in Playwright
When your script sends numerous requests rapidly, websites may flag this behavior as suspicious and block your IP address. Implementing a rotating proxy strategy can effectively prevent this.

By switching to a new IP address after a set number of requests or time intervals, you make each request appear as if it's coming from a different user.

To implement proxy rotation in Playwright, create a simple proxy pool and randomly select different proxies for each request using Python's `random` module. This approach helps distribute your requests across multiple IPs and [reduces the chances of getting blocked](/blog/web-scraping-without-getting-blocked).

Let's look at a practical example using free proxies from the Free Proxy List.

```python
from playwright.async_api import async_playwright
import asyncio
import random

# define a pool of proxy servers
proxy_pool = [
    {"server": "68.183.185.62:80"},
    {"server": "61.28.233.217:3128"},
    {"server": "213.230.108.208:3128"},
    # add more proxy servers as needed
]


async def main():
    # select a random proxy for each request
    proxy = random.choice(proxy_pool)

    async with async_playwright() as playwright:
        browser = await playwright.chromium.launch(proxy=proxy)
        context = await browser.new_context()
        page = await context.new_page()

        await page.goto("https://httpbin.io/ip")
        text_content = await page.content()
        print(text_content)

        await context.close()
        await browser.close()


asyncio.run(main())
```

Here's the result from manually running this script multiple times:

```json
# request 1
{
  "origin": "68.183.185.62"
}
# request 2
{
  "origin": "213.230.108.208"
}
# request 3
{
  "origin": "61.28.233.217"
}
```

Awesome, you've created your first Playwright proxy rotator.

However, it's essential to note that free proxies are unreliable and only used for testing purposes. For actual web scraping projects, you need premium proxies that rotate proxies automatically for you.

Let's explore these options next.

## How to Choose the Best Proxies
To minimize detection and avoid getting blocked while scraping, consider using premium proxies, particularly residential proxies with IP addresses tied to real devices. If you're looking for reliable options, check out our curated list of the [best web scraping proxy services](/blog/web-scraping-proxy).

One of the best premium proxy service providers is [Zenrows Residential Proxies](/products/fetch). It offers advanced features that go beyond basic proxy rotation. It provides proxy auto-rotation, residential IPs, geolocation features, and more that significantly increase your scraping success rate.

To get started, [sign up for Zenrows](/) to open the Request Builder. Go to the [Residential Proxies](https://app.zenrows.com/proxies/generator) page. Then, copy the proxy domain, port, and credentials (username and password).

![generate residential proxies with zenrows](/blog/_img/zenrows-proxy.png)

Modify your Playwright code with the copied credentials as follows:

<!-- scraper.py -->
```python
from playwright.async_api import async_playwright
import asyncio

async def main():
    async with async_playwright() as playwright:
        browser = await playwright.chromium.launch(
            proxy={
                "server": "<PROXY_DOMAIN>:<PROXY_PORT>",
                "username": "<YOUR_ZENROWS_PROXY_USERNAME>",
                "password": "<YOUR_ZENROWS_PROXY_PASSWORD>",
            },
        )
        context = await browser.new_context()
        page = await context.new_page()

        await page.goto("https://httpbin.io/ip")
        html_content = await page.content()
        print(html_content)

        await context.close()
        await browser.close()

asyncio.run(main())
```

Run the code. Here's an example of what the output would look like:

```json
{
  "origin": "94.19.73.27:65404"
}
```

The above output confirms that your request was routed through Zenrows' premium proxies.

Congratulations! You now know how to configure a proxy in Playwright.

## Conclusion
Setting up proxies with Playwright is essential for successful web scraping, but managing proxy rotation manually can be time-consuming and error-prone. While free proxies might seem appealing, their unreliability and poor success rates make them unsuitable for serious scraping projects.

Premium residential proxies are the way to go for reliable results. Zenrows offers a comprehensive solution that automatically handles proxy management. Ready to supercharge your web scraping? [Try Zenrows for free](/)!
