Skip to content

Proxy authentication fails when using .get() from the Tab class #3920

@nyx-rattapoom

Description

@nyx-rattapoom

When I navigate with page.get() on a Tab object, proxy credentials are not sent, because seleniumbase.undetected.cdp_driver.connection.Connection.set_auth() is never invoked.
If I first call driver.get() (on the Browser object), the proxy authentication does work.

Example code (two work-arounds)

import asyncio
import time

from seleniumbase import cdp_driver

proxy_address = "http://xx.xx.xx.xx:yyyy"
proxy_user = "u"
proxy_password = "p"
proxy = f"{proxy_user}:{proxy_password}@{proxy_address}"


async def workaround_a():
    driver = await cdp_driver.start_async(lang="en", proxy=proxy)
    page = driver.main_tab
    # workaround
    if proxy_user and proxy_password:
        await driver.connection.set_auth(proxy_user, proxy_password, page)
        time.sleep(0.25)
    await ip_check(page)
    driver.stop()


async def workaround_b():
    driver = await cdp_driver.start_async(lang="en", proxy=proxy)
    # workaround
    if proxy_user and proxy_password:
        await driver.get("about:blank")
    page = driver.main_tab
    await ip_check(page)
    driver.stop()


async def ip_check(page):
    await page.get("https://api.ipify.org/")
    body_element = await page.select("body")
    ip_address = body_element.text
    if not ip_address or "ERR" in ip_address:
        raise Exception("Failed to determine IP Address!")
    print(f"My IP Address = {ip_address}")


if __name__ == "__main__":
    loop = asyncio.new_event_loop()
    loop.run_until_complete(workaround_a())
    loop.run_until_complete(workaround_b())

SeleniumBase version: 4.40.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    UC Mode / CDP ModeUndetected Chromedriver Mode / CDP Modeinvalid usageYou may need to change what you're doing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions