Skip to content

Instantly share code, notes, and snippets.

@stknohg
Last active June 14, 2018 00:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save stknohg/88d3754833d3f532d8701f638963efa7 to your computer and use it in GitHub Desktop.
Save stknohg/88d3754833d3f532d8701f638963efa7 to your computer and use it in GitHub Desktop.
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
Copy link
Author

stknohg commented Jun 14, 2018

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