master
John Lauer NEW ralph render test (John's taskbar-hover method, automated): tools/ralph-render-test.ps1 captures the DWM thumbnail… d91acfc 2mo ago
# ralph-render-test.ps1 — prove a BACKGROUND pup window actually PAINTED, without forcing a render.
#
# WHY this and not a screenshot: a CDP screenshot (Page.captureScreenshot) and PrintWindow with
# PW_RENDERFULLCONTENT both FORCE a fresh render, so they show content even when the live window is
# blank — they MASK the bug. The Windows taskbar thumbnail (what you see hovering a taskbar icon) is
# generated by DWM from the window's LAST COMPOSITED surface, WITHOUT forcing a new render. So the
# DWM thumbnail is ground truth for "did this occluded window ever paint?". This script captures that
# thumbnail programmatically (DwmRegisterThumbnail into a tiny top-left host form, then screen-grab
# the host) and classifies rendered-vs-blank by counting distinct sampled colors.
#
# Usage:  powershell -NoProfile -ExecutionPolicy Bypass -File ralph-render-test.ps1 -Hwnds "5380294,2824624,12061336"
# Output: one line per hwnd: "<hwnd> -> RENDERED(distinct=N) | BLANK(distinct=N) | THUMBNAIL_EMPTY(...)"
#
# INTERPRETING (pair with a DOM check — pup_eval document.body.innerText.length):
#   RENDERED                      -> the window painted; the fix is working.
#   BLANK  + DOM bodyLen > 0       -> RENDER BUG: content exists but never painted (the thing we fix).
#   BLANK  + DOM bodyLen == 0      -> empty page (bot-wall / 404 / still loading) — NOT a render bug.
# Measured baseline (2026-08-22): a rendered vendor page scores distinct >= 12 (DigiKey 14, TI 13);
# a blank/empty window scores ~9. Threshold 12 separates them cleanly.
#
# The fix this verifies: createPageInNewWindow pulses Emulation.setFocusEmulationEnabled on for two
# animation frames at birth then off (v2.0.280/281), so an off-screen-born, occluded window paints
# ONE frame (Chrome retains it) instead of sitting blank — without continuous render / battery cost.
param([string]$Hwnds = "")
Add-Type -AssemblyName System.Windows.Forms,System.Drawing
Add-Type @"
using System;using System.Runtime.InteropServices;
public class DWMT {
 [StructLayout(LayoutKind.Sequential)] public struct RECT { public int L,T,R,B; }
 [StructLayout(LayoutKind.Sequential)] public struct TP { public int dwFlags; public RECT rcDestination; public RECT rcSource; public byte opacity; public bool fVisible; public bool fSourceClientAreaOnly; }
 [DllImport("dwmapi.dll")] public static extern int DwmRegisterThumbnail(IntPtr dest, IntPtr src, out IntPtr thumb);
 [DllImport("dwmapi.dll")] public static extern int DwmUpdateThumbnailProperties(IntPtr thumb, ref TP props);
 [DllImport("dwmapi.dll")] public static extern int DwmUnregisterThumbnail(IntPtr thumb);
}
"@
function Test-Render([long]$srcHwnd) {
  $W=280; $H=200
  $form = New-Object System.Windows.Forms.Form
  $form.FormBorderStyle='None'; $form.StartPosition='Manual'; $form.Location=New-Object System.Drawing.Point(0,0)
  $form.Size=New-Object System.Drawing.Size($W,$H); $form.TopMost=$true; $form.BackColor=[System.Drawing.Color]::Magenta
  $form.Show(); [System.Windows.Forms.Application]::DoEvents()
  $thumb=[IntPtr]::Zero
  $hr=[DWMT]::DwmRegisterThumbnail($form.Handle,[IntPtr]$srcHwnd,[ref]$thumb)
  if($hr -ne 0){ $form.Close(); return "REGISTER_FAIL(hr=$hr)" }
  $p=New-Object DWMT+TP; $p.dwFlags=0x1 -bor 0x8 -bor 0x4 -bor 0x10
  $r=New-Object DWMT+RECT; $r.L=0;$r.T=0;$r.R=$W;$r.B=$H; $p.rcDestination=$r; $p.opacity=255; $p.fVisible=$true; $p.fSourceClientAreaOnly=$true
  [void][DWMT]::DwmUpdateThumbnailProperties($thumb,[ref]$p)
  [System.Windows.Forms.Application]::DoEvents(); Start-Sleep -Milliseconds 450; [System.Windows.Forms.Application]::DoEvents()
  $bmp=New-Object System.Drawing.Bitmap($W,$H); $g=[System.Drawing.Graphics]::FromImage($bmp)
  $g.CopyFromScreen($form.Location.X,$form.Location.Y,0,0,$bmp.Size)
  $colors=@{}; $magenta=0; $tot=0
  for($y=0;$y -lt $H;$y+=8){ for($x=0;$x -lt $W;$x+=8){ $c=$bmp.GetPixel($x,$y); $colors["$($c.R),$($c.G),$($c.B)"]=1; $tot++; if($c.R -gt 200 -and $c.B -gt 200 -and $c.G -lt 80){$magenta++} } }
  [DWMT]::DwmUnregisterThumbnail($thumb)|Out-Null; $g.Dispose(); $bmp.Dispose(); $form.Close()
  $distinct=$colors.Count
  if($magenta -gt ($tot*0.5)){ return "THUMBNAIL_EMPTY(magenta bleed - src has no composited DWM surface)" }
  elseif($distinct -ge 12){ return "RENDERED(distinct=$distinct)" }
  else { return "BLANK(distinct=$distinct)" }
}
foreach($h in ($Hwnds -split ',')){ $h=$h.Trim(); if($h){ Write-Output ("{0} -> {1}" -f $h, (Test-Render ([long]$h))) } }