-
-
Save jsakamoto/ed77b54123d17cc08a6a178089544448 to your computer and use it in GitHub Desktop.
Selenium WebDriver(Chrome)を使った簡単なMixed Contentのチェック例
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# パスチェック | |
# カレントディレクトリに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() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment