From 24e9e12fee09a7a3ef44273b30360445eafa026c Mon Sep 17 00:00:00 2001 From: Joone Hur Date: Sun, 22 Aug 2021 21:30:41 -0700 Subject: [PATCH] feat: add proxy and bypass list parameters to createIncognitoBrowserContext Issue: #678 Example: const browser = await puppeteer.launch(); const context = await browser.createIncognitoBrowserContext('myproxy.com:3128'); const page = await context.newPage() await page.authenticate({username: 'foo', password: 'bar' }); await page.goto('https://google.com'); await browser.close(); --- docs/api.md | 2 ++ src/common/Browser.ts | 11 +++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/docs/api.md b/docs/api.md index 798a0e0585a1f..7ed65834c88fa 100644 --- a/docs/api.md +++ b/docs/api.md @@ -887,6 +887,8 @@ During the process of closing the browser, Puppeteer attempts to delete the temp #### browser.createIncognitoBrowserContext() +- `proxyServer` <[string]> Proxy server with optional port to use for all requests. username and password can be set in ['page.authenticate']. +- `proxyBypassList` <[string]> Bypass the proxy for the given semi-colon-separated list of hosts. - returns: <[Promise]<[BrowserContext]>> Creates a new incognito browser context. This won't share cookies/cache with other browser contexts. diff --git a/src/common/Browser.ts b/src/common/Browser.ts index cbb3932d8605c..7e047fd6b6a69 100644 --- a/src/common/Browser.ts +++ b/src/common/Browser.ts @@ -293,9 +293,16 @@ export class Browser extends EventEmitter { * })(); * ``` */ - async createIncognitoBrowserContext(): Promise { + async createIncognitoBrowserContext( + server?: string, + bypassList?: string + ): Promise { const { browserContextId } = await this._connection.send( - 'Target.createBrowserContext' + 'Target.createBrowserContext', + { + proxyServer: server || undefined, + proxyBypassList: bypassList || undefined, + } ); const context = new BrowserContext( this._connection,