Skip to content

Commit

Permalink
fix: 修正返回类型非buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
sj817 committed Nov 6, 2024
1 parent c8c2cf7 commit 74b0d2d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/puppeteer/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>
}

/** 获取页面元素 */
Expand All @@ -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<T>
return Buffer.from(uint8Array) as RenderResult<T>
}

/** 分页截图 */
Expand All @@ -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)
}

Expand Down

0 comments on commit 74b0d2d

Please sign in to comment.