Don't use Emulation.resetPageScaleFactor (#147)

Instead of using Emulation.resetPageScaleFactor, this patch starts using clip's scale for
fullPage screenshots.
This commit is contained in:
Pavel Feldman 2017-07-26 15:28:44 -07:00 committed by Andrey Lushnikov
parent 5068185d03
commit 585f815548

View File

@ -400,11 +400,16 @@ class Page extends EventEmitter {
*/
async _screenshotTask(format, options) {
await this._client.send('Target.activateTarget', {targetId: this._client.targetId()});
let clip = options.clip ? Object.assign({}, options['clip']) : undefined;
if (clip)
clip.scale = 1;
if (options.fullPage) {
const metrics = await this._client.send('Page.getLayoutMetrics');
const width = Math.ceil(metrics.contentSize.width);
const height = Math.ceil(metrics.contentSize.height);
await this._client.send('Emulation.resetPageScaleFactor');
// Overwrite clip for full page at all times.
clip = { x: 0, y: 0, width, height, scale: 1 };
const mobile = this._viewport.isMobile || false;
const deviceScaleFactor = this._viewport.deviceScaleFactor || 1;
const landscape = this._viewport.isLandscape || false;
@ -412,9 +417,6 @@ class Page extends EventEmitter {
await this._client.send('Emulation.setDeviceMetricsOverride', { mobile, width, height, deviceScaleFactor, screenOrientation });
}
let clip = options.clip ? Object.assign({}, options['clip']) : undefined;
if (clip)
clip.scale = 1;
let result = await this._client.send('Page.captureScreenshot', { format, quality: options.quality, clip });
if (options.fullPage)