From 6c163122bf142599033378f6d158f0d9fd581500 Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Wed, 2 Aug 2017 15:47:00 -0700 Subject: [PATCH] Update default viewport size to be 800px by 600px (#194) This patch updates default viewport size to be 800px by 600px. This comes handy when observing scripts running in non-headless mode. --- README.md | 2 +- lib/Page.js | 2 +- phantom_shim/WebPage.js | 2 ++ test/test.js | 4 ++-- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0af3771b..d75fd06c 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ A few notes: 1. By default, Puppeteer bundles chromium browser with which it works best. However, you can point Puppeteer to a different executable ([example](https://github.com/GoogleChrome/puppeteer/blob/master/examples/custom-chromium-revision.js)) 2. Puppeteer creates its own Chromium user profile which it cleans up on every run. -3. Puppeteer sets an initial page size to 400px x 300px, which defines the screenshot size. The page size can be changed with `Page.setViewportSize()` method +3. Puppeteer sets an initial page size to 800px x 600px, which defines the screenshot size. The page size can be changed with `Page.setViewportSize()` method 4. By default, browser is launched in a headless mode. This could be changed via ['headless' browser option](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#new-browseroptions) ## API Documentation diff --git a/lib/Page.js b/lib/Page.js index f12c6795..89233f62 100644 --- a/lib/Page.js +++ b/lib/Page.js @@ -45,7 +45,7 @@ class Page extends EventEmitter { const page = new Page(client, ignoreHTTPSErrors, screenshotTaskQueue); await page.navigate('about:blank'); // Initialize default page size. - await page.setViewport({width: 400, height: 300}); + await page.setViewport({width: 800, height: 600}); return page; } diff --git a/phantom_shim/WebPage.js b/phantom_shim/WebPage.js index 51da61e0..ce55dbec 100644 --- a/phantom_shim/WebPage.js +++ b/phantom_shim/WebPage.js @@ -38,6 +38,8 @@ class WebPage { this.settings.userAgent = options.settings.userAgent; if (options.viewportSize) await(this._page.setViewport(options.viewportSize)); + else + await(this._page.setViewport({width: 400, height: 300})); this.loading = false; this.loadingProgress = 0; diff --git a/test/test.js b/test/test.js index 2b3a3a76..291a9fa1 100644 --- a/test/test.js +++ b/test/test.js @@ -1326,13 +1326,13 @@ describe('Page', function() { describe('Page.viewport', function() { it('should get the proper viewport size', SX(async function() { - expect(page.viewport()).toEqual({width: 400, height: 300}); + expect(page.viewport()).toEqual({width: 800, height: 600}); await page.setViewport({width: 123, height: 456}); expect(page.viewport()).toEqual({width: 123, height: 456}); })); it('should support mobile emulation', SX(async function() { await page.navigate(PREFIX + '/mobile.html'); - expect(await page.evaluate(() => window.innerWidth)).toBe(400); + expect(await page.evaluate(() => window.innerWidth)).toBe(800); await page.setViewport(iPhone.viewport); expect(await page.evaluate(() => window.innerWidth)).toBe(375); await page.setViewport({width: 400, height: 300});