Remove userAgent getter (#126)

If needed, the user agent could be fetched via querying
`navigator.userAgent` in page.

Closes #110
This commit is contained in:
JoelEinbinder 2017-07-25 02:01:10 -07:00 committed by Andrey Lushnikov
parent 615381c70e
commit 877f06aacb
5 changed files with 4 additions and 27 deletions

View File

@ -57,7 +57,6 @@
+ [page.type(text)](#pagetypetext)
+ [page.uploadFile(selector, ...filePaths)](#pageuploadfileselector-filepaths)
+ [page.url()](#pageurl)
+ [page.userAgent()](#pageuseragent)
+ [page.viewport()](#pageviewport)
+ [page.waitFor(target[, options])](#pagewaitfortarget-options)
+ [page.waitForNavigation(options)](#pagewaitfornavigationoptions)
@ -601,9 +600,6 @@ To press a special key, use [`page.press`](#pagepresskey-options).
This is a shortcut for [page.mainFrame().url()](#frameurl)
#### page.userAgent()
- returns: <[string]> Returns user agent.
#### page.viewport()
- returns: <[Object]> An object with the save fields as described in [page.setViewport](#pagesetviewportviewport)

View File

@ -19,16 +19,14 @@ const helper = require('./helper');
class NetworkManager extends EventEmitter {
/**
* @param {!Connection} client
* @param {string} userAgent
*/
constructor(client, userAgent) {
constructor(client) {
super();
this._client = client;
this._requestInterceptor = null;
/* @type {!Map<string, !Request>} */
this._idToRequest = new Map();
this._httpHeaders = {};
this._userAgent = userAgent;
this._client.on('Network.requestWillBeSent', this._onRequestWillBeSent.bind(this));
this._client.on('Network.requestIntercepted', this._onRequestIntercepted.bind(this));
@ -61,17 +59,9 @@ class NetworkManager extends EventEmitter {
* @return {!Promise}
*/
async setUserAgent(userAgent) {
this._userAgent = userAgent;
return this._client.send('Network.setUserAgentOverride', { userAgent });
}
/**
* @return {string}
*/
userAgent() {
return this._userAgent;
}
/**
* @param {?function(!InterceptedRequest)} interceptor
* @return {!Promise}

View File

@ -39,12 +39,10 @@ class Page extends EventEmitter {
client.send('Runtime.enable', {}),
client.send('Security.enable', {}),
]);
let userAgentExpression = helper.evaluationString(() => window.navigator.userAgent);
let {result:{value: userAgent}} = await client.send('Runtime.evaluate', { expression: userAgentExpression, returnByValue: true });
let keyboard = new Keyboard(client);
let mouse = new Mouse(client, keyboard);
let frameManager = await FrameManager.create(client, mouse);
let networkManager = new NetworkManager(client, userAgent);
let networkManager = new NetworkManager(client);
let page = new Page(client, frameManager, networkManager, screenshotTaskQueue, mouse, keyboard);
// Initialize default page size.
await page.setViewport({width: 400, height: 300});
@ -197,13 +195,6 @@ class Page extends EventEmitter {
return this._networkManager.setUserAgent(userAgent);
}
/**
* @return {string}
*/
userAgent() {
return this._networkManager.userAgent();
}
/**
* @param {!Object} exceptionDetails
*/

View File

@ -597,7 +597,7 @@ class WebPageSettings {
* @return {string}
*/
get userAgent() {
return this._page.userAgent();
return await(this._page.evaluate(() => window.navigator.userAgent));
}
}

View File

@ -988,7 +988,7 @@ describe('Puppeteer', function() {
describe('Page.setUserAgent', function() {
it('should work', SX(async function() {
expect(page.userAgent()).toContain('Mozilla');
expect(await page.evaluate(() => navigator.userAgent)).toContain('Mozilla');
page.setUserAgent('foobar');
page.navigate(EMPTY_PAGE);
let request = await server.waitForRequest('/empty.html');