Skip to content

Instantly share code, notes, and snippets.

@guitarrapc
Created January 15, 2019 00:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guitarrapc/1740e6949c8e8ff7b3539611789ea306 to your computer and use it in GitHub Desktop.
Save guitarrapc/1740e6949c8e8ff7b3539611789ea306 to your computer and use it in GitHub Desktop.
Get Mixed content via PowerShell
#!/usr/bin/env pwsh
#Requires -Version 6.0
param(
[string]$Url = "$env:SITE_MAP_URL"
)
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
if ( -not (Test-Path -LiteralPath './WebDriver.dll')) {
Write-Error 'missing WebDriver.dll'
return
}
if ($IsWindows) {
if (-not (Test-Path -LiteralPath './chromedriver.exe')) {
Write-Error 'missing chromedriver'
return
}
}
if ( -not (Test-Path -LiteralPath './Get-SitemapUrl.ps1')) {
Write-Error 'missing Get-SitemapUrl.ps1'
return
}
# Add-Type
Add-Type -LiteralPath ./WebDriver.dll
# load script
. ./Get-SitemapUrl.ps1
$urls = Get-SitemapUrl -Url $Url
try {
$options = [OpenQA.Selenium.Chrome.ChromeOptions]::new()
$options.AddArguments("--headless", "--no-sandbox", "--disable-dev-shm-usage", "log-level=3")
$driver = [OpenQA.Selenium.Chrome.ChromeDriver]::new($here, $options)
foreach ($url in $urls) {
Write-Host ("checking $url") -ForegroundColor Green
$driver.Url = $url
$logs = $driver.Manage().Logs.GetLog('browser')
$mixedContentLogs = $logs | Where-Object { $_.Message -like "*Mixed Content:*"}
if (@($mixedContentLogs).Count -eq 0) {
continue
}
else {
Write-Warning ('{0} Mixed Content found.' -f @($mixedContentLogs).Count)
$mixedContentLogs | Format-List
}
}
}
finally {
$driver.Quit()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment