mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
feat(page): expose page.client() (#7582)
Puppeteer already allows creating a new CDP session via target.createCDPSession but there is no way to get access to any existing session to send some additional commands.
This commit is contained in:
parent
2b5c0019dc
commit
99ca842124
@ -133,6 +133,7 @@
|
|||||||
* [page.browser()](#pagebrowser)
|
* [page.browser()](#pagebrowser)
|
||||||
* [page.browserContext()](#pagebrowsercontext)
|
* [page.browserContext()](#pagebrowsercontext)
|
||||||
* [page.click(selector[, options])](#pageclickselector-options)
|
* [page.click(selector[, options])](#pageclickselector-options)
|
||||||
|
* [page.client()](#pageclient)
|
||||||
* [page.close([options])](#pagecloseoptions)
|
* [page.close([options])](#pagecloseoptions)
|
||||||
* [page.content()](#pagecontent)
|
* [page.content()](#pagecontent)
|
||||||
* [page.cookies([...urls])](#pagecookiesurls)
|
* [page.cookies([...urls])](#pagecookiesurls)
|
||||||
@ -1465,6 +1466,12 @@ const [response] = await Promise.all([
|
|||||||
|
|
||||||
Shortcut for [page.mainFrame().click(selector[, options])](#frameclickselector-options).
|
Shortcut for [page.mainFrame().click(selector[, options])](#frameclickselector-options).
|
||||||
|
|
||||||
|
#### page.client()
|
||||||
|
|
||||||
|
- returns: <[CDPSession]>
|
||||||
|
|
||||||
|
Get the CDP session client the page belongs to.
|
||||||
|
|
||||||
#### page.close([options])
|
#### page.close([options])
|
||||||
|
|
||||||
- `options` <[Object]>
|
- `options` <[Object]>
|
||||||
|
@ -729,6 +729,13 @@ export class Page extends EventEmitter {
|
|||||||
return this._target;
|
return this._target;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the CDP session client the page belongs to.
|
||||||
|
*/
|
||||||
|
client(): CDPSession {
|
||||||
|
return this._client;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the browser the page belongs to.
|
* Get the browser the page belongs to.
|
||||||
*/
|
*/
|
||||||
|
@ -27,6 +27,7 @@ import {
|
|||||||
describeFailsFirefox,
|
describeFailsFirefox,
|
||||||
} from './mocha-utils'; // eslint-disable-line import/extensions
|
} from './mocha-utils'; // eslint-disable-line import/extensions
|
||||||
import { Page, Metrics } from '../lib/cjs/puppeteer/common/Page.js';
|
import { Page, Metrics } from '../lib/cjs/puppeteer/common/Page.js';
|
||||||
|
import { CDPSession } from '../lib/cjs/puppeteer/common/Connection.js';
|
||||||
import { JSHandle } from '../lib/cjs/puppeteer/common/JSHandle.js';
|
import { JSHandle } from '../lib/cjs/puppeteer/common/JSHandle.js';
|
||||||
|
|
||||||
describe('Page', function () {
|
describe('Page', function () {
|
||||||
@ -1902,4 +1903,11 @@ describe('Page', function () {
|
|||||||
expect(page.browserContext()).toBe(context);
|
expect(page.browserContext()).toBe(context);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Page.client', function () {
|
||||||
|
it('should return the client instance', async () => {
|
||||||
|
const { page } = getTestState();
|
||||||
|
expect(page.client()).toBeInstanceOf(CDPSession);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user