Skip to content

Error when creating browser contexts with a proxy + credentials url #257

@WilliamLafarie

Description

@WilliamLafarie

Hi!
My plan was to create several browser contexts with a different proxy location for each one. For example:

async def main():
    browser = Chrome()
    await browser.start()

    username = 'username'
    password = 'password'

    # Create context with specific proxy
    context__2 = await browser.create_browser_context(
        proxy_server=f"{username}:{password}@myproxy.com:10000",
    )
    context__3 = await browser.create_browser_context(
        proxy_server=f"{username}:{password}@myproxy.com:20001",
    )

    tab__1 = await browser.start()
    tab__2 = await browser.new_tab(browser_context_id=context__2)
    tab__3 = await browser.new_tab(browser_context_id=context__3)

    ...

On both tabs with a new context, the browser returns ERR_NO_SUPPORTED_PROXIES. However, when I use ChromiumOptions, everything works correctly:

async def main():
    ...
    options = ChromiumOptions()
    options.add_argument(f"--proxy-server={username}:{password}@myproxy.com:20001")
    browser = Chrome(options=options)
    await browser.start()
    ....

According to the create_browser_context method, it seems that it can only handle proxies without authentication. Is this the expected behaviour or have I missed something?

#pydoll/browser/chromium/base.py

async def create_browser_context(
        self, proxy_server: Optional[str] = None, proxy_bypass_list: Optional[str] = None
    ) -> str:
        """
        Create isolated browser context (like incognito).

        Browser contexts provide isolated storage and don't share session data.
        Multiple contexts can exist simultaneously.

        Args:
            proxy_server: Optional proxy for this context only (scheme://host:port).
            proxy_bypass_list: Comma-separated hosts that bypass proxy.

        Returns:
            Browser context ID for use with other methods.
        """
        response: CreateBrowserContextResponse = await self._execute_command(
            TargetCommands.create_browser_context(
                proxy_server=proxy_server,
                proxy_bypass_list=proxy_bypass_list,
            )
        )
        return response['result']['browserContextId']

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions