44 lines
1.5 KiB
JavaScript
44 lines
1.5 KiB
JavaScript
|
|
const { chromium } = require('playwright');
|
||
|
|
|
||
|
|
const input = process.argv[2];
|
||
|
|
|
||
|
|
(async () => {
|
||
|
|
const launchOptions = { headless: true };
|
||
|
|
if (process.env.BROWSER_EXE) {
|
||
|
|
launchOptions.executablePath = process.env.BROWSER_EXE;
|
||
|
|
}
|
||
|
|
const browser = await chromium.launch(launchOptions);
|
||
|
|
const page = await browser.newPage({ viewport: { width: 1920, height: 1080 }, deviceScaleFactor: 1 });
|
||
|
|
await page.goto(input, { waitUntil: 'load', timeout: 30000 });
|
||
|
|
await page.waitForTimeout(1500);
|
||
|
|
await page.waitForSelector('section', { state: 'attached', timeout: 10000 });
|
||
|
|
const info = await page.evaluate(() => {
|
||
|
|
const sections = Array.from(document.querySelectorAll('section'));
|
||
|
|
return {
|
||
|
|
title: document.title,
|
||
|
|
url: location.href,
|
||
|
|
bodyText: document.body.innerText.slice(0, 500),
|
||
|
|
count: sections.length,
|
||
|
|
viewport: { w: innerWidth, h: innerHeight },
|
||
|
|
scroll: { w: document.documentElement.scrollWidth, h: document.documentElement.scrollHeight },
|
||
|
|
sections: sections.map((s, i) => {
|
||
|
|
const r = s.getBoundingClientRect();
|
||
|
|
const cs = getComputedStyle(s);
|
||
|
|
return {
|
||
|
|
index: i + 1,
|
||
|
|
label: s.getAttribute('data-label') || '',
|
||
|
|
rect: { x: r.x, y: r.y, w: r.width, h: r.height },
|
||
|
|
display: cs.display,
|
||
|
|
visibility: cs.visibility,
|
||
|
|
opacity: cs.opacity,
|
||
|
|
};
|
||
|
|
}),
|
||
|
|
};
|
||
|
|
});
|
||
|
|
console.log(JSON.stringify(info, null, 2));
|
||
|
|
await browser.close();
|
||
|
|
})().catch((err) => {
|
||
|
|
console.error(err);
|
||
|
|
process.exit(1);
|
||
|
|
});
|