mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
Rename page.size() and page.setSize() into page.viewportSize()
It turns page.size() and page.setSize() methods are slightly confusing since there multiple different sizes (layout size, content size, viewport size..) This patch renames Page.{size,setSize} methods into Page.{viewportSize,setViewportSize} methods to avoid confusion.
This commit is contained in:
parent
79ceb0c439
commit
ec414eb774
@ -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.
|
||||
|
@ -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('<html><body><canvas id="surface"></canvas></body></html>');
|
||||
await page.evaluate(drawColorWheel);
|
||||
await page.saveScreenshot('colorwheel.png');
|
||||
|
@ -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')
|
||||
]);
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user