From 3bd09e4e1b4d0956a97b552135c953f72703e12e Mon Sep 17 00:00:00 2001 From: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com> Date: Sun, 22 Sep 2024 08:18:02 -0400 Subject: [PATCH] Fallback to fullpage when page dimensions arent available --- src/utils/UrlContentFetcher.ts | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/utils/UrlContentFetcher.ts b/src/utils/UrlContentFetcher.ts index b96b5f4..615180b 100644 --- a/src/utils/UrlContentFetcher.ts +++ b/src/utils/UrlContentFetcher.ts @@ -140,16 +140,25 @@ export class UrlContentFetcher { } }) // const defaultViewport = this.page.viewport(); // width 800 height 600 by default - let options: ScreenshotOptions = { - // fullPage: true, // clip and fullPage are mutually exclusive - encoding: "base64", - // quality: 80, - clip: { - x: 0, - y: 0, - width: pageWidth, - height: Math.min(pageHeight, 8_000), - }, + let options: ScreenshotOptions + if (pageHeight && pageWidth) { + options = { + // fullPage: true, // clip and fullPage are mutually exclusive + encoding: "base64", + // quality: 80, + clip: { + x: 0, + 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({