SeleniumからChromeのインスタンス作成時にエラー

OpenQA.Selenium.WebDriverException: 'disconnected: Unable to receive message from renderer
  (failed to check if window was closed: disconnected: not connected to DevTools)
  (Session info: chrome=119.0.6045.124)'

C#環境でSeleniumからChromeのインスタンスを作成しようとすると上記のエラーが発生する。

この場合は下記の通り”–no-sandbox”オプションを追記すると問題が解決する場合がある。どうもコンソールリダイレクトのパイプライン処理などが引っかかる場合があるらしい。

using OpenQA.Selenium.Chrome;
using OpenQA.Selenium;
・・・
var options = new OpenQA.Selenium.Chrome.ChromeOptions();
options.AddArgument("--no-sandbox");
var newWebDriver = new ChromeDriver(options);

sandboxはWEB閲覧中のScript動作などの安全性を担保する上で重要な機能になる。接続先WEBサイトに不正なScriptが置かれていた場合、損失を受ける可能性もあるので注意が必要になる。Firefoxなど別のブラウザに移行した方が良いのかもしれない。

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です