From 74b0d2d75378816c6436e3a0abb658d7a40021ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=97=B6=E7=91=BE?= Date: Wed, 6 Nov 2024 14:35:11 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A3=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E9=9D=9Ebuffer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/puppeteer/core.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/puppeteer/core.ts b/src/puppeteer/core.ts index b81cc2a..4988a92 100644 --- a/src/puppeteer/core.ts +++ b/src/puppeteer/core.ts @@ -156,10 +156,10 @@ export class Render { /** 整个页面截图 */ if (data.fullPage) { options.captureBeyondViewport = true - const image = await page.screenshot(options) + const uint8Array = await page.screenshot(options) await this.setViewport(page, data?.setViewport?.width, data?.setViewport?.height, data?.setViewport?.deviceScaleFactor) this.screenshot(page) - return image as T['multiPage'] extends true | number ? Buffer[] : Buffer + return Buffer.from(uint8Array) as RenderResult } /** 获取页面元素 */ @@ -176,10 +176,10 @@ export class Render { /** 指定元素截图 */ if (!data.multiPage) { /** 截图 */ - const image = await page.screenshot(options) + const uint8Array = await page.screenshot(options) this.screenshot(page) - return image as RenderResult + return Buffer.from(uint8Array) as RenderResult } /** 分页截图 */ @@ -205,8 +205,8 @@ export class Render { /** 截图位置 */ data.clip = { x: 0, y, width: boxWidth, height: clipHeight } - const Uint8Array = await body!.screenshot(data) - const buffer = Buffer.from(Uint8Array) + const uint8Array = await body!.screenshot(data) + const buffer = Buffer.from(uint8Array) list.push(buffer) }