mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
Allow capturing transparent screenshots (#354)
This patch adds `omitBackground` option to the `page.screenshot` method. Fixes #344
This commit is contained in:
parent
1ca7849017
commit
127f3966d7
@ -604,6 +604,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
|
||||
- `omitBackground` <[boolean]> Hides default white background and allows capturing screenshots with transparency. Defaults to `false`.
|
||||
- returns: <[Promise]<[Buffer]>> Promise which resolves to buffer with captured screenshot
|
||||
|
||||
#### page.setContent(html)
|
||||
|
@ -467,7 +467,11 @@ class Page extends EventEmitter {
|
||||
await this._client.send('Emulation.setDeviceMetricsOverride', { mobile, width, height, deviceScaleFactor, screenOrientation });
|
||||
}
|
||||
|
||||
if (options.omitBackground)
|
||||
await this._client.send('Emulation.setDefaultBackgroundColorOverride', { color: { r: 0, g: 0, b: 0, a: 0 } });
|
||||
let result = await this._client.send('Page.captureScreenshot', { format, quality: options.quality, clip });
|
||||
if (options.omitBackground)
|
||||
await this._client.send('Emulation.setDefaultBackgroundColorOverride');
|
||||
|
||||
if (options.fullPage)
|
||||
await this.setViewport(this._viewport);
|
||||
|
BIN
test/golden/transparent.png
Normal file
BIN
test/golden/transparent.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 119 B |
@ -1810,6 +1810,12 @@ describe('Page', function() {
|
||||
expect(screenshots[i]).toBeGolden(`grid-cell-${i}.png`);
|
||||
await Promise.all(pages.map(page => page.close()));
|
||||
}));
|
||||
it('should allow transparency', SX(async function() {
|
||||
await page.setViewport({ width: 100, height: 100 });
|
||||
await page.goto(EMPTY_PAGE);
|
||||
let screenshot = await page.screenshot({omitBackground:true});
|
||||
expect(screenshot).toBeGolden('transparent.png');
|
||||
}));
|
||||
});
|
||||
|
||||
describe('Tracing', function() {
|
||||
|
Loading…
Reference in New Issue
Block a user