Answer stability round 1: 0 🔴, 4 🟡 (0 misread); count chunks and projects as the archive holds them, date the 876 commits, fail the print when a font fails to load, build the image under run-heavy, and print from Python
This commit is contained in:
@@ -1,12 +1,21 @@
|
||||
// Print /work/page.html to /work/out.pdf with Chromium, as build-pdf.sh runs it inside the playwright-for-claude image.
|
||||
// build-pdf.py runs this in the playwright-for-claude image: it prints /work/page.html to /work/out.pdf with Chromium.
|
||||
const { chromium } = require('/app/node_modules/playwright');
|
||||
|
||||
(async () => {
|
||||
const browser = await chromium.launch({ args: ['--no-sandbox', '--disable-dev-shm-usage'] });
|
||||
const page = await browser.newPage({ viewport: { width: 1100, height: 1400 } });
|
||||
// A font that fails to load falls back to another, and the pages no longer fit their sheets, so any failed request fails the build.
|
||||
const failed = [];
|
||||
page.on('requestfailed', (request) => failed.push(request.url()));
|
||||
page.on('response', (response) => { if (response.status() >= 400) failed.push(`${response.status()} ${response.url()}`); });
|
||||
// networkidle waits for the Google Fonts the page loads; fonts.ready waits for them to apply.
|
||||
await page.goto('file:///work/page.html', { waitUntil: 'networkidle' });
|
||||
await page.evaluate(() => document.fonts.ready);
|
||||
if (failed.length) {
|
||||
console.error(`Not printed, since these failed to load: ${failed.join(', ')}`);
|
||||
await browser.close();
|
||||
process.exit(1);
|
||||
}
|
||||
await page.emulateMedia({ media: 'print' });
|
||||
// preferCSSPageSize takes the page's own @page rule: A4 landscape.
|
||||
await page.pdf({ path: '/work/out.pdf', format: 'A4', printBackground: true, preferCSSPageSize: true });
|
||||
|
||||
Reference in New Issue
Block a user