Weblitz Preview

Scripts and the virtual clock

A page's scripts run once, before printing, in V8 (Chrome's JavaScript engine, built into the package): pages built by React or Vue, charts drawn by Chart.js, tables filled from the page's own data. The scripts of the page's frames run with them. HtmlScripts.Off runs none.

The virtual clock

Timers and animations run in virtual time: a page that waits two seconds for a timer does not make the render wait two seconds. The page gets WaitFor of virtual time (5 seconds by default) before it is printed; a timer set for later does not run. Timeout is different: the real processor time scripts may take (30 seconds by default) before they are stopped and the page printed as it is. See scripts and the clock.

var options = new HtmlPdfOptions
{
    Scripts = HtmlScripts.Default with { WaitFor = TimeSpan.FromSeconds(10), Timeout = TimeSpan.FromSeconds(5) },
};

The same PDF every time

What scripts read of the world is fixed by the options: Locale (en-US), TimeZone (UTC) and Now; Date and Intl both read the time zone. Give them, and the same input prints the same PDF: see locale and clock.

Canvas text and web fonts

A chart drawn on a canvas writes its text with the fonts loaded when it draws. Draw after your web fonts are loaded, the weight you use included:

Promise.all([document.fonts.load("400 12px 'Your Font'"), document.fonts.ready]).then(drawCharts);

The browser a page sees

A page sees desktop Chrome 156 on the machine's own system (navigator.userAgent, navigator.userAgentData, and the User-Agent header when the network is on). UserAgent and UserAgentMetadata change it: see the browser a page sees.