Skip to content

k.utils.screenShot

Web pages and page screenshots

Overview

k.utils.screenShot Generates a PNG byte array for an absolute URL, site page, or HTML string.

take()

Screenshot of absolute URL; supports width, height, fullPage and scaling parameter overloading.

ParameterTypeRequiredDescription
absoluteUrlstringYesPublicly accessible absolute URL
widthnumberNoViewport width, default 1366
heightnumberNoViewport height, default 768
scaleWidthnumberNoScaled output width
scaleHeightnumberNoScaled output height
fullPagebooleanNoWhether to capture the full page

Returns: number[] \| null, PNG bytes.

ts
const png = k.utils.screenShot.take("https://www.kooboo.com", 1280, 720, true)

takeLocalPageUrl() / takePage()

Take a screenshot of the relative path or page name of the site.

MethodParameterReturnDescription
takeLocalPageUrl(url, width?, height?, fullPage?)string, number?, number?, boolean?number[] | nullCapture by site-relative URL
takePage(pageName, width?, height?, fullPage?)string, number?, number?, boolean?number[] | nullCapture by page name
ts
const png = k.utils.screenShot.takeLocalPageUrl("/products", 1280, 720, true)
k.file.writeBinary("shots/products.png", png)

takeFromHTML()

Screenshot of HTML string after rendering.

ParameterTypeRequiredDescription
htmlCodestringYesHTML to render and capture
widthnumberNoViewport width
heightnumberNoViewport height
scaleWidthnumberNoScaled output width
scaleHeightnumberNoScaled output height
fullPagebooleanNoWhether to capture the full page

Returns: number[] \| null, PNG bytes.

ts
const html = "<html><body><h1>Invoice</h1></body></html>"
const png = k.utils.screenShot.takeFromHTML(html, 800, 600, false)
k.file.writeBinary("shots/invoice.png", png)