// fixtures/engines/navigate.mjs — moving between slides never shows a // frame without a slide, in Chromium and in WebKit (Astra's finding 4 on // #27; Paul, 2026-10-26: "No flashing, ever!" — a visible gap counts). // // Run by internal/slidestest/fonts_engines_browser_test.go with the same // SLIDES_ENGINES_CONFIG as first-reveal.mjs. Every font file is held // 800 ms on the way out, so a page load — whose slide the font gate // hides until its faces are confirmed — would show an empty stage for // most of a second. // // Each scenario opens a surface, waits for its first slide, then pages: // the viewer's Next, Next, Previous and the browser's Back; the same in // the viewer's scriptless presenting mode; the presenter's own buttons // on the projector; and a next slide whose family the page has not // loaded (the deck changed after the page was opened). Captures every // ~50 ms. The verdict: from the first capture with text, no capture is // blank, and every picture captured is one the slide rested on (seen in // at least three captures) — never a half-drawn one in between. // // The control pages by loading the page, as the links do without a // script. It must fail the verdict in each engine, or the check is blind. process.env.PW_TEST_SCREENSHOT_NO_FONTS_READY = '1' const { chromium, webkit } = await import('playwright') const { PNG } = await import('pngjs') const { createHash } = await import('node:crypto') const config = JSON.parse(process.env.SLIDES_ENGINES_CONFIG) const pause = (ms) => new Promise((r) => setTimeout(r, ms)) const click = (sel) => `document.querySelector(${JSON.stringify(sel)}).click()` const submit = (sel) => `document.querySelector(${JSON.stringify(sel)}).form.requestSubmit()` const scenarios = [ { name: 'viewer: next, next, previous, back', deck: 'three', path: (s) => `/d/${s}?slide=1`, steps: [click('[slides-pager] a[rel="next"]'), click('[slides-pager] a[rel="next"]'), click('[slides-pager] a[rel="prev"]'), 'history.back()'] }, { name: 'presenting by link: next, next, previous, back', deck: 'three', path: (s) => `/d/${s}?slide=1&present=1`, steps: [click('[slides-pager] a[rel="next"]'), click('[slides-pager] a[rel="next"]'), click('[slides-pager] a[rel="prev"]'), 'history.back()'] }, { name: 'projector: the presenter\'s next and previous', deck: 'projectorToken', path: (s) => s, steps: [submit('[slides-bar] form input[value="next"]'), submit('[slides-bar] form input[value="next"]'), submit('[slides-bar] form input[value="prev"]')] }, { name: 'viewer: a next slide whose family is not in', deck: 'plainThree', path: (s) => `/d/${s}?slide=1`, addCode: true, slowFont: /LiberationMono-/, fontDelay: 2000, steps: [click('[slides-pager] a[rel="next"]')], gap: 3000 }, { name: 'control: paging by loading the page', deck: 'three', path: (s) => `/d/${s}?slide=1`, control: true, steps: [`location.assign(document.querySelector('[slides-pager] a[rel="next"]').href)`] }, ] const slideBox = () => { const s = document.querySelector('[slides-slide]') if (!s) return null const r = s.getBoundingClientRect() if (r.width < 50 || r.height < 50 || Math.abs(r.width / r.height - 16 / 9) > 0.05) return null return { x: Math.max(0, Math.floor(r.left)), y: Math.max(0, Math.floor(r.top)), width: Math.floor(r.width), height: Math.floor(r.height) } } function verdict(frames) { const first = frames.findIndex((f) => !f.blank) if (first < 0) return 'the slide was never seen with text on it' const counts = new Map() for (const f of frames.slice(first)) counts.set(f.hash, (counts.get(f.hash) || 0) + 1) for (const f of frames.slice(first)) { if (f.blank) return `a slide was on screen at ${frames[first].ms}ms and the stage was empty at ${f.ms}ms` if (counts.get(f.hash) < 3) return `at ${f.ms}ms a picture the slide never rested on (${f.hash.slice(0, 8)})` } const rested = new Set(frames.slice(first).map((f) => f.hash)) if (rested.size < 2) return 'the slide never changed' return null } const failures = [] const engines = Object.entries({ chromium, webkit }).filter(([n]) => !process.env.SLIDES_ENGINES_ENGINE || n === process.env.SLIDES_ENGINES_ENGINE) for (const [engineName, engine] of engines) { // Chromium is the full browser in its new headless mode (channel // 'chromium'), not Playwright's default headless shell: the shell // re-rasterises a few glyph edges differently when a late editor // replaces a text's DOM with an identical one, which no browser a // person uses does, and these checks compare pixels exactly. const browser = await engine.launch(engineName === 'chromium' ? { headless: true, channel: 'chromium' } : { headless: true }) for (const s of scenarios) { const label = `${engineName}, ${s.name}` const context = await browser.newContext({ viewport: { width: 1280, height: 900 }, deviceScaleFactor: 1 }) await context.addCookies(config.cookies.map((c) => ({ name: c.Name, value: c.Value, url: config.origin, httpOnly: c.HttpOnly, sameSite: 'Lax' }))) await context.addInitScript(config.probe) await context.route('**/*', async (route) => { const url = route.request().url() const wait = /\/static\/fonts\//.test(url) ? (s.slowFont && s.slowFont.test(url) ? s.fontDelay : 800) : 0 if (wait) { const response = await route.fetch() await pause(wait) try { await route.fulfill({ response }) } catch {} return } return route.continue() }) const page = await context.newPage() const target = config.decks[s.deck].shift() if (!target) throw new Error(`no fresh ${s.deck} deck left for ${label}`) await page.goto(config.origin + s.path(target.path || target)) await page.waitForFunction(() => document.documentElement.getAttribute('data-slides-fonts') === 'shown', null, { timeout: 15000 }) if (s.addCode) { // The deck changes after the page is open: slide 2 gains code. const res = await fetch(`${config.origin}/api/v1/decks/${target}/ops`, { method: 'POST', headers: { Authorization: `Bearer ${config.token}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ ops: [{ op: 'add_block', slide: 'slidetwo0002', type: 'code', region: 'body', markdown: 'late(code)' }] }), }) if (!res.ok) throw new Error(`${label}: ops ${res.status}`) } await pause(1200) // the prefetch of the neighbours let clip = null const frames = [] const start = Date.now() const gap = s.gap || 1100 let step = 0 while (Date.now() - start < gap * (s.steps.length + 1)) { const ms = Date.now() - start if (step < s.steps.length && ms >= gap * (step + 0.5)) { await page.evaluate(s.steps[step]).catch(() => {}) step++ } if (!clip) clip = await page.evaluate(slideBox).catch(() => null) if (!clip) continue const visible = await page.evaluate(() => { const sl = document.querySelector('[slides-slide]') return !!sl && getComputedStyle(sl).visibility === 'visible' }).catch(() => false) const raw = await page.screenshot({ clip, caret: 'hide', timeout: 2000 }).catch(() => null) if (!raw) continue const shot = PNG.sync.read(raw) const counts = new Map() for (let i = 0; i < shot.data.length; i += 4 * 17) { const k = (shot.data[i] >> 3) << 10 | (shot.data[i + 1] >> 3) << 5 | (shot.data[i + 2] >> 3) counts.set(k, (counts.get(k) || 0) + 1) } let bg = 0 let most = -1 for (const [k, n] of counts) if (n > most) { most = n; bg = k } const [br, bgc, bb] = [((bg >> 10) & 31) << 3, ((bg >> 5) & 31) << 3, (bg & 31) << 3] let ink = 0 for (let i = 0; i < shot.data.length; i += 4) { if (Math.abs(shot.data[i] - br) + Math.abs(shot.data[i + 1] - bgc) + Math.abs(shot.data[i + 2] - bb) > 160) ink++ } frames.push({ ms, blank: !visible || ink < 20, hash: createHash('sha256').update(shot.data).digest('hex') }) } let v = verdict(frames) const probe = await page.evaluate(() => window.__fontProbe || null).catch(() => null) if (!v && probe && probe.violations.length) v = `text visible in a face that had not loaded: ${probe.violations[0]}` if (!v && probe && probe.errors && probe.errors.length) v = `the page: ${probe.errors[0]}` if (!v && probe && probe.gaps && probe.gaps.length) v = `the DOM probe saw slide text gone at ${probe.gaps[0]}ms` const transitions = frames.filter((f, i) => !i || f.hash !== frames[i - 1].hash || f.blank !== frames[i - 1].blank).map((f) => `${f.ms}:${f.blank ? 'blank' : f.hash.slice(0, 6)}`) console.log(JSON.stringify({ engine: engineName, scenario: s.name, frames: frames.length, verdict: v, transitions: transitions.slice(0, 14) })) if (s.control && !v) failures.push(`${label}: the check did not see the page load's empty stage; it is blind`) else if (!s.control && v) failures.push(`${label}: ${v}`) await context.close() } await browser.close() } if (failures.length) { console.error(failures.join('\n')) process.exit(1) }