From 96adedf54fae8faa237485c45b55881ac9e000c8 Mon Sep 17 00:00:00 2001 From: Joel Einbinder Date: Fri, 11 Jan 2019 15:24:43 -0800 Subject: [PATCH] fix(screenshots): throw on 0x0 screenshots (#3756) Fix #2672 --- lib/ExecutionContext.js | 2 ++ lib/Page.js | 2 ++ test/screenshot.spec.js | 7 ++++--- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/ExecutionContext.js b/lib/ExecutionContext.js index 4709b2e5..8b6ebcf5 100644 --- a/lib/ExecutionContext.js +++ b/lib/ExecutionContext.js @@ -504,6 +504,8 @@ class ElementHandle extends JSHandle { boundingBox = await this.boundingBox(); assert(boundingBox, 'Node is either not visible or not an HTMLElement'); + assert(boundingBox.width !== 0, 'Node has 0 width.'); + assert(boundingBox.height !== 0, 'Node has 0 height.'); const { layoutViewport: { pageX, pageY } } = await this._client.send('Page.getLayoutMetrics'); diff --git a/lib/Page.js b/lib/Page.js index 62b9064d..e0176e2e 100644 --- a/lib/Page.js +++ b/lib/Page.js @@ -841,6 +841,8 @@ class Page extends EventEmitter { assert(typeof options.clip.y === 'number', 'Expected options.clip.y to be a number but found ' + (typeof options.clip.y)); assert(typeof options.clip.width === 'number', 'Expected options.clip.width to be a number but found ' + (typeof options.clip.width)); assert(typeof options.clip.height === 'number', 'Expected options.clip.height to be a number but found ' + (typeof options.clip.height)); + assert(options.clip.width !== 0, 'Expected options.clip.width not to be 0.'); + assert(options.clip.height !== 0, 'Expected options.clip.width not to be 0.'); } return this._screenshotTaskQueue.postTask(this._screenshotTask.bind(this, screenshotType, options)); } diff --git a/test/screenshot.spec.js b/test/screenshot.spec.js index 58fffdbb..36fba459 100644 --- a/test/screenshot.spec.js +++ b/test/screenshot.spec.js @@ -218,10 +218,11 @@ module.exports.addTests = function({testRunner, expect, product}) { const screenshotError = await elementHandle.screenshot().catch(error => error); expect(screenshotError.message).toBe('Node is either not visible or not an HTMLElement'); }); - xit('should not hang with zero width/height element', async({page, server}) => { - await page.setContent('
'); + it('should not hang with zero width/height element', async({page, server}) => { + await page.setContent('
'); const div = await page.$('div'); - await div.screenshot(); + const error = await div.screenshot().catch(e => e); + expect(error.message).toBe('Node has 0 height.'); }); });