mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
parent
053d960fb5
commit
260e428227
@ -13,8 +13,9 @@ export interface ScreenshotClip
|
|||||||
## Properties
|
## Properties
|
||||||
|
|
||||||
| Property | Modifiers | Type | Description |
|
| Property | Modifiers | Type | Description |
|
||||||
| ---------------------------------------------- | --------- | ------ | ----------- |
|
| ---------------------------------------------- | --------- | ------ | ----------------- |
|
||||||
| [height](./puppeteer.screenshotclip.height.md) | | number | |
|
| [height](./puppeteer.screenshotclip.height.md) | | number | |
|
||||||
|
| [scale?](./puppeteer.screenshotclip.scale.md) | | number | <i>(Optional)</i> |
|
||||||
| [width](./puppeteer.screenshotclip.width.md) | | number | |
|
| [width](./puppeteer.screenshotclip.width.md) | | number | |
|
||||||
| [x](./puppeteer.screenshotclip.x.md) | | number | |
|
| [x](./puppeteer.screenshotclip.x.md) | | number | |
|
||||||
| [y](./puppeteer.screenshotclip.y.md) | | number | |
|
| [y](./puppeteer.screenshotclip.y.md) | | number | |
|
||||||
|
13
docs/api/puppeteer.screenshotclip.scale.md
Normal file
13
docs/api/puppeteer.screenshotclip.scale.md
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
---
|
||||||
|
sidebar_label: ScreenshotClip.scale
|
||||||
|
---
|
||||||
|
|
||||||
|
# ScreenshotClip.scale property
|
||||||
|
|
||||||
|
**Signature:**
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
interface ScreenshotClip {
|
||||||
|
scale?: number;
|
||||||
|
}
|
||||||
|
```
|
@ -163,6 +163,10 @@ export interface ScreenshotClip {
|
|||||||
y: number;
|
y: number;
|
||||||
width: number;
|
width: number;
|
||||||
height: number;
|
height: number;
|
||||||
|
/**
|
||||||
|
* @defaultValue 1
|
||||||
|
*/
|
||||||
|
scale?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -3012,7 +3016,12 @@ export class Page extends EventEmitter {
|
|||||||
const result = await this.#client.send('Page.captureScreenshot', {
|
const result = await this.#client.send('Page.captureScreenshot', {
|
||||||
format,
|
format,
|
||||||
quality: options.quality,
|
quality: options.quality,
|
||||||
clip,
|
clip: clip
|
||||||
|
? {
|
||||||
|
...clip,
|
||||||
|
scale: clip.scale === undefined ? 1 : clip.scale,
|
||||||
|
}
|
||||||
|
: undefined,
|
||||||
captureBeyondViewport,
|
captureBeyondViewport,
|
||||||
fromSurface,
|
fromSurface,
|
||||||
});
|
});
|
||||||
@ -3044,14 +3053,12 @@ export class Page extends EventEmitter {
|
|||||||
}
|
}
|
||||||
return buffer;
|
return buffer;
|
||||||
|
|
||||||
function processClip(
|
function processClip(clip: ScreenshotClip): ScreenshotClip {
|
||||||
clip: ScreenshotClip
|
|
||||||
): ScreenshotClip & {scale: number} {
|
|
||||||
const x = Math.round(clip.x);
|
const x = Math.round(clip.x);
|
||||||
const y = Math.round(clip.y);
|
const y = Math.round(clip.y);
|
||||||
const width = Math.round(clip.width + clip.x - x);
|
const width = Math.round(clip.width + clip.x - x);
|
||||||
const height = Math.round(clip.height + clip.y - y);
|
const height = Math.round(clip.height + clip.y - y);
|
||||||
return {x, y, width, height, scale: 1};
|
return {x, y, width, height, scale: clip.scale};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BIN
test/golden-chromium/screenshot-clip-rect-scale2.png
Normal file
BIN
test/golden-chromium/screenshot-clip-rect-scale2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.3 KiB |
@ -52,6 +52,22 @@ describe('Screenshots', function () {
|
|||||||
});
|
});
|
||||||
expect(screenshot).toBeGolden('screenshot-clip-rect.png');
|
expect(screenshot).toBeGolden('screenshot-clip-rect.png');
|
||||||
});
|
});
|
||||||
|
itFailsFirefox('should use scale for clip', async () => {
|
||||||
|
const {page, server} = getTestState();
|
||||||
|
|
||||||
|
await page.setViewport({width: 500, height: 500});
|
||||||
|
await page.goto(server.PREFIX + '/grid.html');
|
||||||
|
const screenshot = await page.screenshot({
|
||||||
|
clip: {
|
||||||
|
x: 50,
|
||||||
|
y: 100,
|
||||||
|
width: 150,
|
||||||
|
height: 100,
|
||||||
|
scale: 2,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
expect(screenshot).toBeGolden('screenshot-clip-rect-scale2.png');
|
||||||
|
});
|
||||||
itFailsFirefox(
|
itFailsFirefox(
|
||||||
'should get screenshot bigger than the viewport',
|
'should get screenshot bigger than the viewport',
|
||||||
async () => {
|
async () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user