Elffuss BraidHub

utopia-ia/elffuss-code public

2df00d521f0c · 1.1 KiBRawPermalink
1import { chromium } from 'playwright';
2import { readFileSync, writeFileSync } from 'fs';
3
4const SB = (process.env.SCRATCH || '/tmp/elffuss-test');
5const tpl = readFileSync(SB + '/og_template.html', 'utf8');
6const svgCode = readFileSync(new URL('../../elffuss-code/web/img/elffuss-code.svg', import.meta.url).pathname, 'utf8').replace(/`/g,'\\`');
7const svgClaw = readFileSync(new URL('../../elffuss-claw/web/img/elffuss.svg', import.meta.url).pathname, 'utf8').replace(/`/g,'\\`');
8const html = tpl.replace('__SVG_CODE__', svgCode).replace('__SVG_CLAW__', svgClaw);
9writeFileSync(SB + '/og_built.html', html);
10
11const b = await chromium.launch();
12const ctx = await b.newContext({ viewport: { width: 1200, height: 630 }, deviceScaleFactor: 2 });
13const page = await ctx.newPage();
14for (const p of ['code','claw']) {
15 await page.goto('file://' + SB + '/og_built.html?p=' + p, { waitUntil: 'load' });
16 await page.waitForFunction(() => window.__ready === true).catch(()=>{});
17 await page.waitForTimeout(300);
18 const el = await page.$('.og');
19 await el.screenshot({ path: `${SB}/og-${p}-en.png` });
20 console.log('OK og-' + p + '-en.png');
21}
22await b.close();