Preview a receipt in your app
Draw a receipt in your own web page, without a printer and without a key, with the npm packages @tillcast/preview and @tillcast/html-render.
Both packages are 0.x: the API can change between minor versions, so pin the version you test. They are licensed under Apache-2.0.
@tillcast/preview draws a receipt in your page. It is a React component and a function for any other page. It takes the same blocks as the document of a print job, or ReceiptLine text, and draws what a printer would print on 80 mm paper (48 characters a line) or 58 mm paper.
It runs in the browser, with the renderer that Tillcast uses, compiled to WebAssembly. It needs no API key and makes no call to Tillcast to draw: the renderer is a file that your own page serves, fetched once. It stores nothing and sends nothing. It does not print. The picture is not the printed receipt: the font and the paper differ, and the printer’s own output is the only exact one. To print, create a print job.
There is no preview call in the REST API. The MCP server has preview_document, which draws a receipt as text for an assistant that its owner connected. To show a receipt in your own page or code, or to draw one without an MCP client, use these packages.
Install
The renderer, @tillcast/html-render, is a dependency and comes with it. You need React 19 for the component only, and a bundler or a server that serves a .wasm file. Recent versions of Vite and Next.js need no configuration.
Draw a receipt
React
Any other page
The preview never throws. A source it cannot draw, or a page whose policy blocks WebAssembly, is a visible message in the preview and a call of onError, never a blank box.
Preview and Content Security Policy
The preview draws with WebAssembly. A page that sends a Content-Security-Policy blocks WebAssembly unless the policy allows it, so a strict page needs two things, and the second is the one that is forgotten:
'wasm-unsafe-eval'inscript-src(or indefault-src, whichscript-srcfalls back to). The word lets the browser compile WebAssembly and nothing else: it does not alloweval,new Functionor an inline script, and it is not'unsafe-eval'.connect-src 'self', or the origin that serves the.wasmfile. The file is fetched once, from your own origin and never from Tillcast. Underdefault-src 'none'the browser refuses the fetch.
A QR code, a barcode or an image on a receipt is a data: picture, so img-src needs data: as well.
Change the script-src and connect-src your policy already has: a browser ignores a second directive of the same name. A page that uses a nonce and 'strict-dynamic' keeps both and adds the word:
Whether your page’s policy changes is your decision. If it should not, draw the receipt on your own server instead, as shown below.
In the browser
A page with a strict policy. This policy works the same in a <meta> tag as in a header:
The React component needs the same policy. Both were tried in Chromium 141, built with Vite from the published packages, under script-src 'self' 'wasm-unsafe-eval' and under a nonce with 'strict-dynamic'.
Without the word, the preview does not throw and does not leave a blank box. It draws this in place of the receipt:
The preview cannot start: this page’s Content-Security-Policy blocks WebAssembly, which draws the receipt in the browser. Add ‘wasm-unsafe-eval’ to the script-src directive of the policy. That source expression allows compiling WebAssembly; it does not allow eval, new Function or inline script.
It also calls onError with kind: "csp-script", fix: "script-src 'self' 'wasm-unsafe-eval'" (an example of the line, not a replacement: add the word to the script-src you have) and cause, whose message ends with what the browser said. Chromium 141 said this, and reported a securitypolicyviolation event for script-src:
Other browsers use their own words. Without a connect-src under default-src 'none', the preview says that the page may not fetch the .wasm file (kind: "csp-connect", fix: "connect-src 'self'"), and the console of Chromium 141 says, with the address of your file:
On your own server
The renderer under the preview, @tillcast/html-render, also runs in Node. Draw the receipt there, in your own process, and send the page HTML and a stylesheet: the page has no script and no WebAssembly, so it needs no 'wasm-unsafe-eval'. This runs in your own process: nothing is sent to Tillcast, no key is needed, and the REST API has no preview call.
format: "html" gives content, the HTML of the paper, and stylesheet, its CSS. The markup has no style attribute, so style-src 'self' with the stylesheet served as a file is enough. The renderer escapes the text of the receipt, so content goes into the page as it is. This page shows the same receipt as the browser example. (email_html has inline styles: it is for mail.)
The renderer on its own
@tillcast/html-render is what draws. In a browser, a worker or Node it turns blocks or ReceiptLine text into HTML for a screen, HTML for a mail, or text, for the layout of a printer profile. A server of your own can use it to prepare the body of an e-mail. It does not print and it does not send mail. Its README on npm has the request, the answer and the limits.