fix(capture): run page.evaluate as plain string (tsx/esbuild __name helpers break in browser context)
CI (SIAX Cloud) / contracts (pull_request) Successful in 17s
CI (SIAX Cloud) / security (pull_request) Successful in 25s
CI (SIAX Cloud) / contracts (push) Successful in 16s
CI (SIAX Cloud) / security (push) Successful in 18s
CI (SIAX Cloud) / quality (pull_request) Successful in 50s
CI (SIAX Cloud) / quality (push) Successful in 53s

This commit is contained in:
2026-09-16 23:00:45 +02:00
parent a4cdee7f64
commit 1e74c69228
+17 -7
View File
@@ -138,9 +138,11 @@ export async function capturePage(
});
const response = await page.goto(url, { timeout: opts.timeoutMs, waitUntil: "domcontentloaded" });
await page.waitForTimeout(500);
const captured = await page.evaluate(() => {
const count = (sel: string) => document.querySelectorAll(sel).length;
const pick = (el: Element | null, props: string[]) => {
// NOTE: evaluate code must be a plain string — tsx/esbuild would inject
// __name helpers into a transpiled function, which break in the browser.
const captured = await page.evaluate(`(() => {
const count = (sel) => document.querySelectorAll(sel).length;
const pick = (el, props) => {
if (!el) return Object.fromEntries(props.map((p) => [p, null]));
const cs = getComputedStyle(el);
return Object.fromEntries(props.map((p) => [p, cs.getPropertyValue(p) || null]));
@@ -176,13 +178,21 @@ export async function capturePage(
video: count("video"),
canvas: count("canvas"),
},
stylesheets: Array.from(document.querySelectorAll('link[rel="stylesheet"]')).map((l) =>
(l as HTMLLinkElement).href,
),
stylesheets: Array.from(document.querySelectorAll('link[rel="stylesheet"]')).map((l) => l.href),
images: Array.from(document.querySelectorAll("img")).slice(0, 50).map((i) => i.src),
computedStyle: { body, h1 },
};
});
})()`) as {
title: string;
description: string | null;
lang: string | null;
charset: string;
viewportMeta: string | null;
domCounts: Record<string, number>;
stylesheets: string[];
images: string[];
computedStyle: Record<string, Record<string, string | null>>;
};
let screenshotBase64: string | null = null;
try {
screenshotBase64 = await page.screenshot({