param([string]$Name='desktop',[int]$Width=1366,[int]$Height=768,[string]$Page='index.html',[string]$Theme='light',[switch]$Footer,[string]$Period='',[string]$Anchor='',[string]$Focus='') $ErrorActionPreference='Continue' $projectRoot=Split-Path -Parent $PSScriptRoot $qaRoot=Join-Path $projectRoot '.qa' [IO.Directory]::CreateDirectory($qaRoot) | Out-Null $tempBase=[IO.Path]::GetFullPath([IO.Path]::GetTempPath()) $profile=Join-Path $tempBase ('mangabom-render-'+[Guid]::NewGuid().ToString('N')) $probeName='layout-check-'+[Guid]::NewGuid().ToString('N')+'.html' $probePath=Join-Path $projectRoot ('dist\'+$probeName) [IO.File]::WriteAllText($probePath,[IO.File]::ReadAllText((Join-Path $PSScriptRoot 'layout-probe.html')),[Text.UTF8Encoding]::new($false)) try { $url='http://localhost:8080/'+$probeName+'?width='+$Width+'&height='+$Height+'&page='+[Uri]::EscapeDataString($Page)+'&theme='+$Theme if($Footer){$url+='&footer=1'} if($Period){$url+='&period='+[Uri]::EscapeDataString($Period)} if($Anchor){$url+='&anchor='+[Uri]::EscapeDataString($Anchor)} if($Focus){$url+='&focus='+[Uri]::EscapeDataString($Focus)} $dump=& 'C:\Program Files\Google\Chrome\Application\chrome.exe' --headless=new --no-first-run --no-default-browser-check "--user-data-dir=$profile" "--window-size=$Width,$Height" --virtual-time-budget=10000 "--screenshot=$qaRoot\$Name.png" --dump-dom $url 2> (Join-Path $qaRoot ($Name+'.chrome.log')) | Out-String $match=[regex]::Match($dump,'
(.*?)
') if(-not $match.Success -or $match.Groups[1].Value -eq 'pending'){throw 'Layout probe did not finish'} $json=[Net.WebUtility]::HtmlDecode($match.Groups[1].Value) [IO.File]::WriteAllText((Join-Path $qaRoot ($Name+'.json')),$json,[Text.UTF8Encoding]::new($false)) Write-Output ($Name+': '+$json) $metrics=$json | ConvertFrom-Json if($metrics.probeError){throw $metrics.probeError} if($metrics.heroReadClipped){throw 'Hero reading button is clipped'} if($metrics.scrollWidth -gt $metrics.viewport -or $metrics.logoOverlapsMenu -or $metrics.overlappingMenuItems -or $metrics.outside.Count -or $metrics.textClipped.Count -or $metrics.errors.Count -or @($metrics.themeButtons | Where-Object {-not $_.inFooter}).Count){throw 'Layout check failed; inspect the screenshot and metrics in .qa/'} } finally { [IO.File]::Delete($probePath) $resolvedProfile=[IO.Path]::GetFullPath($profile) if(-not $resolvedProfile.StartsWith((Join-Path $tempBase 'mangabom-render-'),[StringComparison]::OrdinalIgnoreCase)){throw 'Unsafe temporary profile cleanup path'} if(Test-Path -LiteralPath $resolvedProfile){Remove-Item -LiteralPath $resolvedProfile -Recurse -Force -ErrorAction SilentlyContinue} }