microsoft / playwright-dotnet

.NET version of the Playwright testing and automation library.

Home Page:https://playwright.dev/dotnet/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG]I want to create a browser settings proxy,

bbhxwl opened this issue · comments

Can't create a browser with different contexts? One context can set a proxy, while the other context doesn't set a proxy. Is it impossible to implement this? Setting up proxies seems to require setting up proxies for all?

Are you using Microsoft.Playwright.{NUnit,MSTest}?

Proxy settings can be provided on the context and launch-level. If you are using Microsoft.Playwright.{NUnit,MSTest}, it can be done via the runsettings file e.g.:

<?xml version="1.0" encoding="utf-8"?>
        <RunSettings>
            <Playwright>
                <BrowserName>chromium</BrowserName>
                <LaunchOptions>
                    <Headless>false</Headless>
                    <Proxy>
                        <Server>http://127.0.0.1:3128</Server>
                        <Username>user</Username>
                        <Password>pwd</Password>
                    </Proxy>
                </LaunchOptions>
            </Playwright>
        </RunSettings>

or when using the Library via:

var browser = await playwright.Chromium.LaunchAsync(new() {
    Proxy = new() {
         Server = "...",
    }
});

Are you using Microsoft.Playwright.{NUnit,MSTest}?

Proxy settings can be provided on the context and launch-level. If you are using Microsoft.Playwright.{NUnit,MSTest}, it can be done via the runsettings file e.g.:

<?xml version="1.0" encoding="utf-8"?>
        <RunSettings>
            <Playwright>
                <BrowserName>chromium</BrowserName>
                <LaunchOptions>
                    <Headless>false</Headless>
                    <Proxy>
                        <Server>http://127.0.0.1:3128</Server>
                        <Username>user</Username>
                        <Password>pwd</Password>
                    </Proxy>
                </LaunchOptions>
            </Playwright>
        </RunSettings>

or when using the Library via:

var browser = await playwright.Chromium.LaunchAsync(new() {
    Proxy = new() {
         Server = "...",
    }
});

What I mean is to create one browser, where some contexts do not have proxies set, while others do. It seems that it is not possible to do so, so it is necessary to create two browsers? Do you still not support Socks5 proxy?

You can do the following, would that work for you?

var context1 = await Browser.NewContextAsync(new () {
    Proxy = new()
    {
        Server = "http://foobar",
    },
});
var page1 = await context1.NewPageAsync();
var context2 = await Browser.NewContextAsync(new () {
    Proxy = new()
    {
        Server = "http://foobar2",
    },
});
var page2 = await context1.NewPageAsync();

Socks5 is supported, just not with auth: microsoft/playwright#10567

If you are using Windows, you might run into microsoft/playwright#17252, for which we recommend creating two browsers then. One with proxies, one without since there is no way of resetting/removing a proxy which was previously globally set.

You can do the following, would that work for you?

var context1 = await Browser.NewContextAsync(new () {
    Proxy = new()
    {
        Server = "http://foobar",
    },
});
var page1 = await context1.NewPageAsync();
var context2 = await Browser.NewContextAsync(new () {
    Proxy = new()
    {
        Server = "http://foobar2",
    },
});
var page2 = await context1.NewPageAsync();

Socks5 is supported, just not with auth: microsoft/playwright#10567

If you are using Windows, you might run into microsoft/playwright#17252, for which we recommend creating two browsers then. One with proxies, one without since there is no way of resetting/removing a proxy which was previously globally set.

I understand. When can I support Socks5 with an account and password?

We unfortunately cannot commit on any eta. You could workaround it by having some kind of reverse proxy which is between and takes care of the auth.

I'm closing it for now, since the original issue has been answered.