← back to Consulting Designerwallcoverings Com

scripts/aeo-render-verify.mjs

49 lines

#!/usr/bin/env node
// TK-20 READ-ONLY storefront render verification.
// Loads each AEO target in a real Chromium browser and greps the RENDERED DOM
// for the AEO marker class + a signature phrase. No writes of any kind.
import pw from '/Users/macstudio3/Projects/animals/node_modules/playwright/index.js';
const { chromium } = pw;

const TARGETS = [
  { url: 'https://www.designerwallcoverings.com/collections/versace-wallpaper', phrase: 'Medusa', kind: 'collection body_html' },
  { url: 'https://www.designerwallcoverings.com/collections/osborne-little',   phrase: 'Osborne', kind: 'collection body_html' },
  { url: 'https://www.designerwallcoverings.com/pages/wall-coverings',         phrase: 'wall covering', kind: 'new page body' },
];

const browser = await chromium.launch({ headless: true });
const ctx = await browser.newContext({
  userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0 Safari/537.36',
  viewport: { width: 1280, height: 900 },
});
const results = [];
for (const t of TARGETS) {
  const page = await ctx.newPage();
  const r = { url: t.url, kind: t.kind };
  try {
    const resp = await page.goto(t.url, { waitUntil: 'domcontentloaded', timeout: 45000 });
    r.status = resp ? resp.status() : null;
    // give the theme a moment to hydrate
    await page.waitForTimeout(2500);
    const html = await page.content();
    r.htmlLen = html.length;
    r.hasAeoAnswer = /dw-aeo-answer/i.test(html);
    r.hasAeoBlock  = /dw-aeo-block/i.test(html);
    r.hasFaq       = /dw-aeo-faq/i.test(html);
    r.hasPhrase    = new RegExp(t.phrase.replace(/[.*+?^${}()|[\]\\]/g,'\\$&'), 'i').test(html);
    r.hasJsonLdFaq = /"@type"\s*:\s*"FAQPage"/i.test(html);
    // Grab a small excerpt around the marker if present
    const idx = html.search(/dw-aeo-answer|dw-aeo-block/i);
    r.excerpt = idx >= 0 ? html.slice(idx, idx + 220).replace(/\s+/g,' ') : null;
    // Also check whether body_html content area exists at all (RTE / description container)
    r.hasRte = /class="[^"]*\brte\b/i.test(html) || /collection[-_]?description/i.test(html);
  } catch (e) {
    r.error = String(e).split('\n')[0];
  } finally {
    await page.close();
  }
  results.push(r);
}
await browser.close();
console.log(JSON.stringify(results, null, 2));