Skip to content

Commit

Permalink
api(cdp): rename createSession to newCDPSession (#1378)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelfeldman authored Mar 13, 2020
1 parent b1a3b23 commit 8aba111
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
10 changes: 5 additions & 5 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -3721,7 +3721,7 @@ await browser.stopTracing();
```

<!-- GEN:toc -->
- [chromiumBrowser.createBrowserSession()](#chromiumbrowsercreatebrowsersession)
- [chromiumBrowser.newBrowserCDPSession()](#chromiumbrowsernewbrowsercdpsession)
- [chromiumBrowser.startTracing([page, options])](#chromiumbrowserstarttracingpage-options)
- [chromiumBrowser.stopTracing()](#chromiumbrowserstoptracing)
<!-- GEN:stop -->
Expand All @@ -3734,7 +3734,7 @@ await browser.stopTracing();
- [browser.newPage([options])](#browsernewpageoptions)
<!-- GEN:stop -->

#### chromiumBrowser.createBrowserSession()
#### chromiumBrowser.newBrowserCDPSession()
- returns: <[Promise]<[ChromiumSession]>> Promise that resolves to the newly created browser
session.

Expand Down Expand Up @@ -3766,7 +3766,7 @@ const backgroundPage = await backroundPageTarget.page();
- [event: 'backgroundpage'](#event-backgroundpage)
- [event: 'serviceworker'](#event-serviceworker)
- [chromiumBrowserContext.backgroundPages()](#chromiumbrowsercontextbackgroundpages)
- [chromiumBrowserContext.createSession(page)](#chromiumbrowsercontextcreatesessionpage)
- [chromiumBrowserContext.newCDPSession(page)](#chromiumbrowsercontextnewcdpsessionpage)
<!-- GEN:stop -->
<!-- GEN:toc-extends-BrowserContext -->
- [event: 'close'](#event-close)
Expand Down Expand Up @@ -3806,7 +3806,7 @@ Emitted when new service worker is created in the context.
#### chromiumBrowserContext.backgroundPages()
- returns: <[Promise]<[Array]<[Page]>>> Promise which resolves to an array of all existing background pages in the context.

#### chromiumBrowserContext.createSession(page)
#### chromiumBrowserContext.newCDPSession(page)
- `page` <[Page]> Page to create new session for.
- returns: <[Promise]<[ChromiumSession]>> Promise that resolves to the newly created session.

Expand Down Expand Up @@ -3888,7 +3888,7 @@ Useful links:
- Getting Started with DevTools Protocol: https://github.com/aslushnikov/getting-started-with-cdp/blob/master/README.md

```js
const client = await page.context().createSession(page);
const client = await page.context().newCDPSession(page);
await client.send('Animation.enable');
client.on('Animation.animationCreated', () => console.log('Animation created!'));
const response = await client.send('Animation.getPlaybackRate');
Expand Down
4 changes: 2 additions & 2 deletions src/chromium/crBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export class CRBrowser extends platform.EventEmitter implements Browser {
await disconnected;
}

async createBrowserSession(): Promise<CRSession> {
async newBrowserCDPSession(): Promise<CRSession> {
return await this._connection.createBrowserSession();
}

Expand Down Expand Up @@ -419,7 +419,7 @@ export class CRBrowserContext extends BrowserContextBase {
return pages.filter(page => (page instanceof Page) && !page.isClosed()) as Page[];
}

async createSession(page: Page): Promise<CRSession> {
async newCDPSession(page: Page): Promise<CRSession> {
const targetId = CRTarget.fromPage(page)._targetId;
const rootSession = await this._browser._clientRootSession();
const { sessionId } = await rootSession.send('Target.attachToTarget', { targetId, flatten: true });
Expand Down
4 changes: 2 additions & 2 deletions test/chromium/launcher.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ module.exports.describe = function({testRunner, expect, defaultBrowserOptions, b
it('should open devtools when "devtools: true" option is given', async({server}) => {
const browser = await browserType.launch(Object.assign({devtools: true}, headfulOptions));
const context = await browser.newContext();
const browserSession = await browser.createBrowserSession();
const browserSession = await browser.newBrowserCDPSession();
await browserSession.send('Target.setDiscoverTargets', { discover: true });
const devtoolsPagePromise = new Promise(fulfill => browserSession.on('Target.targetCreated', async ({targetInfo}) => {
if (targetInfo.type === 'other' && targetInfo.url.includes('devtools://'))
Expand Down Expand Up @@ -124,7 +124,7 @@ module.exports.describe = function({testRunner, expect, defaultBrowserOptions, b
describe('BrowserContext', function() {
it('should not create pages automatically', async function() {
const browser = await browserType.launch();
const browserSession = await browser.createBrowserSession();
const browserSession = await browser.newBrowserCDPSession();
const targets = [];
browserSession.on('Target.targetCreated', async ({targetInfo}) => {
if (targetInfo.type !== 'browser')
Expand Down
2 changes: 1 addition & 1 deletion test/chromium/oopif.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ module.exports.describe = function({testRunner, expect, defaultBrowserOptions, b
};

async function countOOPIFs(browser) {
const browserSession = await browser.createBrowserSession();
const browserSession = await browser.newBrowserCDPSession();
const oopifs = [];
browserSession.on('Target.targetCreated', async ({targetInfo}) => {
if (targetInfo.type === 'iframe')
Expand Down
18 changes: 9 additions & 9 deletions test/chromium/session.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports.describe = function({testRunner, expect, FFOX, CHROMIUM, WEBKIT})

describe('ChromiumBrowserContext.createSession', function() {
it('should work', async function({page, browser, server}) {
const client = await page.context().createSession(page);
const client = await page.context().newCDPSession(page);

await Promise.all([
client.send('Runtime.enable'),
Expand All @@ -36,15 +36,15 @@ module.exports.describe = function({testRunner, expect, FFOX, CHROMIUM, WEBKIT})
expect(foo).toBe('bar');
});
it('should send events', async function({page, browser, server}) {
const client = await page.context().createSession(page);
const client = await page.context().newCDPSession(page);
await client.send('Network.enable');
const events = [];
client.on('Network.requestWillBeSent', event => events.push(event));
await page.goto(server.EMPTY_PAGE);
expect(events.length).toBe(1);
});
it('should enable and disable domains independently', async function({page, browser, server}) {
const client = await page.context().createSession(page);
const client = await page.context().newCDPSession(page);
await client.send('Runtime.enable');
await client.send('Debugger.enable');
// JS coverage enables and then disables Debugger domain.
Expand All @@ -59,7 +59,7 @@ module.exports.describe = function({testRunner, expect, FFOX, CHROMIUM, WEBKIT})
expect(event.url).toBe('foo.js');
});
it('should be able to detach session', async function({page, browser, server}) {
const client = await page.context().createSession(page);
const client = await page.context().newCDPSession(page);
await client.send('Runtime.enable');
const evalResponse = await client.send('Runtime.evaluate', {expression: '1 + 2', returnByValue: true});
expect(evalResponse.result.value).toBe(3);
Expand All @@ -73,7 +73,7 @@ module.exports.describe = function({testRunner, expect, FFOX, CHROMIUM, WEBKIT})
expect(error.message).toContain('Session closed.');
});
it('should throw nice errors', async function({page, browser}) {
const client = await page.context().createSession(page);
const client = await page.context().newCDPSession(page);
const error = await theSourceOfTheProblems().catch(error => error);
expect(error.stack).toContain('theSourceOfTheProblems');
expect(error.message).toContain('ThisCommand.DoesNotExist');
Expand All @@ -85,25 +85,25 @@ module.exports.describe = function({testRunner, expect, FFOX, CHROMIUM, WEBKIT})
it('should not break page.close()', async function({browser, server}) {
const context = await browser.newContext();
const page = await context.newPage();
const session = await page.context().createSession(page);
const session = await page.context().newCDPSession(page);
await session.detach();
await page.close();
await context.close();
});
it('should detach when page closes', async function({browser, server}) {
const context = await browser.newContext();
const page = await context.newPage();
const session = await context.createSession(page);
const session = await context.newCDPSession(page);
await page.close();
let error;
await session.detach().catch(e => error = e);
expect(error).toBeTruthy('Calling detach on a closed page\'s session should throw');
await context.close();
});
});
describe('ChromiumBrowser.createBrowserSession', function() {
describe('ChromiumBrowser.newBrowserCDPSession', function() {
it('should work', async function({page, browser, server}) {
const session = await browser.createBrowserSession();
const session = await browser.newBrowserCDPSession();
const version = await session.send('Browser.getVersion');
expect(version.userAgent).toBeTruthy();
await session.detach();
Expand Down

0 comments on commit 8aba111

Please sign in to comment.