Fallback to fullpage when page dimensions arent available

This commit is contained in:
Saoud Rizwan
2024-09-22 08:18:02 -04:00
parent 1528aeb3dd
commit 3bd09e4e1b

View File

@@ -140,16 +140,25 @@ export class UrlContentFetcher {
} }
}) })
// const defaultViewport = this.page.viewport(); // width 800 height 600 by default // const defaultViewport = this.page.viewport(); // width 800 height 600 by default
let options: ScreenshotOptions = { let options: ScreenshotOptions
// fullPage: true, // clip and fullPage are mutually exclusive if (pageHeight && pageWidth) {
encoding: "base64", options = {
// quality: 80, // fullPage: true, // clip and fullPage are mutually exclusive
clip: { encoding: "base64",
x: 0, // quality: 80,
y: 0, clip: {
width: pageWidth, x: 0,
height: Math.min(pageHeight, 8_000), y: 0,
}, width: pageWidth,
height: Math.min(pageHeight, 8_000),
},
}
} else {
// if we can't get the page dimensions, fallback to full page screenshot
options = {
encoding: "base64",
fullPage: true,
}
} }
let screenshotBase64 = await this.page.screenshot({ let screenshotBase64 = await this.page.screenshot({