From 1528aeb3ddca340d63d7400c6bd321e0e77f674c Mon Sep 17 00:00:00 2001 From: Saoud Rizwan <7799382+saoudrizwan@users.noreply.github.com> Date: Sun, 22 Sep 2024 07:42:50 -0400 Subject: [PATCH] Fallback to body if documentElement not available --- src/utils/UrlContentFetcher.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/utils/UrlContentFetcher.ts b/src/utils/UrlContentFetcher.ts index c312d96..b96b5f4 100644 --- a/src/utils/UrlContentFetcher.ts +++ b/src/utils/UrlContentFetcher.ts @@ -131,7 +131,15 @@ export class UrlContentFetcher { }).catch(() => {}) // image cannot exceed 8_000 pixels - const pageHeight = await this.page.evaluate(() => document.documentElement.scrollHeight) + const { pageHeight, pageWidth } = await this.page.evaluate(() => { + const html: HTMLElement | null = document.documentElement + const body: HTMLElement | null = document.body + return { + pageHeight: html?.scrollHeight || body?.scrollHeight, + pageWidth: html?.clientWidth || body?.clientWidth, + } + }) + // const defaultViewport = this.page.viewport(); // width 800 height 600 by default let options: ScreenshotOptions = { // fullPage: true, // clip and fullPage are mutually exclusive encoding: "base64", @@ -139,7 +147,7 @@ export class UrlContentFetcher { clip: { x: 0, y: 0, - width: await this.page.evaluate(() => document.documentElement.clientWidth), + width: pageWidth, height: Math.min(pageHeight, 8_000), }, }