fysh711426 / UndetectedChromeDriver

GNU General Public License v3.0
172 stars 61 forks source link

'Unable to receive message from renderer' error after setting userDataDir #85

Open anastasiam opened 4 weeks ago

anastasiam commented 4 weeks ago

Hello!

When setting userDataDir and navigating to a url I get an error Unable to receive message from renderer in console output. When I try to do anything else, after this message appears, I get OpenQA.Selenium.WebDriverException: disconnected: not connected to DevTools exception. If userDataDir is not being set it works perfectly fine.

Error in console: Screenshot 2024-08-14 174802

Exception:

OpenQA.Selenium.WebDriverException: disconnected: not connected to DevTools
  (failed to check if window was closed: disconnected: not connected to DevTools)
  (Session info: chrome=127.0.6533.101)
   at OpenQA.Selenium.WebDriver.UnpackAndThrowOnError(Response errorResponse)
   at OpenQA.Selenium.WebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.WebDriver.GetScreenshot()

My code:

using var chromeDriver = UndetectedChromeDriver.Create(
    headless: true,
    driverExecutablePath: await new ChromeDriverInstaller().Auto(),
    userDataDir: $@"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}\Google\Chrome\User Data"
);

Console.WriteLine("Navigating to nowsecure.nl...");
chromeDriver.GoToUrl("https://nowsecure.nl");

Console.WriteLine("Getting screenshot...");
var screenshot = chromeDriver.GetScreenshot();

Even though I set headless: true, it behaves like it's set to false. The window is opening, navigating to the url and closing immediately.

I would appreciate any help.

STRATZ-Ken commented 4 weeks ago

I am no expert, but I think this happens when you have an instance of chromedriver.exe running. You should run a taskkill chromedriver.exe prior to running each time. You most likely started it, then stopped, and didnt clean it up. You cannot have two instances in the same directory or you get this error.

anastasiam commented 4 weeks ago

I am no expert, but I think this happens when you have an instance of chromedriver.exe running. You should run a taskkill chromedriver.exe prior to running each time. You most likely started it, then stopped, and didnt clean it up. You cannot have two instances in the same directory or you get this error.

When I execute taskkill /f /im chromedriver.exe, it shows ERROR: The process "chromedriver.exe" not found. I terminated all Google Chrome processes as well. I was even restarting my computer.

STRATZ-Ken commented 4 weeks ago

Did you try chrome.exe as well?

anastasiam commented 4 weeks ago

Did you try chrome.exe as well?

Yes

anastasiam commented 4 weeks ago

I've also tried to copy User Data folder to a separate one and use it, but I still get the same error.