Skip to content

Commit

Permalink
feat: add proxy and bypass list parameters to createIncognitoBrowserC…
Browse files Browse the repository at this point in the history
…ontext

Issue: puppeteer#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();
  • Loading branch information
Joone Hur authored and joone committed Aug 23, 2021
1 parent 90163ef commit 24e9e12
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/api.md
Expand Up @@ -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.
Expand Down
11 changes: 9 additions & 2 deletions src/common/Browser.ts
Expand Up @@ -293,9 +293,16 @@ export class Browser extends EventEmitter {
* })();
* ```
*/
async createIncognitoBrowserContext(): Promise<BrowserContext> {
async createIncognitoBrowserContext(
server?: string,
bypassList?: string
): Promise<BrowserContext> {
const { browserContextId } = await this._connection.send(
'Target.createBrowserContext'
'Target.createBrowserContext',
{
proxyServer: server || undefined,
proxyBypassList: bypassList || undefined,
}
);
const context = new BrowserContext(
this._connection,
Expand Down

0 comments on commit 24e9e12

Please sign in to comment.