Get rid of page.emulate() / page.emulatedDevices() methods

This patch:
- gets rid of `page.emulate` and `page.emulatedDevices`
  methods. Instead, it is suggested to use `page.setViewport()`
  and `page.setUserAgent()` methods.
- moves DeviceDescriptors to the top level of the puppeteer so that
  it is convenient to require them.
- improves on documentation to describe the suggested emulation
  approach.

References #88.
This commit is contained in:
Andrey Lushnikov
2017-07-20 18:14:43 -07:00
parent 76ac3bded5
commit 139b9e9b6d
5 changed files with 197 additions and 199 deletions

View File

@@ -14,38 +14,7 @@
* limitations under the License.
*/
const DeviceDescriptors = require('./DeviceDescriptors');
class EmulationManager {
/**
* @return {!Promise<!Array<string>>}
*/
static deviceNames() {
return Promise.resolve(DeviceDescriptors.map(device => device.name));
}
/**
* @param {string} name
* @param {!Object=} options
* @return {!Page.Viewport}
*/
static deviceViewport(name) {
const device = DeviceDescriptors.find(device => device.name === name);
if (!device)
throw new Error(`Unable to emulate ${name}, no such device metrics in the library.`);
return device.viewport;
}
/**
* @param {string} name
*/
static deviceUserAgent(name) {
const device = DeviceDescriptors.find(device => device.name === name);
if (!device)
throw new Error(`Unable to emulate ${name}, no such device metrics in the library.`);
return device.userAgent;
}
/**
* @param {!Connection} client
* @param {!Page.Viewport} viewport