Spaces:
Sleeping
Sleeping
Download scripts/test_baseline_experiment.cjs from Sarvesh213/getcert-backend: direct link, hf CLI and curl.
- Browser
- Download file 4.19 kB
-
https://huggingface.co/spaces/Sarvesh213/getcert-backend/resolve/main/scripts/test_baseline_experiment.cjs
- Command line
-
hf download hf://spaces/Sarvesh213/getcert-backend/scripts/test_baseline_experiment.cjs
-
curl -L -o test_baseline_experiment.cjs https://huggingface.co/spaces/Sarvesh213/getcert-backend/resolve/main/scripts/test_baseline_experiment.cjs
4.19 kB
| const { chromium } = require('playwright'); | |
| const fs = require('fs'); | |
| const { execSync } = require('child_process'); | |
| (async () => { | |
| const browser = await chromium.launch({ headless: true }); | |
| const page = await browser.newPage({ viewport: { width: 1440, height: 1000 } }); | |
| await page.goto('http://127.0.0.1:5173/preview-certificate'); | |
| await page.waitForTimeout(2000); | |
| // Take screenshot of the exact DOM element in the browser | |
| const certEl = await page.locator('[data-certificate-canvas="true"]'); | |
| await certEl.screenshot({ path: '/home/grim/.gemini/antigravity/brain/780fc6f2-0ee4-4d27-a3c9-d81026488398/ref_dom_screenshot.png' }); | |
| console.log('Saved ref_dom_screenshot.png'); | |
| // Let's run an experiment directly in page with html2canvas and different onclone options | |
| const results = await page.evaluate(async () => { | |
| // We need html2canvas | |
| const html2canvasModule = await import('html2canvas'); | |
| const html2canvas = html2canvasModule.default || html2canvasModule; | |
| const certCanvas = document.querySelector('[data-certificate-canvas="true"]'); | |
| const targetWidth = 1024; | |
| const targetHeight = 682; | |
| async function testExport(name, oncloneFn) { | |
| const canvas = await html2canvas(certCanvas, { | |
| scale: 2, | |
| useCORS: true, | |
| allowTaint: true, | |
| backgroundColor: '#FFFFFF', | |
| logging: false, | |
| width: targetWidth, | |
| height: targetHeight, | |
| windowWidth: targetWidth, | |
| windowHeight: targetHeight, | |
| onclone: oncloneFn, | |
| }); | |
| return { name, dataUrl: canvas.toDataURL('image/png') }; | |
| } | |
| const exp1 = await testExport('baseline_current', (clonedDoc) => { | |
| const clonedCanvas = clonedDoc.querySelector('[data-certificate-canvas="true"]'); | |
| if (clonedCanvas) { | |
| clonedDoc.body.innerHTML = ''; | |
| clonedDoc.body.style.margin = '0'; | |
| clonedDoc.body.style.padding = '0'; | |
| clonedDoc.body.style.overflow = 'hidden'; | |
| clonedDoc.body.style.background = '#FFFFFF'; | |
| clonedCanvas.style.position = 'absolute'; | |
| clonedCanvas.style.top = '0'; | |
| clonedCanvas.style.left = '0'; | |
| clonedCanvas.style.margin = '0'; | |
| clonedCanvas.style.transform = 'none'; | |
| clonedDoc.body.appendChild(clonedCanvas); | |
| } | |
| }); | |
| const exp2 = await testExport('body_lineheight_1', (clonedDoc) => { | |
| const clonedCanvas = clonedDoc.querySelector('[data-certificate-canvas="true"]'); | |
| if (clonedCanvas) { | |
| clonedDoc.body.innerHTML = ''; | |
| clonedDoc.body.style.margin = '0'; | |
| clonedDoc.body.style.padding = '0'; | |
| clonedDoc.body.style.lineHeight = '1'; | |
| clonedDoc.body.style.overflow = 'hidden'; | |
| clonedDoc.body.style.background = '#FFFFFF'; | |
| clonedCanvas.style.position = 'absolute'; | |
| clonedCanvas.style.top = '0'; | |
| clonedCanvas.style.left = '0'; | |
| clonedCanvas.style.margin = '0'; | |
| clonedCanvas.style.transform = 'none'; | |
| clonedDoc.body.appendChild(clonedCanvas); | |
| } | |
| }); | |
| const exp3 = await testExport('body_lineheight_normal', (clonedDoc) => { | |
| const clonedCanvas = clonedDoc.querySelector('[data-certificate-canvas="true"]'); | |
| if (clonedCanvas) { | |
| clonedDoc.body.innerHTML = ''; | |
| clonedDoc.body.style.margin = '0'; | |
| clonedDoc.body.style.padding = '0'; | |
| clonedDoc.body.style.lineHeight = 'normal'; | |
| clonedDoc.body.style.overflow = 'hidden'; | |
| clonedDoc.body.style.background = '#FFFFFF'; | |
| clonedCanvas.style.position = 'absolute'; | |
| clonedCanvas.style.top = '0'; | |
| clonedCanvas.style.left = '0'; | |
| clonedCanvas.style.margin = '0'; | |
| clonedCanvas.style.transform = 'none'; | |
| clonedDoc.body.appendChild(clonedCanvas); | |
| } | |
| }); | |
| return [exp1, exp2, exp3]; | |
| }); | |
| for (const exp of results) { | |
| const base64Data = exp.dataUrl.replace(/^data:image\/png;base64,/, ''); | |
| const outPath = `/home/grim/.gemini/antigravity/brain/780fc6f2-0ee4-4d27-a3c9-d81026488398/exp_${exp.name}.png`; | |
| fs.writeFileSync(outPath, base64Data, 'base64'); | |
| console.log(`Saved ${outPath}`); | |
| } | |
| await browser.close(); | |
| })(); | |