Private/Get-RaidinessBrowser.ps1

<#
    Finding the browser that is already on this machine.

    The report carries the whole assessment engine, so running it headlessly is
    how a PowerShell-only operator gets report.md, run.json, the LLM bundle and
    the PDF into a folder they chose -- without installing Node and without
    clicking four download buttons.

    Edge is present on every supported Windows machine, so in practice this
    finds something. When it does not, nothing fails: the caller falls back to
    opening the report in the browser, which is what happened before.
#>

function Get-RaidinessBrowser {
    [CmdletBinding()]
    [OutputType([string])]
    param(
        # An explicit path wins over everything, for an unusual install or a test.
        [string] $BrowserPath
    )

    if ($BrowserPath) {
        if (Test-Path -Path $BrowserPath) { return (Resolve-Path -Path $BrowserPath).Path }
        throw "No browser at $BrowserPath."
    }

    if ($env:RAIDINESS_BROWSER -and (Test-Path -Path $env:RAIDINESS_BROWSER)) {
        return (Resolve-Path -Path $env:RAIDINESS_BROWSER).Path
    }

    $candidates = [System.Collections.Generic.List[string]]::new()

    if ($IsWindows) {
        foreach ($root in $env:ProgramFiles, ${env:ProgramFiles(x86)}, $env:LOCALAPPDATA) {
            if (-not $root) { continue }
            $candidates.Add((Join-Path $root 'Microsoft\Edge\Application\msedge.exe'))
            $candidates.Add((Join-Path $root 'Google\Chrome\Application\chrome.exe'))
        }
        foreach ($name in 'msedge.exe', 'chrome.exe') {
            $key = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\$name"
            $registered = (Get-ItemProperty -Path $key -ErrorAction SilentlyContinue).'(default)'
            if ($registered) { $candidates.Add($registered) }
        }
    }
    elseif ($IsMacOS) {
        $candidates.Add('/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge')
        $candidates.Add('/Applications/Google Chrome.app/Contents/MacOS/Google Chrome')
        $candidates.Add('/Applications/Chromium.app/Contents/MacOS/Chromium')
    }

    foreach ($candidate in $candidates) {
        if ($candidate -and (Test-Path -Path $candidate)) { return (Resolve-Path -Path $candidate).Path }
    }

    foreach ($name in 'microsoft-edge-stable', 'microsoft-edge', 'google-chrome-stable', 'google-chrome', 'chromium', 'chromium-browser', 'msedge', 'chrome') {
        $found = Get-Command -Name $name -CommandType Application -ErrorAction SilentlyContinue | Select-Object -First 1
        if ($found) { return $found.Source }
    }

    $null
}