Skip to main content

@paprize/puppeteer

openReport()

openReport(page, reportUrl, jsonData, timeout): Promise<void>

Defined in: openReport.ts:21

Opens a report in the given Puppeteer page, injects a JSON data file if provided, and waits for the report to be ready.

Parameters

ParameterTypeDefault valueDescription
pagePageundefinedThe Puppeteer Page instance where the report will be opened.
reportUrlURLundefinedThe URL of the report to be opened.
jsonDatastring | undefinedundefinedOptional JSON data as a string to be injected into the page.
timeoutnumber30000The maximum time to wait for the report to be ready, in milliseconds. Defaults to 30,000 ms.

Returns

Promise<void>

A promise that resolves when the report is ready.

Throws

Will throw an error if the report does not become ready within the specified timeout.


pageToPdf()

pageToPdf(page, options?): Promise<Uint8Array<ArrayBufferLike>>

Defined in: pageToPdf.ts:12

Generates a PDF from the given Puppeteer Page instance using the specified options.

Parameters

ParameterTypeDescription
pagePageThe Puppeteer Page instance to generate the PDF from.
options?ReportOptionsOptional additional options to customize the PDF generation. These options will be merged with the default settings.

Returns

Promise<Uint8Array<ArrayBufferLike>>

A promise that resolves to a Uint8Array containing the generated PDF data.


reportToPdf()

reportToPdf(page, reportUrl, jsonData?, pdfOptions?): Promise<Uint8Array<ArrayBufferLike>>

Defined in: reportToPdf.ts:15

Generates a PDF from a report by navigating to the specified report URL and optionally sending JSON data to the page.

Parameters

ParameterTypeDescription
pagePageThe Puppeteer Page instance used to interact with the report.
reportUrlURLThe URL of the report to be converted to a PDF.
jsonData?stringOptional JSON data to be sent to the report page.
pdfOptions?PDFOptionsOptional configuration for generating the PDF, including timeout and other settings.

Returns

Promise<Uint8Array<ArrayBufferLike>>

A promise that resolves to a Uint8Array containing the generated PDF data.


serveReport()

serveReport(dir, port?): Promise<ReportServer>

Defined in: serveReport.ts:23

Serves a static report from the specified directory over HTTP.

Parameters

ParameterTypeDescription
dirstringThe directory containing the static files to serve.
port?numberOptional. The port on which the server will listen. If not provided, a random available port will be used.

Returns

Promise<ReportServer>

A promise that resolves to a ReportServer object, which provides methods to close the server and retrieve its host URL.

The server serves files from the specified directory and automatically rewrites requests to /index.html for any unmatched routes. Subdirectories in the specified directory are mapped to corresponding routes.