0

I am encountering a "disconnected: Unable to receive message from renderer" error while using Selenium with Chrome WebDriver.
The issue occurs after connecting to a VPN and attempting to open a web page with WebDriver.
I need to start the WebDriver before connecting to the VPN.

Fetching a web page before VPN connection works fine.
I have tried various solutions, including adjusting ChromeOptions, but the error persists.
Could anyone please provide insights or solutions to resolve this issue? Thank you.

import subprocess
import time

from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument("--start-maximized")

driver = webdriver.Chrome(
    options=options
)

subprocess.Popen(
    'rasdial "jp-free-09.protonvpn.net"',
    stdout=subprocess.PIPE,
    stderr=subprocess.PIPE,
    shell=True
)
print('Connected to VPN.')

time.sleep(10)

driver.get('https://stackoverflow.com/')
driver.quit()
print('Completed.')
Traceback (most recent call last):
  File "c:\Users\****\****\****\****\****.py", line 23, in <module>
    driver.get('https://stackoverflow.com/')
  File "C:\Users\****\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 355, in get
    self.execute(Command.GET, {"url": url})
  File "C:\Users\****\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 346, in execute
    self.error_handler.check_response(response)
  File "C:\Users\****\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 245, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: disconnected: not connected to DevTools
  (failed to check if window was closed: disconnected: not connected to DevTools)
  (Session info: chrome=115.0.5790.102)
Stacktrace:
Backtrace:
        GetHandleVerifier [0x00A5A813+48355]
        (No symbol) [0x009EC4B1]
        (No symbol) [0x008F5358]
        (No symbol) [0x008E7D96]
        (No symbol) [0x008E7AB9]
        (No symbol) [0x008F67C0]
        (No symbol) [0x0094C4D8]
        (No symbol) [0x0093A536]
        (No symbol) [0x009182DC]
        (No symbol) [0x009193DD]
        GetHandleVerifier [0x00CBAABD+2539405]
        GetHandleVerifier [0x00CFA78F+2800735]
        GetHandleVerifier [0x00CF456C+2775612]
        GetHandleVerifier [0x00AE51E0+616112]
        (No symbol) [0x009F5F8C]
        (No symbol) [0x009F2328]
        (No symbol) [0x009F240B]
        (No symbol) [0x009E4FF7]
        BaseThreadInitThunk [0x779200C9+25]
        RtlGetAppContainerNamedObjectPath [0x77C87B1E+286]
        RtlGetAppContainerNamedObjectPath [0x77C87AEE+238]

Python: 3.11.4
selenium: 4.10.0
webdriver-manager: 3.8.6
Chrome: 115.0.5790.102 (matching ChromeDriver version)

Y-404
  • 1
  • 1

1 Answers1

0

Remove the following arguments added through the instance of webdriver.ChromeOptions() unless mandatory:

  • --disable-gpu
  • --no-sandbox
  • --disable-dev-shm-usage
  • --disable-software-rasterizer
  • ignore-certificate-errors
  • --remote-debugging-port=9222

Further, if you are using Selenium v4.6 or above you don't have to explicitly use ChromeDriverManager().install() anymore as Selenium Manager can silently download the matching ChromeDriver


Solution

Your minimal code block can be:

from selenium import webdriver

option = webdriver.ChromeOptions()
option.add_argument("--start-maximized")
driver = webdriver.Chrome(options=option)
driver.get("https://google.com/")
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thank you, webdriver.ChromeOptions() was added to explicitly state that I had tried to solve the problem, but you are correct. Also, the implicit installation of ChromeDriverManager().install() was new to me. I have modified the code based on the above. However, "disconnected: not connected to DevTools" issue still seems to occur. – Y-404 Jul 19 '23 at 01:52
  • Checkout the updated answer and let me know the status. – undetected Selenium Jul 21 '23 at 20:07
  • I have added the Traceback code, is this ok? Please check. – Y-404 Jul 24 '23 at 06:55