mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user