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

Allow capturing transparent screenshots #354

Merged
merged 5 commits into from Aug 18, 2017

Conversation

pavelfeldman
Copy link
Contributor

No description provided.

lib/Page.js Outdated
let result = await this._client.send('Page.captureScreenshot', { format, quality: options.quality, clip });
if (options.noBackground)
await this._client.send('Emulation.setDefaultBackgroundColorOverride', { color: { r: 255, g: 255, b: 255, a: 1 } });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sending no color should go back to the default.

docs/api.md Outdated
@@ -605,6 +605,7 @@ Shortcut for [`keyboard.down`](#keyboarddownkey-options) and [`keyboard.up`](#ke
- `y` <[number]> y-coordinate of top-left corner of clip area
- `width` <[number]> width of clipping area
- `height` <[number]> height of clipping area
- `noBackground` <[boolean]> When true, hides default white background and allows capturing screenshots with transparency.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hides default white background and allows capturing screenshots with transparency. Defaults to false

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -23,6 +23,9 @@ const page = await browser.newPage();
await page.goto('http://example.com');
await page.screenshot({path: 'example.png'});

await page.setContent('TRANSPARENT BACKGROUND');
await page.screenshot({path: 'transparent.png', noBackground: true});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if this warrants a place in the example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

docs/api.md Outdated
@@ -605,6 +605,7 @@ Shortcut for [`keyboard.down`](#keyboarddownkey-options) and [`keyboard.up`](#ke
- `y` <[number]> y-coordinate of top-left corner of clip area
- `width` <[number]> width of clipping area
- `height` <[number]> height of clipping area
- `noBackground` <[boolean]> Hides default white background and allows capturing screenshots with transparency. Defaults to `false`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about calling this background which defaults to true, or maybe transparentBackground which defaults to false? The double negation in noBackground: false feels weird.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer parameters that default to false, hence the name. transparentBackground works for me as well, but I don't think it is particularly better. The parameter controls behavior that is somewhat involved, so it is hard to find a simple name for it. How can background be transparent? Is it when there is noBackground? 😝

@aslushnikov aslushnikov merged commit 127f396 into puppeteer:master Aug 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants