Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: NS_ERROR_PROXY_CONNECTION_REFUSED when trying to override headers in Firefox with Proxy enabled #33663

Open
paveldudka opened this issue Nov 19, 2024 · 1 comment

Comments

@paveldudka
Copy link

Version

1.48.0

Steps to reproduce

In my setup I try to override "User-Agent" http header while using Firefox + HTTP Proxy
However I get NS_ERROR_PROXY_CONNECTION_REFUSED error.
Important notes:

  • I verified that my HTTP Proxy works fine
  • Commenting out part that is responsible for http header solves the issue
  • Switching to Chromium solves the issue

My script:

import asyncio
import logging

from playwright.async_api import ProxySettings, async_playwright
logging.basicConfig(level=logging.DEBUG)


async def main():
    proxy: ProxySettings = {
        "server": "<proxy host>",
        "username": "< proxy username>",
        "password": "<proxy password>",
    }
    

    async with async_playwright() as playwright, await playwright.firefox.launch(
        headless=False,
    ) as browser:
        context = await browser.new_context(proxy=proxy)
        page = await context.new_page()
        await page.route(
            "**/*",
            lambda route: route.continue_(
                headers={
                    "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:131.0) Gecko/20100101 Firefox/131.0",
                }
            ),
        )

        await page.goto("https://bot.sannysoft.com/")

        await page.wait_for_timeout(30000)


if __name__ == "__main__":
    asyncio.run(main())

Expected behavior

I expect web page to load

Actual behavior

Calling page.goto() throws NS_ERROR_PROXY_CONNECTION_REFUSED

Additional context

No response

Environment

- Operating System: MacOS 14.6.1
- CPU: Apple M3 Max
- Browser: Firefox
- Python Version: 3.12.5
@mxschmitt
Copy link
Member

Instead of overriding the User-Agent like this, would our official API work for you?

        context = await browser.new_context(proxy=proxy, user_agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:131.0) Gecko/20100101 Firefox/131.0")
        page = await context.new_page()

@mxschmitt mxschmitt transferred this issue from microsoft/playwright-python Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants