Skip to content

Commit

Permalink
fix(firefox): properly round clip when doing element screenshots (#4001)
Browse files Browse the repository at this point in the history
Do clipping the same way we do it in Chromium.
  • Loading branch information
aslushnikov committed Feb 14, 2019
1 parent 670d758 commit 2275c3c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
8 changes: 4 additions & 4 deletions experimental/puppeteer-firefox/lib/JSHandle.js
Expand Up @@ -169,10 +169,10 @@ class ElementHandle extends JSHandle {

return await this._frame._page.screenshot(Object.assign({}, options, {
clip: {
x: Math.round(clip.x),
y: Math.round(clip.y),
width: Math.round(clip.width),
height: Math.round(clip.height),
x: clip.x,
y: clip.y,
width: clip.width,
height: clip.height,
},
}));
}
Expand Down
12 changes: 11 additions & 1 deletion experimental/puppeteer-firefox/lib/Page.js
Expand Up @@ -379,12 +379,22 @@ class Page extends EventEmitter {
const {data} = await this._session.send('Page.screenshot', {
mimeType: getScreenshotMimeType(options),
fullPage: options.fullPage,
clip: options.clip,
clip: processClip(options.clip),
});
const buffer = options.encoding === 'base64' ? data : Buffer.from(data, 'base64');
if (options.path)
await writeFileAsync(options.path, buffer);
return buffer;

function processClip(clip) {
if (!clip)
return undefined;
const x = Math.round(clip.x);
const y = Math.round(clip.y);
const width = Math.round(clip.width + clip.x - x);
const height = Math.round(clip.height + clip.y - y);
return {x, y, width, height};
}
}

async evaluate(pageFunction, ...args) {
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions test/puppeteer.spec.js
Expand Up @@ -23,8 +23,8 @@ const YELLOW_COLOR = '\x1b[33m';
const RESET_COLOR = '\x1b[0m';

module.exports.addTests = ({testRunner, product, puppeteer, Errors, DeviceDescriptors}) => {
const {describe, xdescribe, fdescribe, describe_fails_ffox} = testRunner;
const {it, fit, xit, it_fails_ffox} = testRunner;
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;

const CHROME = product === 'Chromium';
Expand Down
4 changes: 2 additions & 2 deletions test/screenshot.spec.js
Expand Up @@ -15,7 +15,7 @@
*/

module.exports.addTests = function({testRunner, expect, product}) {
const {describe, xdescribe, fdescribe, describe_fails_ffox} = testRunner;
const {describe, xdescribe, fdescribe} = testRunner;
const {it, fit, xit, it_fails_ffox} = testRunner;
const {beforeAll, beforeEach, afterAll, afterEach} = testRunner;

Expand Down Expand Up @@ -230,7 +230,7 @@ module.exports.addTests = function({testRunner, expect, product}) {
const screenshot = await elementHandle.screenshot();
expect(screenshot).toBeGolden('screenshot-element-fractional.png');
});
it_fails_ffox('should work for an element with an offset', async({page}) => {
it('should work for an element with an offset', async({page}) => {
await page.setContent('<div style="position:absolute; top: 10.3px; left: 20.4px;width:50.3px;height:20.2px;border:1px solid black;"></div>');
const elementHandle = await page.$('div');
const screenshot = await elementHandle.screenshot();
Expand Down

0 comments on commit 2275c3c

Please sign in to comment.