mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
Introduce Page.saveScreenshot
Page.saveScreenshot uses filepath to infer screenshot type (either PNG of JPG) and saves the screenshot to file system.
This commit is contained in:
@@ -226,14 +226,6 @@ class WebPage {
|
||||
* {string} fileName
|
||||
*/
|
||||
render(fileName) {
|
||||
var mimeType = mime.lookup(fileName);
|
||||
var screenshotType = null;
|
||||
if (mimeType === 'image/png')
|
||||
screenshotType = ScreenshotTypes.PNG;
|
||||
else if (mimeType === 'image/jpeg')
|
||||
screenshotType = ScreenshotTypes.JPG;
|
||||
if (!screenshotType)
|
||||
throw new Error(`Cannot render to file ${fileName} - unsupported mimeType ${mimeType}`);
|
||||
var clipRect = null;
|
||||
if (this.clipRect && (this.clipRect.left || this.clipRect.top || this.clipRect.width || this.clipRect.height)) {
|
||||
clipRect = {
|
||||
@@ -243,8 +235,7 @@ class WebPage {
|
||||
height: this.clipRect.height
|
||||
};
|
||||
}
|
||||
var imageBuffer = await(this._page.screenshot(screenshotType, clipRect));
|
||||
fs.writeFileSync(fileName, imageBuffer);
|
||||
var imageBuffer = await(this._page.saveScreenshot(fileName, clipRect));
|
||||
}
|
||||
|
||||
release() {
|
||||
|
||||
Reference in New Issue
Block a user