Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(screenshots): throw on 0x0 screenshots #3756

Merged
merged 1 commit into from
Jan 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/ExecutionContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
2 changes: 2 additions & 0 deletions lib/Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,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));
}
Expand Down
7 changes: 4 additions & 3 deletions test/screenshot.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('<div style="width: 0; height: 0"></div>');
it('should not hang with zero width/height element', async({page, server}) => {
await page.setContent('<div style="width: 50px; height: 0"></div>');
const div = await page.$('div');
await div.screenshot();
const error = await div.screenshot().catch(e => e);
expect(error.message).toBe('Node has 0 height.');
});
});

Expand Down