Files
git.stella-ops.org/src/Web/StellaOps.Web/cdp-check.cjs

42 lines
1.4 KiB
JavaScript

const { chromium } = require('playwright');
const fs = require('fs');
(async () => {
const browser = await chromium.launch({ headless: true });
const context = await browser.newContext({ ignoreHTTPSErrors: true });
const page = await context.newPage();
// NO event handlers - they hang because of Zone.js
const response = await page.goto('https://stella-ops.local/', {
waitUntil: 'domcontentloaded',
timeout: 10000,
});
console.log('DOM loaded, status=' + response.status());
const client = await context.newCDPSession(page);
// Wait for Angular
await new Promise((r) => setTimeout(r, 6000));
// CDP evaluate - bypasses Zone.js
const r1 = await client.send('Runtime.evaluate', {
expression: 'JSON.stringify({title: document.title, bodyLen: document.body.innerHTML.length, text: document.body.innerText.substring(0,500), hasRouter: !!document.querySelector("router-outlet"), hasSplash: !!document.getElementById("stella-splash")})',
timeout: 3000,
returnByValue: true,
});
console.log('\nPage state:', r1.result.value);
// Screenshot via CDP
const ss = await client.send('Page.captureScreenshot', { format: 'png' });
const outPath = 'C:/dev/New folder/git.stella-ops.org/page-check.png';
fs.writeFileSync(outPath, Buffer.from(ss.data, 'base64'));
console.log('Screenshot saved to', outPath);
await browser.close();
process.exit(0);
})().catch((e) => {
console.error('Fatal:', e.message);
process.exit(1);
});