[CmdletBinding()] param( [string]$Url = 'https://example.com/', [switch]$Json ) $ErrorActionPreference = 'Stop' try { $page = Invoke-WebRequest -Uri $Url -UseBasicParsing } catch { Write-Error ("Page failed: {0}" -f $_.Exception.Message) exit 1 } $linkMatches = [regex]::Matches($page.Content, ']*>', 'IgnoreCase') $manifestLink = $linkMatches | Where-Object { $_.Value -match 'rel\s*=\s*["'']manifest["'']' } | Select-Object -First 1 if (-not $manifestLink) { Write-Host 'manifest не найден' exit 1 } $hrefMatch = [regex]::Match($manifestLink.Value, 'href\s*=\s*["'']([^"'']+)["'']', 'IgnoreCase') if (-not $hrefMatch.Success) { Write-Host 'У ссылки manifest нет href' exit 1 } $manifestUrl = [Uri]::new([Uri]$Url, $hrefMatch.Groups[1].Value).AbsoluteUri try { $manifest = Invoke-RestMethod -Uri $manifestUrl -UseBasicParsing } catch { Write-Error ("Manifest failed: {0}" -f $_.Exception.Message) exit 1 } $problems = @() foreach ($name in @('name', 'short_name', 'start_url', 'display')) { if (-not $manifest.$name) { $problems += "нет поля $name" } } if ($manifest.display -eq 'browser') { $problems += 'display=browser не даёт полноценный режим приложения' } $icons = @() if ($manifest.icons) { $icons = @($manifest.icons) } if ($icons.Count -eq 0) { $problems += 'нет иконок' } foreach ($icon in $icons) { if (-not $icon.src) { $problems += 'иконка без src' } if (-not $icon.sizes) { $problems += ("иконка без sizes: {0}" -f $icon.src) } } if ($Json) { [pscustomobject]@{ url = $manifestUrl name = $manifest.name short_name = $manifest.short_name start_url = $manifest.start_url display = $manifest.display icons = $icons.Count problems = $problems } | ConvertTo-Json -Depth 5 exit $(if ($problems.Count -eq 0) { 0 } else { 1 }) } Write-Host ("manifest: {0}" -f $manifestUrl) Write-Host ("name: {0}" -f $manifest.name) Write-Host ("short_name: {0}" -f $manifest.short_name) Write-Host ("start_url: {0}" -f $manifest.start_url) Write-Host ("display: {0}" -f $manifest.display) Write-Host ("icons: {0}" -f $icons.Count) foreach ($icon in $icons) { Write-Host (" {0} {1}" -f $icon.src, $icon.sizes) } if ($problems.Count -gt 0) { Write-Host 'Замечания:' $problems | ForEach-Object { Write-Host (" - {0}" -f $_) } exit 1 }