mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
fix(page): full page screenshot when defaultViewport is null (#3306)
Fixes #3104
This commit is contained in:
parent
e75e36b9c2
commit
842fee860b
15
lib/Page.js
15
lib/Page.js
@ -796,19 +796,20 @@ class Page extends EventEmitter {
|
||||
clip.scale = 1;
|
||||
|
||||
if (options.fullPage) {
|
||||
assert(this._viewport, 'fullPage screenshots do not work without first setting viewport.');
|
||||
const metrics = await this._client.send('Page.getLayoutMetrics');
|
||||
const width = Math.ceil(metrics.contentSize.width);
|
||||
const height = Math.ceil(metrics.contentSize.height);
|
||||
|
||||
// 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;
|
||||
const {
|
||||
isMobile = false,
|
||||
deviceScaleFactor = 1,
|
||||
isLandscape = false
|
||||
} = this._viewport || {};
|
||||
/** @type {!Protocol.Emulation.ScreenOrientation} */
|
||||
const screenOrientation = landscape ? { angle: 90, type: 'landscapePrimary' } : { angle: 0, type: 'portraitPrimary' };
|
||||
await this._client.send('Emulation.setDeviceMetricsOverride', { mobile, width, height, deviceScaleFactor, screenOrientation });
|
||||
const screenOrientation = isLandscape ? { angle: 90, type: 'landscapePrimary' } : { angle: 0, type: 'portraitPrimary' };
|
||||
await this._client.send('Emulation.setDeviceMetricsOverride', { mobile: isMobile, width, height, deviceScaleFactor, screenOrientation });
|
||||
}
|
||||
const shouldSetDefaultBackground = options.omitBackground && format === 'png';
|
||||
if (shouldSetDefaultBackground)
|
||||
@ -817,7 +818,7 @@ class Page extends EventEmitter {
|
||||
if (shouldSetDefaultBackground)
|
||||
await this._client.send('Emulation.setDefaultBackgroundColorOverride');
|
||||
|
||||
if (options.fullPage)
|
||||
if (options.fullPage && this._viewport)
|
||||
await this.setViewport(this._viewport);
|
||||
|
||||
const buffer = options.encoding === 'base64' ? result.data : Buffer.from(result.data, 'base64');
|
||||
|
@ -279,6 +279,19 @@ module.exports.addTests = function({testRunner, expect, defaultBrowserOptions})
|
||||
expect(page.viewport()).toBe(null);
|
||||
await browser.close();
|
||||
});
|
||||
it('should take fullPage screenshots when defaultViewport is null', async({server}) => {
|
||||
const options = Object.assign({}, defaultBrowserOptions, {
|
||||
defaultViewport: null
|
||||
});
|
||||
const browser = await puppeteer.launch(options);
|
||||
const page = await browser.newPage();
|
||||
await page.goto(server.PREFIX + '/grid.html');
|
||||
const screenshot = await page.screenshot({
|
||||
fullPage: true
|
||||
});
|
||||
expect(screenshot).toBeInstanceOf(Buffer);
|
||||
await browser.close();
|
||||
});
|
||||
});
|
||||
describe('Puppeteer.connect', function() {
|
||||
it('should be able to connect multiple times to the same browser', async({server}) => {
|
||||
|
Loading…
Reference in New Issue
Block a user