Instantly share code, notes, and snippets.

Embed
What would you like to do?
Selenium WebDriver(Chrome)を使った簡単なMixed Contentのチェック例
#Requires -Version 5.0
# パスチェック
# カレントディレクトリにWebDriver.dllとchromedriver.exeがある前提
if ( -not (Test-Path -LiteralPath '.\WebDriver.dll')) {
Write-Error 'WebDriver.dllがありません。'
return
}
if ( -not (Test-Path -LiteralPath '.\chromedriver.exe')) {
Write-Error 'chromedriver.exeがありません。'
return
}
# Add-Type
Add-Type -LiteralPath .\WebDriver.dll
$url = 'https://googlesamples.github.io/web-fundamentals/fundamentals/security/prevent-mixed-content/active-mixed-content.html'
#$url = 'https://blog.shibata.tech/' # 警告ログなしの場合
try {
# 開始
$options = [OpenQA.Selenium.Chrome.ChromeOptions]::new()
# ヘッドレス、log-level=3(LOG_FATAL)
$options.AddArguments("headless", "disable-gpu", "log-level=3")
$driver = [OpenQA.Selenium.Chrome.ChromeDriver]::new($options)
# ブラウザログチェック
Write-Host ("{0} をチェックします..." -f $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) {
Write-Host 'Mixed Contentではありませんでした。' -ForegroundColor Green
} else {
Write-Warning ('Mixed Contentログが{0}件ありました。' -f @($mixedContentLogs).Count)
$mixedContentLogs | Format-List
}
} finally {
# 終了
$driver.Quit()
}
@stknohg

This comment has been minimized.

Show comment
Hide comment
Owner

stknohg commented Jun 14, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment