feat: introduce browser.userAgent() (#1716)
The patch introduces browser.userAgent() method to retrieve default browser user agent. Fixes #1706.
This commit is contained in:
parent
05b1aca21e
commit
8e9c54a789
@ -24,6 +24,7 @@
|
|||||||
* [browser.pages()](#browserpages)
|
* [browser.pages()](#browserpages)
|
||||||
* [browser.process()](#browserprocess)
|
* [browser.process()](#browserprocess)
|
||||||
* [browser.targets()](#browsertargets)
|
* [browser.targets()](#browsertargets)
|
||||||
|
* [browser.userAgent()](#browseruseragent)
|
||||||
* [browser.version()](#browserversion)
|
* [browser.version()](#browserversion)
|
||||||
* [browser.wsEndpoint()](#browserwsendpoint)
|
* [browser.wsEndpoint()](#browserwsendpoint)
|
||||||
- [class: Page](#class-page)
|
- [class: Page](#class-page)
|
||||||
@ -362,6 +363,11 @@ Disconnects Puppeteer from the browser, but leaves the Chromium process running.
|
|||||||
#### browser.targets()
|
#### browser.targets()
|
||||||
- returns: <[Array]<[Target]>> An array of all active targets.
|
- returns: <[Array]<[Target]>> An array of all active targets.
|
||||||
|
|
||||||
|
#### browser.userAgent()
|
||||||
|
- returns: <[Promise]<[string]>> Promise which resolves to the browser's original user agent.
|
||||||
|
|
||||||
|
> **NOTE** Pages can override browser user agent with [page.setUserAgent](#pagesetuseragentuseragent)
|
||||||
|
|
||||||
#### browser.version()
|
#### browser.version()
|
||||||
- returns: <[Promise]<[string]>> For headless Chromium, this is similar to `HeadlessChrome/61.0.3153.0`. For non-headless, this is similar to `Chrome/61.0.3153.0`.
|
- returns: <[Promise]<[string]>> For headless Chromium, this is similar to `HeadlessChrome/61.0.3153.0`. For non-headless, this is similar to `Chrome/61.0.3153.0`.
|
||||||
|
|
||||||
|
@ -131,10 +131,18 @@ class Browser extends EventEmitter {
|
|||||||
* @return {!Promise<string>}
|
* @return {!Promise<string>}
|
||||||
*/
|
*/
|
||||||
async version() {
|
async version() {
|
||||||
const version = await this._connection.send('Browser.getVersion');
|
const version = await this._getVersion();
|
||||||
return version.product;
|
return version.product;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {!Promise<string>}
|
||||||
|
*/
|
||||||
|
async userAgent() {
|
||||||
|
const version = await this._getVersion();
|
||||||
|
return version.userAgent;
|
||||||
|
}
|
||||||
|
|
||||||
async close() {
|
async close() {
|
||||||
await this._closeCallback.call(null);
|
await this._closeCallback.call(null);
|
||||||
this.disconnect();
|
this.disconnect();
|
||||||
@ -143,6 +151,13 @@ class Browser extends EventEmitter {
|
|||||||
disconnect() {
|
disconnect() {
|
||||||
this._connection.dispose();
|
this._connection.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return {!Promise<!Object>}
|
||||||
|
*/
|
||||||
|
_getVersion() {
|
||||||
|
return this._connection.send('Browser.getVersion');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @enum {string} */
|
/** @enum {string} */
|
||||||
|
@ -273,6 +273,14 @@ describe('Page', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Browser.userAgent', function() {
|
||||||
|
it('should include WebKit', async({browser}) => {
|
||||||
|
const userAgent = await browser.userAgent();
|
||||||
|
expect(userAgent.length).toBeGreaterThan(0);
|
||||||
|
expect(userAgent).toContain('WebKit');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('Browser.process', function() {
|
describe('Browser.process', function() {
|
||||||
it('should return child_process instance', async function({browser}) {
|
it('should return child_process instance', async function({browser}) {
|
||||||
const process = await browser.process();
|
const process = await browser.process();
|
||||||
|
Loading…
Reference in New Issue
Block a user