#!/usr/bin/env node /** Probe: which engines produce real pixels on the WASM-embedded (default URL) path. */ import path from "node:path"; import fs from "node:fs"; import { REPO, parseArgs, waitForServer, launchBrowser, newPage, openFile, waitScene } from "./course/lib/lesson-recorder.mjs"; const args = parseArgs(); const BASE = `http://127.0.0.1:${args.port}`; const SCENE = path.join(REPO, "web/app/public/tutorial/rendering/render-studio.blend"); const OUT = "/tmp/render-basics-probe"; fs.mkdirSync(OUT, { recursive: true }); await waitForServer(`${BASE}/`); const browser = await launchBrowser(args.gpu); const { context } = await newPage(browser, { baseUrl: null }); const page = context.pages()[0] ?? await context.newPage(); await page.goto(`${BASE}/`, { waitUntil: "domcontentloaded" }); await page.locator("main.blender-app").waitFor({ timeout: 120_000 }); await openFile(page, SCENE); await waitScene(page, { objects: 7, timeout: 120_000 }); await page.waitForFunction(() => [...document.querySelectorAll(".workspace-tab")].some((t) => t.getAttribute("aria-current") !== null), null, { timeout: 90_000 }); await page.evaluate(() => { const t = [...document.querySelectorAll(".workspace-tab")].find((i) => i.textContent === "Rendering"); if (t instanceof HTMLElement) t.click(); }); await page.waitForTimeout(1500); const toggle = page.getByTestId("native-web-tools-toggle"); if (await toggle.count() && await toggle.first().isVisible().catch(() => false)) { await toggle.first().click({ force: true }); await page.waitForTimeout(1500); } // The React subtree holding the panel only mounts once a render hands the // screen back (App.tsx clears gpuSurfaceOpen inside `if (stored.length)`), so // the first F12 is what makes the panel reachable at all. await page.evaluate(() => { if (document.activeElement instanceof HTMLElement) document.activeElement.blur(); }); await page.keyboard.press("F12"); await page.waitForFunction(() => document.querySelector(".native-render-panel") !== null, null, { timeout: 120_000 }); const details = page.locator("details.native-render-fallback").first(); await details.waitFor({ timeout: 120_000 }); if (!(await details.evaluate((e) => e.open))) await details.locator("summary").first().click({ force: true }); await page.locator(".native-render-panel").first().waitFor({ timeout: 60_000 }); for (const engine of ["SCENE", "BLENDER_WORKBENCH", "BLENDER_EEVEE"]) { const started = Date.now(); try { const panel = page.locator(".native-render-panel").first(); await panel.locator('select[aria-label="Engine"]').selectOption(engine); await panel.getByRole("button", { name: "Render Frame", exact: true }).click(); await page.waitForFunction(() => { const p = document.querySelector(".native-render-panel"); const text = p?.querySelector(".native-workflow-output")?.textContent ?? ""; if (/FAILED|CANCELLED/.test(text)) return true; return /SUCCEEDED/.test(text) && p.querySelector(".native-workflow-artifacts a[download]") !== null; }, null, { timeout: 240_000 }); const links = panel.locator(".native-workflow-artifacts a[download]"); const names = await links.evaluateAll((nodes) => nodes.map((n) => n.getAttribute("download") ?? "")); const idx = names.findIndex((n) => /\.png$/i.test(n)); if (idx < 0) { console.log(engine, "no png", names); continue; } const [dl] = await Promise.all([page.waitForEvent("download", { timeout: 60_000 }), links.nth(idx).click({ force: true })]); const file = path.join(OUT, `wasm-${engine}.png`); await dl.saveAs(file); console.log(engine, "saved", file, fs.statSync(file).size, "ms", Date.now() - started); } catch (error) { console.log(engine, "FAIL", String(error?.message ?? error).split("\n")[0], Date.now() - started); } } await context.close(); await browser.close();