Skip to content

renderer.ts#

View Markdown

Source

4 documented symbols. Read the signatures first, then expand each item for parameters, return types, and examples.

4 symbols 3 functions 1 modules 11 parameters 3 returns

Reference#

modulerendererHTML → PNG renderer using Chromium screenshots via Playwright.

HTML → PNG renderer using Chromium screenshots via Playwright.

View source

fnrenderHtmlToPng(page: Page, html: string, width: number, height: number, publicDir?: string): Promise<Buffer>Renders an HTML string to a PNG buffer using Chromium.

Renders an HTML string to a PNG buffer using Chromium.

Signature

export async function renderHtmlToPng(page: Page, html: string, width: number, height: number, publicDir?: string): Promise<Buffer>

View source

Parameters

  • page Page

    Playwright page instance

  • html string

    HTML string from template function

  • width number

    Image width

  • height number

    Image height

  • publicDir string

    Optional public directory for serving local assets (images, fonts, etc.) — optional

Returns

Promise<Buffer>

PNG buffer

fnroutePublicDir(page: Page, publicDir: string): Promise<void>Serves local assets from publicDir for anything the card requests. Registered o…

Serves local assets from publicDir for anything the card requests.

Registered once per page rather than once per render: a handler added on every render stacks up on a page that is reused, and Playwright then walks the whole stack for every request.

Signature

export async function routePublicDir(page: Page, publicDir: string): Promise<void>

View source

Parameters

  • page Page
  • publicDir string

Returns

Promise<void>
fnwrapHtml(bodyHtml: string, width: number, height: number, useBaseUrl: boolean): stringWraps template HTML in a minimal document with viewport locked to given dimensi…

Wraps template HTML in a minimal document with viewport locked to given dimensions.

Signature

function wrapHtml(bodyHtml: string, width: number, height: number, useBaseUrl: boolean): string

View source

Parameters

  • bodyHtml string
  • width number
  • height number
  • useBaseUrl boolean

Returns

string