Skip to content

Commit

Permalink
feat: replace normal arguments with an object in createIncognitoBrows…
Browse files Browse the repository at this point in the history
…erContext

Issue: #678
  • Loading branch information
Joone Hur authored and joone committed Sep 17, 2021
1 parent 00f9bbb commit 99de59e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
10 changes: 5 additions & 5 deletions docs/api.md
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,10 +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()

- `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.
#### 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
11 changes: 8 additions & 3 deletions src/common/Browser.ts
Expand Up @@ -23,6 +23,7 @@ import { Protocol } from 'devtools-protocol';
import { Page } from './Page.js';
import { ChildProcess } from 'child_process';
import { Viewport } from './PuppeteerViewport.js';
import { BrowserContextOptions } from './BrowserContextOptions.js';

/**
* @internal
Expand Down Expand Up @@ -296,9 +297,13 @@ export class Browser extends EventEmitter {
* ```
*/
async createIncognitoBrowserContext(
proxyServer?: string,
proxyBypassList?: string
): Promise<BrowserContext> {
options: BrowserContextOptions = {}
): Promise<BrowserContext> {
const {
proxyServer = '',
proxyBypassList = '',
} = options;

const { browserContextId } = await this._connection.send(
'Target.createBrowserContext',
{
Expand Down
32 changes: 32 additions & 0 deletions src/common/BrowserContextOptions.ts
@@ -0,0 +1,32 @@
/**
* Copyright 2021 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

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

0 comments on commit 99de59e

Please sign in to comment.