Home > other >  How can I prevent Chrome from crashing through Selenium?
How can I prevent Chrome from crashing through Selenium?

Time:01-30

I am using Selenium in node.js to test web pages in Chrome on Windows 11. I recently moved to a new laptop, and now my Chrome browser crashes as soon as the driver launches it. I am using Chrome and Chromedriver version 109.0.5414.74 (same as on the old machine), node.js v16.13.0, and selenium-webdriver v4.7.1. Outside of Selenium, Chrome is working fine. Here's the simple repro:

const { Builder } = require( 'selenium-webdriver' );
const chrome = require( 'selenium-webdriver/chrome' );

async function main() {
    const chrome_options = new chrome.Options()
    .addArguments( '--disable-gpu' );
    const driver = await new Builder()
    .forBrowser( 'chrome' )
    .setChromeOptions( chrome_options )
    .build();

    await driver.get( 'https://google.com/' );

    await driver.quit();
}

main()
.then( () => {
    console.log( 'Done' );
})
.catch( e => {
    console.error( `Error: ${e.message}` );
});

I only added the disable-gpu because of some google search results that said it was needed, and because the error message references GPU problems, but nothing's different without it. Here's the output from node crash.js:

DevTools listening on ws://127.0.0.1:53101/devtools/browser/701cedaa-d8e3-4541-9c9b-d22f53244ac4
[29204:3600:0124/223239.948:ERROR:display_layout.cc(551)] PlacementList must be sorted by first 8 bits of display_id
[29204:3600:0124/223240.003:ERROR:gpu_process_host.cc(985)] GPU process launch failed: error_code=18
[29204:3600:0124/223240.038:ERROR:display_layout.cc(551)] PlacementList must be sorted by first 8 bits of display_id
[29204:3600:0124/223240.177:ERROR:device_event_log_impl.cc(215)] [22:32:40.176] USB: usb_service_win.cc:415 Could not read device interface GUIDs: The system cannot find the file specified. (0x2)
[29204:3600:0124/223240.179:ERROR:device_event_log_impl.cc(215)] [22:32:40.178] USB: usb_device_handle_win.cc:1046 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[29204:3600:0124/223240.179:ERROR:usb_descriptors.cc(141)] Failed to read length for configuration 1.
[29204:3600:0124/223240.180:ERROR:usb_descriptors.cc(100)] Failed to read all configuration descriptors. Expected 2, got 1.
[29204:3600:0124/223240.181:ERROR:device_event_log_impl.cc(215)] [22:32:40.180] USB: usb_device_win.cc:96 Failed to read descriptors from \\?\usb#vid_17ef&pid_3082#101b74e97#{a5dcbf10-6530-11d2-901f-00c04fb951ed}.
[29204:3600:0124/223240.181:ERROR:device_event_log_impl.cc(215)] [22:32:40.181] USB: usb_device_handle_win.cc:1046 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[29204:3600:0124/223240.190:ERROR:device_event_log_impl.cc(215)] [22:32:40.190] USB: usb_device_handle_win.cc:1046 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[29204:3600:0124/223240.191:ERROR:device_event_log_impl.cc(215)] [22:32:40.192] USB: usb_device_handle_win.cc:1046 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[29204:3600:0124/223240.191:ERROR:device_event_log_impl.cc(215)] [22:32:40.193] USB: usb_device_handle_win.cc:1046 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[29204:3600:0124/223240.222:ERROR:device_event_log_impl.cc(215)] [22:32:40.232] Bluetooth: bluetooth_adapter_winrt.cc:1164 RequestRadioAccessAsync failed: RadioAccessStatus::DeniedByUserWill not be able to change radio power.
[29204:3600:0124/223240.238:ERROR:device_event_log_impl.cc(215)] [22:32:40.240] USB: usb_device_handle_win.cc:1046 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[29204:3600:0124/223240.238:ERROR:device_event_log_impl.cc(215)] [22:32:40.247] USB: usb_device_handle_win.cc:1046 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[29204:3600:0124/223240.238:ERROR:gpu_process_host.cc(985)] GPU process launch failed: error_code=18
[29204:3600:0124/223240.457:ERROR:gpu_process_host.cc(985)] GPU process launch failed: error_code=18
[29204:3600:0124/223240.598:ERROR:gpu_process_host.cc(985)] GPU process launch failed: error_code=18
[29204:3600:0124/223240.739:ERROR:gpu_process_host.cc(985)] GPU process launch failed: error_code=18
[29204:3600:0124/223240.865:ERROR:gpu_process_host.cc(985)] GPU process launch failed: error_code=18
[29204:3600:0124/223240.881:FATAL:gpu_data_manager_impl_private.cc(440)] GPU process isn't usable. Goodbye.
Error: unknown error: Chrome failed to start: crashed.
  (chrome not reachable)
  (The process started from chrome location C:\Program Files\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

How can I tell why this is crashing?

CodePudding user response:

This error message indicates that there is a problem with the GPU process launch. The error_code=18 suggests that the GPU process has crashed, which is causing the Chrome browser to crash as well. This is likely due to a compatibility issue between the version of Chrome and the GPU driver on your new laptop.

You could try updating the GPU driver on your new laptop to see if that resolves the issue.

Alternatively, you could try using a different version of Chrome or Chromedriver that is known to be compatible with the GPU driver on your new laptop. You should also check if there any other software running on your new laptop that could be conflicting with Selenium and Chrome.

Also, try running your script with --no-sandbox option to see if it works.

const chrome_options = new chrome.Options()
  .addArguments("--disable-gpu")
  .addArguments("--no-sandbox");
  • Related