A.Bokizh
A.Bokizh

Reputation: 165

How do I authenticate a proxy in playwright

I have this arg in my playwright browser options, '--proxy-server=endpoint:port' and I could authenticate my proxy in puppeteer with await page.authenticate({username, password});. I could not find any ways to do the same operation with playwright. How do I do that?

Upvotes: 2

Views: 9828

Answers (2)

geng smb88
geng smb88

Reputation: 11

For newest Playwright version (Year 2024) using 'username' for proxy user variable, with example as pavelsaman above:

const browser = await chromium.launch({
    'headless': false,
    'proxy': {
        'server': 'http://your-default-proxy-host:port',
        'username': 'username',
        'password': 'passwd'
     }
});
const context = await browser.newContext({
    'proxy': {
        'server': PERCONTEXT_PROXY_SERVER,
        'username': 'username',
        'password': 'passwd'
     }
});

Upvotes: 1

pavelsaman
pavelsaman

Reputation: 8352

You can load pages over a HTTP proxy in two ways:

1/ set it globally for the entire browser:

const browser = await chromium.launch({
    proxy: {
        server: 'http://myproxy.com:3128',
        user: 'usr',
        password: 'pwd'
    }
});

2/ or you can set it per context:

const browser = await chromium.launch({
    proxy: { server: 'per-context' }
});
const context = await browser.newContext({
    proxy: {
        server: 'http://myproxy.com:3128',
        user: 'usr',
        password: 'pwd'
    }
})

It's all documented in Playwright documentation here.

Upvotes: 6

Related Questions