diff --git a/docs/api.md b/docs/api.md index bfea91b9..7564e251 100644 --- a/docs/api.md +++ b/docs/api.md @@ -19,8 +19,8 @@ - [page.url()](#pageurl) - [page.setContent(html)](#pagesetcontenthtml) - [page.navigate(url)](#pagenavigateurl) - - [page.setSize(size)](#pagesetsizesize) - - [page.size()](#pagesize) + - [page.setViewportSize(size)](#pagesetsizesize) + - [page.viewportSize()](#pagesize) - [page.evaluate(fun, args)](#pageevaluatefun-args) - [page.evaluateAsync(fun, args)](#pageevaluateasyncfun-args) - [page.evaluateOnInitialized(fun, args)](#pageevaluateoninitializedfun-args) @@ -136,14 +136,14 @@ Pages could be closed by `page.close()` method. - `true` if the navigation succeeds and page's `load` event is fired. - `false` if the navigation fails due to bad URL or SSL errors. -#### page.setSize(size) +#### page.setViewportSize(size) - `size` [<Object>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) An object with two fields: - `width` [<number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) Specify page's width in pixels. - `height` [<number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) Specify page's height in pixels. - returns: [<Promise>](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise) Promise which resolves when the dimensions are updated. -#### page.size() +#### page.viewportSize() - returns: [<Object>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) An object with two fields: - `width` [<number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) Page's width in pixels. diff --git a/examples/colorwheel.js b/examples/colorwheel.js index cbc71347..c9bade3a 100644 --- a/examples/colorwheel.js +++ b/examples/colorwheel.js @@ -18,7 +18,7 @@ var Browser = require('../lib/Browser'); var browser = new Browser(); browser.newPage().then(async page => { - await page.setSize({width: 400, height: 400}); + await page.setViewportSize({width: 400, height: 400}); await page.setContent(''); await page.evaluate(drawColorWheel); await page.saveScreenshot('colorwheel.png'); diff --git a/lib/Page.js b/lib/Page.js index d93030b8..9511e191 100644 --- a/lib/Page.js +++ b/lib/Page.js @@ -35,7 +35,7 @@ class Page extends EventEmitter { var screenDPI = await helpers.evaluate(client, () => window.devicePixelRatio, []); var page = new Page(browser, client, screenDPI.result.value); // Initialize default page size. - await page.setSize({width: 400, height: 300}); + await page.setViewportSize({width: 400, height: 300}); return page; } @@ -285,7 +285,7 @@ class Page extends EventEmitter { * @param {!{width: number, height: number}} size * @return {!Promise} */ - async setSize(size) { + async setViewportSize(size) { this._size = size; var width = size.width; var height = size.height; @@ -309,7 +309,7 @@ class Page extends EventEmitter { /** * @return {!{width: number, height: number}} */ - size() { + viewportSize() { return this._size; } @@ -378,7 +378,7 @@ class Page extends EventEmitter { }); if (clipRect) { await Promise.all([ - this.setSize(this.size()), + this.setViewportSize(this.viewportSize()), this._client.send('Emulation.resetViewport') ]); } diff --git a/phantom_shim/WebPage.js b/phantom_shim/WebPage.js index 38662f85..5b77cb73 100644 --- a/phantom_shim/WebPage.js +++ b/phantom_shim/WebPage.js @@ -37,7 +37,7 @@ class WebPage { if (options.settings.userAgent) this.settings.userAgent = options.settings.userAgent; if (options.viewportSize) - await(this._page.setSize(options.viewportSize)); + await(this._page.setViewportSize(options.viewportSize)); await(this._page.setInPageCallback('callPhantom', (...args) => this.onCallback.apply(null, args))); @@ -91,7 +91,7 @@ class WebPage { * @return {!{width: number, height: number}} */ get viewportSize() { - return this._page.size(); + return this._page.viewportSize(); } /** @@ -245,7 +245,7 @@ class WebPage { * @param {!{width: number, height: number}} options */ set viewportSize(options) { - await(this._page.setSize(options)); + await(this._page.setViewportSize(options)); } /**