mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
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.process()](#browserprocess)
|
||||
* [browser.targets()](#browsertargets)
|
||||
* [browser.userAgent()](#browseruseragent)
|
||||
* [browser.version()](#browserversion)
|
||||
* [browser.wsEndpoint()](#browserwsendpoint)
|
||||
- [class: Page](#class-page)
|
||||
@ -362,6 +363,11 @@ Disconnects Puppeteer from the browser, but leaves the Chromium process running.
|
||||
#### browser.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()
|
||||
- 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>}
|
||||
*/
|
||||
async version() {
|
||||
const version = await this._connection.send('Browser.getVersion');
|
||||
const version = await this._getVersion();
|
||||
return version.product;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {!Promise<string>}
|
||||
*/
|
||||
async userAgent() {
|
||||
const version = await this._getVersion();
|
||||
return version.userAgent;
|
||||
}
|
||||
|
||||
async close() {
|
||||
await this._closeCallback.call(null);
|
||||
this.disconnect();
|
||||
@ -143,6 +151,13 @@ class Browser extends EventEmitter {
|
||||
disconnect() {
|
||||
this._connection.dispose();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {!Promise<!Object>}
|
||||
*/
|
||||
_getVersion() {
|
||||
return this._connection.send('Browser.getVersion');
|
||||
}
|
||||
}
|
||||
|
||||
/** @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() {
|
||||
it('should return child_process instance', async function({browser}) {
|
||||
const process = await browser.process();
|
||||
|
Loading…
Reference in New Issue
Block a user