From c7cf4886ea0a5d0bbfc1b4a605afeca0888e2b50 Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Thu, 12 Dec 2019 20:14:00 -0800 Subject: [PATCH] api: s/createIncognitoBrowserContext/newContext/ --- docs/api.md | 10 +++++----- src/browserContext.ts | 2 +- src/chromium/Browser.ts | 2 +- src/firefox/Browser.ts | 2 +- src/webkit/Browser.ts | 4 ++-- test/browsercontext.spec.js | 10 +++++----- test/chromium/chromium.spec.js | 8 ++++---- test/chromium/headful.spec.js | 2 +- test/chromium/oopif.spec.js | 2 +- test/cookies.spec.js | 4 ++-- test/features/permissions.spec.js | 2 +- test/ignorehttpserrors.spec.js | 2 +- test/playwright.spec.js | 2 +- 13 files changed, 26 insertions(+), 26 deletions(-) diff --git a/docs/api.md b/docs/api.md index 07d8e776f1..565c5f6019 100644 --- a/docs/api.md +++ b/docs/api.md @@ -32,7 +32,7 @@ * [browser.browserContexts()](#browserbrowsercontexts) * [browser.chromium](#browserchromium) * [browser.close()](#browserclose) - * [browser.createIncognitoBrowserContext()](#browsercreateincognitobrowsercontext) + * [browser.newContext()](#browsernewcontext) * [browser.defaultBrowserContext()](#browserdefaultbrowsercontext) * [browser.disconnect()](#browserdisconnect) * [browser.isConnected()](#browserisconnected) @@ -625,7 +625,7 @@ a single instance of [BrowserContext]. Closes Chromium and all of its pages (if any were opened). The [Browser] object itself is considered to be disposed and cannot be used anymore. -#### browser.createIncognitoBrowserContext() +#### browser.newContext() - returns: <[Promise]<[BrowserContext]>> Creates a new incognito browser context. This won't share cookies/cache with other browser contexts. @@ -634,7 +634,7 @@ Creates a new incognito browser context. This won't share cookies/cache with oth (async () => { const browser = await playwright.launch(); // Create a new incognito browser context. - const context = await browser.createIncognitoBrowserContext(); + const context = await browser.newContext(); // Create a new page in a pristine context. const page = await context.newPage(); // Do stuff @@ -691,12 +691,12 @@ a single BrowserContext used by default. The method `browser.newPage()` creates If a page opens another page, e.g. with a `window.open` call, the popup will belong to the parent page's browser context. -Playwright allows creation of "incognito" browser contexts with `browser.createIncognitoBrowserContext()` method. +Playwright allows creation of "incognito" browser contexts with `browser.newContext()` method. "Incognito" browser contexts don't write any browsing data to disk. ```js // Create a new incognito browser context -const context = await browser.createIncognitoBrowserContext(); +const context = await browser.newContext(); // Create a new page inside context. const page = await context.newPage(); // ... do stuff with page ... diff --git a/src/browserContext.ts b/src/browserContext.ts index 2145849c65..07b8432b2d 100644 --- a/src/browserContext.ts +++ b/src/browserContext.ts @@ -23,7 +23,7 @@ import * as childProcess from 'child_process'; export interface BrowserInterface { browserContexts(): BrowserContext[]; close(): Promise; - createIncognitoBrowserContext(): Promise; + newContext(): Promise; defaultBrowserContext(): BrowserContext; newPage(): Promise; pages(): Promise; diff --git a/src/chromium/Browser.ts b/src/chromium/Browser.ts index 7244eaf833..b028183d1b 100644 --- a/src/chromium/Browser.ts +++ b/src/chromium/Browser.ts @@ -127,7 +127,7 @@ export class Browser extends EventEmitter implements BrowserInterface { return this._process; } - async createIncognitoBrowserContext(): Promise { + async newContext(): Promise { const {browserContextId} = await this._client.send('Target.createBrowserContext'); const context = this._createBrowserContext(browserContextId); this._contexts.set(browserContextId, context); diff --git a/src/firefox/Browser.ts b/src/firefox/Browser.ts index 92df635f6f..a5dc691438 100644 --- a/src/firefox/Browser.ts +++ b/src/firefox/Browser.ts @@ -78,7 +78,7 @@ export class Browser extends EventEmitter implements BrowserInterface { return !this._connection._closed; } - async createIncognitoBrowserContext(): Promise { + async newContext(): Promise { const {browserContextId} = await this._connection.send('Target.createBrowserContext'); const context = this._createBrowserContext(browserContextId); this._contexts.set(browserContextId, context); diff --git a/src/webkit/Browser.ts b/src/webkit/Browser.ts index cc3678e922..7d33f74aa3 100644 --- a/src/webkit/Browser.ts +++ b/src/webkit/Browser.ts @@ -70,7 +70,7 @@ export class Browser extends EventEmitter implements BrowserInterface { } async userAgent(): Promise { - const context = await this.createIncognitoBrowserContext(); + const context = await this.newContext(); const page = await context.newPage(); const userAgent = await page.evaluate(() => navigator.userAgent); context.close(); @@ -86,7 +86,7 @@ export class Browser extends EventEmitter implements BrowserInterface { return this._process; } - async createIncognitoBrowserContext(): Promise { + async newContext(): Promise { const {browserContextId} = await this._connection.send('Browser.createContext'); const context = this._createBrowserContext(browserContextId); this._contexts.set(browserContextId, context); diff --git a/test/browsercontext.spec.js b/test/browsercontext.spec.js index 491a8ef0ba..e1252202e2 100644 --- a/test/browsercontext.spec.js +++ b/test/browsercontext.spec.js @@ -34,7 +34,7 @@ module.exports.addTests = function({testRunner, expect}) { }); it('should create new incognito context', async function({browser, server}) { expect(browser.browserContexts().length).toBe(1); - const context = await browser.createIncognitoBrowserContext(); + const context = await browser.newContext(); expect(context.isIncognito()).toBe(true); expect(browser.browserContexts().length).toBe(2); expect(browser.browserContexts().indexOf(context) !== -1).toBe(true); @@ -44,7 +44,7 @@ module.exports.addTests = function({testRunner, expect}) { it('should close all belonging targets once closing context', async function({browser, server}) { expect((await browser.pages()).length).toBe(1); - const context = await browser.createIncognitoBrowserContext(); + const context = await browser.newContext(); await context.newPage(); expect((await browser.pages()).length).toBe(2); expect((await context.pages()).length).toBe(1); @@ -53,7 +53,7 @@ module.exports.addTests = function({testRunner, expect}) { expect((await browser.pages()).length).toBe(1); }); it('window.open should use parent tab context', async function({browser, server}) { - const context = await browser.createIncognitoBrowserContext(); + const context = await browser.newContext(); const page = await context.newPage(); await page.goto(server.EMPTY_PAGE); const [popupTarget] = await Promise.all([ @@ -65,8 +65,8 @@ module.exports.addTests = function({testRunner, expect}) { }); it('should isolate localStorage and cookies', async function({browser, server}) { // Create two incognito contexts. - const context1 = await browser.createIncognitoBrowserContext(); - const context2 = await browser.createIncognitoBrowserContext(); + const context1 = await browser.newContext(); + const context2 = await browser.newContext(); expect((await context1.pages()).length).toBe(0); expect((await context2.pages()).length).toBe(0); diff --git a/test/chromium/chromium.spec.js b/test/chromium/chromium.spec.js index 1a2f66f52e..0459f583a1 100644 --- a/test/chromium/chromium.spec.js +++ b/test/chromium/chromium.spec.js @@ -24,7 +24,7 @@ module.exports.addTests = function({testRunner, expect, playwright, FFOX, CHROME describe('Chromium', function() { it('should work across sessions', async function({browser, server}) { expect(browser.browserContexts().length).toBe(2); - const context = await browser.createIncognitoBrowserContext(); + const context = await browser.newContext(); expect(browser.browserContexts().length).toBe(3); const remoteBrowser = await playwright.connect({ browserWSEndpoint: browser.chromium.wsEndpoint() @@ -175,7 +175,7 @@ module.exports.addTests = function({testRunner, expect, playwright, FFOX, CHROME describe('Chromium.waitForTarget', () => { it('should wait for a target', async function({browser, server}) { - const context = await browser.createIncognitoBrowserContext(); + const context = await browser.newContext(); let resolved = false; const targetPromise = browser.chromium.waitForTarget(target => target.browserContext() === context && target.url() === server.EMPTY_PAGE); targetPromise.then(() => resolved = true); @@ -187,7 +187,7 @@ module.exports.addTests = function({testRunner, expect, playwright, FFOX, CHROME await context.close(); }); it('should timeout waiting for a non-existent target', async function({browser, server}) { - const context = await browser.createIncognitoBrowserContext(); + const context = await browser.newContext(); const error = await browser.chromium.waitForTarget(target => target.browserContext() === context && target.url() === server.EMPTY_PAGE, {timeout: 1}).catch(e => e); expect(error).toBeInstanceOf(playwright.errors.TimeoutError); await context.close(); @@ -211,7 +211,7 @@ module.exports.addTests = function({testRunner, expect, playwright, FFOX, CHROME expect(error).toBeInstanceOf(playwright.errors.TimeoutError); }); it('should fire target events', async function({browser, server}) { - const context = await browser.createIncognitoBrowserContext(); + const context = await browser.newContext(); const events = []; browser.chromium.on('targetcreated', target => events.push('CREATED: ' + target.url())); browser.chromium.on('targetchanged', target => events.push('CHANGED: ' + target.url())); diff --git a/test/chromium/headful.spec.js b/test/chromium/headful.spec.js index a76fb97e9f..649602cac1 100644 --- a/test/chromium/headful.spec.js +++ b/test/chromium/headful.spec.js @@ -118,7 +118,7 @@ module.exports.addTests = function({testRunner, expect, playwright, defaultBrows }); it('should open devtools when "devtools: true" option is given', async({server}) => { const browser = await playwright.launch(Object.assign({devtools: true}, headfulOptions)); - const context = await browser.createIncognitoBrowserContext(); + const context = await browser.newContext(); await Promise.all([ context.newPage(), browser.chromium.waitForTarget(target => target.browserContext() === context && target.url().includes('devtools://')), diff --git a/test/chromium/oopif.spec.js b/test/chromium/oopif.spec.js index 97ba5eff42..08e3b68386 100644 --- a/test/chromium/oopif.spec.js +++ b/test/chromium/oopif.spec.js @@ -26,7 +26,7 @@ module.exports.addTests = function({testRunner, expect, defaultBrowserOptions, p })); }); beforeEach(async function(state) { - state.context = await state.browser.createIncognitoBrowserContext(); + state.context = await state.browser.newContext(); state.page = await state.context.newPage(); }); afterEach(async function(state) { diff --git a/test/cookies.spec.js b/test/cookies.spec.js index ea14fb9d8b..5db5bbee75 100644 --- a/test/cookies.spec.js +++ b/test/cookies.spec.js @@ -155,7 +155,7 @@ module.exports.addTests = function({testRunner, expect, FFOX, CHROME, WEBKIT}) { expect(await page.evaluate(() => document.cookie)).toEqual('password=123456'); }); it('should isolate cookies in browser contexts', async({context, server, browser}) => { - const anotherContext = await browser.createIncognitoBrowserContext(); + const anotherContext = await browser.newContext(); await context.setCookies([{url: server.EMPTY_PAGE, name: 'page1cookie', value: 'page1value'}]); await anotherContext.setCookies([{url: server.EMPTY_PAGE, name: 'page2cookie', value: 'page2value'}]); @@ -365,7 +365,7 @@ module.exports.addTests = function({testRunner, expect, FFOX, CHROME, WEBKIT}) { expect(await page.evaluate('document.cookie')).toBe(''); }); it('should isolate cookies when clearing', async({context, server, browser}) => { - const anotherContext = await browser.createIncognitoBrowserContext(); + const anotherContext = await browser.newContext(); await context.setCookies([{url: server.EMPTY_PAGE, name: 'page1cookie', value: 'page1value'}]); await anotherContext.setCookies([{url: server.EMPTY_PAGE, name: 'page2cookie', value: 'page2value'}]); diff --git a/test/features/permissions.spec.js b/test/features/permissions.spec.js index c2a29d4eda..738809b2dc 100644 --- a/test/features/permissions.spec.js +++ b/test/features/permissions.spec.js @@ -77,7 +77,7 @@ module.exports.addTests = function({testRunner, expect, WEBKIT}) { }); it.skip(WEBKIT)('should isolate permissions between browser contexs', async({page, server, context, browser}) => { await page.goto(server.EMPTY_PAGE); - const otherContext = await browser.createIncognitoBrowserContext(); + const otherContext = await browser.newContext(); const otherPage = await otherContext.newPage(); await otherPage.goto(server.EMPTY_PAGE); expect(await getPermission(page, 'geolocation')).toBe('prompt'); diff --git a/test/ignorehttpserrors.spec.js b/test/ignorehttpserrors.spec.js index 5adb6faac0..d929de2ab3 100644 --- a/test/ignorehttpserrors.spec.js +++ b/test/ignorehttpserrors.spec.js @@ -28,7 +28,7 @@ module.exports.addTests = function({testRunner, expect, defaultBrowserOptions, p delete state.browser; }); beforeEach(async state => { - state.context = await state.browser.createIncognitoBrowserContext(); + state.context = await state.browser.newContext(); state.page = await state.context.newPage(); }); afterEach(async state => { diff --git a/test/playwright.spec.js b/test/playwright.spec.js index 5377ca4791..610fe3884d 100644 --- a/test/playwright.spec.js +++ b/test/playwright.spec.js @@ -126,7 +126,7 @@ module.exports.addTests = ({testRunner, product, playwrightPath}) => { describe('Page', function() { beforeEach(async state => { - state.context = await state.browser.createIncognitoBrowserContext(); + state.context = await state.browser.newContext(); state.page = await state.context.newPage(); });