Skip to content

[Bug]: Chromium new_context({ proxy }) ignored when running inside Docker without CDP #2883

Open
@4dvisor

Description

@4dvisor

Version

1.52.0

Steps to reproduce

import asyncio
import json
from playwright.async_api import async_playwright

TEST_URL = "https://api.ipify.org?format=json"
PROXY = {
    "server": "http://proxy_url:proxy_port",
    "username": "username",
    "password": "password", 
}

async def fetch_ip(context):
    page = await context.new_page()
    await page.goto(TEST_URL, wait_until="domcontentloaded")
    ip = json.loads(await page.text_content("body"))["ip"]
    await context.close()
    return ip


async def main():
    async with async_playwright() as p:
        browser = await p.chromium.launch(
            headless=True,
            proxy={"server": "per-context"},               # <-- required
            args=["--disable-blink-features=AutomationControlled"],
        )

        ctx1 = await browser.new_context(proxy=PROXY)
        print("CTX-1 IP ⇒", await fetch_ip(ctx1))

        await browser.close()

asyncio.run(main())

Expected behavior

CTX-1 IP ⇒ <IP-from-proxy>

Actual behavior

CTX-1 ⇒ <host-public-IP>

Additional context

When Chromium is launched with proxy={"server": "per-context"} inside a Docker container, no context created with browser.new_context(proxy=…) uses the proxy at all—all requests always fall back to the container’s outbound IP.

Environment

- Operating System: [Ubuntu 22.04]
- CPU: [amd64]
- Browser: [Chromium]
- Python Version: [3.12]
- Docker img: mcr.microsoft.com/playwright/python:v1.52.0-noble
- Other info:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions