AI agents
mcp-guardrails
AI agent guardrails for MCP servers: dry run and confirm, signed preview tokens, optimistic concurrency, revision undo and errors that teach the agent.
Print HTML to PDF with Playwright and headless Chromium, with JavaScript and the network turned off, hard limits, and a layout lint for overflow and broken images.
npm install safe-html-pdf playwright
npx playwright install chromiumsafe-html-pdf is a Playwright PDF renderer for HTML you do not fully trust. It prints HTML to a PDF in headless Chromium with JavaScript turned off and every network request refused. The page can only load the files you hand it through a resolveAsset callback.
While the page is open it also checks the layout, per page or per slide, and reports overflow, text drawn outside the page and images that failed to load, so a bad document is caught before anyone opens it.
html-pdf-node and puppeteer-html-pdf also print HTML to PDF, but they leave JavaScript and the network on and say nothing about the layout. That is fine for HTML you wrote yourself and the wrong default for HTML written by a model or a user. safe-html-pdf renders the quotation PDFs in the Bundlewise CRM.
import { writeFile } from 'node:fs/promises';
import { createRenderer } from 'safe-html-pdf';
const renderer = createRenderer({ concurrency: 4 });
const { pdf, pages, warnings } = await renderer.render(html, {
format: 'slides',
pageSelector: 'section.slide',
});
await writeFile('deck.pdf', pdf);
for (const warning of warnings) console.warn(warning.message);
await renderer.close();import { renderPdf } from 'safe-html-pdf';
const { pdf } = await renderPdf('<h1>Invoice</h1>', { format: 'Letter', margin: '15mm' });const renderer = createRenderer({
resolveAsset: (url) => (url.pathname === '/logo.png' ? { body: logoBytes, contentType: 'image/png' } : null),
});safe-html-pdf proposal.html -o proposal.pdf --format slides --page-selector section.slide --assets assetsWrote proposal.pdf (3 pages, 15.1 KB)
5 warnings
page 2 overflow Page 2 overflows its 1280 x 720 area: div.card
page 3 broken-image Page 3: image failed to load: /team.png
page 3 broken-image Page 3: image failed to load: https://cdn.example.com/photo.jpg
- missing-asset No file was served for the image request to http://document.invalid/team.png
- blocked-request Blocked image request to https://cdn.example.com/photo.jpgsafe-html-pdf <input.html> [-o out.pdf] [options]Install safe-html-pdf and playwright, run npx playwright install chromium, then call renderPdf(html) from code or run safe-html-pdf input.html from the command line. You get the PDF bytes, the page count and a list of layout warnings.
HTML written by a model or a user can contain scripts that read local files, call out to the network or change the page after you check it. With JavaScript and the network off, the PDF shows only the markup and the files you chose to serve.
It does the same job on Playwright. html-pdf-node and puppeteer-html-pdf leave JavaScript and the network on and report nothing about the layout. safe-html-pdf turns both off, limits time and concurrency, and lints each page or slide.
Serve them through resolveAsset, or point the CLI at a folder with --assets. A path that tries to leave the folder, through .. or a symbolic link, is refused and counts as a missing file. Playwright 1.40 or newer is a peer dependency.
Yes. In a container, or as root, Chromium may refuse to start with its sandbox on. Pass launch: { chromiumSandbox: false } and isolate the container yourself; the package never turns the sandbox off for you.
AI agents
AI agent guardrails for MCP servers: dry run and confirm, signed preview tokens, optimistic concurrency, revision undo and errors that teach the agent.
Web QA
Responsive design testing that measures the layout at every viewport width: overflow, clipping, inconsistent insets and radii, low-resolution images and layout shift.
Web QA
A broken link checker and launch checklist for a static site build: SEO basics, links and assets, redirects, share cards, icons, JSON-LD and old-URL coverage.
Author
Saimul Islam is a Forward Deployed Engineer and Solutions Architect. Several of these packages run in production on DeveloperLook, the Bundlewise CRM and Sitessa.