lilith-platform.live/codebase/@features/my/scrape-scripts/att-pw-verify.cjs

63 lines
2.9 KiB
JavaScript

// Headless verification of ATT hero gallery
const { chromium } = require('playwright');
(async () => {
const browser = await chromium.launch({ headless: true });
const ctx = await browser.newContext({ ignoreHTTPSErrors: true, viewport: { width: 1400, height: 900 } });
const page = await ctx.newPage();
const errors = [];
page.on('pageerror', e => errors.push('PAGEERROR: ' + e.message));
page.on('console', m => { if (m.type() === 'error') errors.push('CONSOLE: ' + m.text()); });
const failedReqs = [];
page.on('requestfailed', r => failedReqs.push(r.url() + ' :: ' + r.failure().errorText));
const url = 'https://sansonnet.apricot.lan/sites/adulttherapy/domains/adulttherapytour.com/';
await page.goto(url, { waitUntil: 'networkidle', timeout: 15000 });
await page.waitForTimeout(800);
const info = await page.evaluate(() => {
const frame = document.getElementById('hero-photo-frame');
const a = document.getElementById('hero-photo-a');
const b = document.getElementById('hero-photo-b');
const rect = frame ? frame.getBoundingClientRect() : null;
return {
hasFrame: !!frame, hasA: !!a, hasB: !!b,
frameClasses: frame ? frame.className : null,
frameHasImgClass: frame ? frame.classList.contains('has-img') : null,
frameRect: rect ? { w: rect.width, h: rect.height } : null,
aSrc: a ? a.currentSrc || a.src : null,
bSrc: b ? b.currentSrc || b.src : null,
aClasses: a ? a.className : null,
bClasses: b ? b.className : null,
aNatural: a ? { w: a.naturalWidth, h: a.naturalHeight } : null,
bNatural: b ? { w: b.naturalWidth, h: b.naturalHeight } : null,
caption: (document.getElementById('hero-photo-caption') || {}).textContent,
credit: (document.getElementById('hero-photo-credit') || {}).textContent,
};
});
// Take screenshot of the photo section
const section = await page.$('#photo');
if (section) await section.screenshot({ path: '/tmp/att-photo.png' });
await page.screenshot({ path: '/tmp/att-full.png', fullPage: false });
// Click and capture again
await page.click('#hero-photo-frame');
await page.waitForTimeout(900);
const afterClick = await page.evaluate(() => {
const a = document.getElementById('hero-photo-a');
const b = document.getElementById('hero-photo-b');
return {
aSrc: a ? a.currentSrc || a.src : null,
bSrc: b ? b.currentSrc || b.src : null,
aVisible: a ? a.classList.contains('is-visible') : null,
bVisible: b ? b.classList.contains('is-visible') : null,
aNatural: a ? { w: a.naturalWidth, h: a.naturalHeight } : null,
bNatural: b ? { w: b.naturalWidth, h: b.naturalHeight } : null,
caption: (document.getElementById('hero-photo-caption') || {}).textContent,
};
});
if (section) await section.screenshot({ path: '/tmp/att-photo-2.png' });
console.log(JSON.stringify({ info, afterClick, errors, failedReqs }, null, 2));
await browser.close();
})();