Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add proxy and bypass list parameters to createIncognitoBrowserContext #7516

Merged
merged 5 commits into from
Sep 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
* [event: 'targetdestroyed'](#event-targetdestroyed)
* [browser.browserContexts()](#browserbrowsercontexts)
* [browser.close()](#browserclose)
* [browser.createIncognitoBrowserContext()](#browsercreateincognitobrowsercontext)
* [browser.createIncognitoBrowserContext([options])](#browsercreateincognitobrowsercontextoptions)
* [browser.defaultBrowserContext()](#browserdefaultbrowsercontext)
* [browser.disconnect()](#browserdisconnect)
* [browser.isConnected()](#browserisconnected)
Expand Down Expand Up @@ -886,8 +886,10 @@ Closes Chromium and all of its pages (if any were opened). The [Browser] object

During the process of closing the browser, Puppeteer attempts to delete the temp folder created exclusively for this browser instance. If this fails (either because a file in the temp folder is locked by another process or because of insufficient permissions) an error is logged. This implies that: a) the folder and/or its content is not fully deleted; and b) the connection with the browser is not properly disposed (see [browser.disconnect()](#browserdisconnect)).

#### browser.createIncognitoBrowserContext()

#### browser.createIncognitoBrowserContext([options])
- `options` <[Object]> Set of configurable options to set on the browserContext. Can have the following fields:
- `proxyServer` <[string]> Optional proxy server with optional port to use for all requests. Username and password can be set in [page.authenticate(credentials)](#pageauthenticatecredentials).
- `proxyBypassList` <[string]> Optional: 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
29 changes: 27 additions & 2 deletions src/common/Browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,23 @@ import { Page } from './Page.js';
import { ChildProcess } from 'child_process';
import { Viewport } from './PuppeteerViewport.js';

/**
* BrowserContext options.
*
* @public
*/
export interface BrowserContextOptions {
/**
* Proxy server with optional port to use for all requests.
* Username and password can be set in `Page.authenticate`.
*/
proxyServer?: string;
/**
* Bypass the proxy for the given semi-colon-separated list of hosts.
*/
proxyBypassList?: string[];
}

/**
* @internal
*/
Expand Down Expand Up @@ -295,9 +312,17 @@ export class Browser extends EventEmitter {
* })();
* ```
*/
async createIncognitoBrowserContext(): Promise<BrowserContext> {
async createIncognitoBrowserContext(
options: BrowserContextOptions = {}
): Promise<BrowserContext> {
const { proxyServer = '', proxyBypassList = [] } = options;

const { browserContextId } = await this._connection.send(
'Target.createBrowserContext'
'Target.createBrowserContext',
{
proxyServer,
proxyBypassList: proxyBypassList && proxyBypassList.join(','),
}
);
const context = new BrowserContext(
this._connection,
Expand Down
7 changes: 7 additions & 0 deletions utils/doclint/check_public_api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,13 @@ function compareDocumentations(actual, expected) {
'"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array<PuppeteerLifeCycleEvent>',
},
],
[
'Method Browser.createIncognitoBrowserContext() options',
{
actualName: 'Object',
expectedName: 'BrowserContextOptions',
},
],
[
'Method BrowserContext.overridePermissions() permissions',
{
Expand Down