How can I prevent Chrome from crashing through Selenium? - node.js

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?

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

xwininfo -tree always shows 0 children on lambda container

As the title states, I'm finding that whenever I issue xwininfo -tree on a container running Ubuntu in lambda, there are never child screens, though when I run the same container locally it works fine (listing all the windows used by said application). The issue must lie somewhere from application start and it registering with the X server. Does anyone have any insights here as to what could be going on, or how I can get this to work?
To attach some code to this problem, the gist is essentially:
# Start Xvfb
Xvfb $DISPLAY -screen 0 1920x1080x24 -nolisten tcp -nolisten unix &
# Open Visual Studio Code (just as an example application)
code .
# List all windows
xwininfo -root -tree
As mentioned, locally xwininfo produces something like this:
Root window id: 0x50d (the root window) (has no name)
Parent window id: 0x0 (none)
6 children:
0x600006 "Code": ("code" "Code") 800x600+560+240 +560+240
0x600002 "Get Started - src - Visual Studio Code": ("code" "Code") 1024x768+448+156 +448+156
0x600003 (has no name): () 1x1+0+0 +0+0
0x800003 "code": ("code" "Code") 200x200+0+0 +0+0
1 child:
0x800004 (has no name): () 1x1+-1+-1 +-1+-1
0x800001 "code": ("code" "Code") 10x10+10+10 +10+10
0x600000 "Chromium clipboard": () 10x10+-100+-100 +-100+-100
but in lambda, the output only shows the root window, with no children:
Root window id: 0x50d (the root window) (has no name)
Parent window id: 0x0 (none)
0 children.
What could be going on here? Why are my application windows not appearing in the output of xwininfo -tree?
This is a sort of half answer in that I'm unable to definitely solve the root cause of the original question, but it's an answer that explains tells why Visual Studio Code fails to launch (and does not appear in xwininfo). If you pass the --verbose flag to Visual Studio code when it launches, in a Lambda environment, you'll get output like this:
prctl(PR_SET_NO_NEW_PRIVS) failed
prctl(PR_SET_NO_NEW_PRIVS) failed
Unable to create argv.json configuration file in /home/sbx_user1051/.vscode/argv.json, falling back to defaults (Error: ENOENT: no such file or directory, mkdir \'/home/sbx_user1051/.vscode\')
[94:1213/213845.593392:ERROR:bus.cc(398)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")
[94:1213/213845.593463:ERROR:bus.cc(398)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")
[94:1213/213845.626853:ERROR:bus.cc(398)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
[94:1213/213845.626936:ERROR:bus.cc(398)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
[94:1213/213845.671433:WARNING:bluez_dbus_manager.cc(248)] Floss manager not present, cannot set Floss enable/disable.
[94:1213/213845.671514:ERROR:gpu_process_host.cc(974)] GPU process launch failed: error_code=1002
[94:1213/213845.671522:WARNING:gpu_process_host.cc(1282)] The GPU process has crashed 1 time(s)
[94:1213/213845.672685:ERROR:gpu_process_host.cc(974)] GPU process launch failed: error_code=1002
[94:1213/213845.672708:WARNING:gpu_process_host.cc(1282)] The GPU process has crashed 2 time(s)
[94:1213/213845.688115:ERROR:gpu_process_host.cc(974)] GPU process launch failed: error_code=1002
[94:1213/213845.688143:WARNING:gpu_process_host.cc(1282)] The GPU process has crashed 3 time(s)
[94:1213/213845.689768:ERROR:gpu_process_host.cc(974)] GPU process launch failed: error_code=1002
[94:1213/213845.689790:WARNING:gpu_process_host.cc(1282)] The GPU process has crashed 4 time(s)
[94:1213/213845.690646:ERROR:gpu_process_host.cc(974)] GPU process launch failed: error_code=1002
[94:1213/213845.690662:WARNING:gpu_process_host.cc(1282)] The GPU process has crashed 5 time(s)
[94:1213/213846.470027:ERROR:gpu_process_host.cc(974)] GPU process launch failed: error_code=1002
[94:1213/213846.470054:WARNING:gpu_process_host.cc(1282)] The GPU process has crashed 6 time(s)
[94:1213/213846.471084:ERROR:gpu_process_host.cc(974)] GPU process launch failed: error_code=1002
[94:1213/213846.471101:WARNING:gpu_process_host.cc(1282)] The GPU process has crashed 7 time(s)
[94:1213/213846.471742:ERROR:gpu_process_host.cc(974)] GPU process launch failed: error_code=1002
[94:1213/213846.471761:WARNING:gpu_process_host.cc(1282)] The GPU process has crashed 8 time(s)
[94:1213/213846.472344:ERROR:gpu_process_host.cc(974)] GPU process launch failed: error_code=1002
[94:1213/213846.472357:WARNING:gpu_process_host.cc(1282)] The GPU process has crashed 9 time(s)
[94:1213/213846.472371:FATAL:gpu_data_manager_impl_private.cc(450)] GPU process isn\'t usable. Goodbye.
The problem is that even though Visual Studio Code is built on Electron / Chromium, it doesn't seem to support a --headless option yet (as apposed to something like Chrome, which is possible to launch in a Lambda function with some careful tinkering). So, due to the restrictions of the Lambda environment, for now, it seems that it's not possible to Launch Visual Studio code in a lambda environment. (I know there is the web version, but I don't want this). Would have been nice as a single instance per call would have been perfect for what I was trying to accomplish. I'm going to move on to some other backend infrastructure to do what I want...

USB: usb_device_handle_win.cc:1048 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)

I am making an automatic youtube viewer software.
BUT when I run the code I get an error
[7856:3848:0628/112843.870:ERROR:device_event_log_impl.cc(214)] [11:28:43.869] USB: usb_device_handle_win.cc:1048 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
[7856:3848:0628/112843.871:ERROR:device_event_log_impl.cc(214)] [11:28:43.871] USB: usb_device_handle_win.cc:1048 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
PS C:\Users\Long\he\sesison4> [7856:1700:0628/112941.446:ERROR:util.cc(127)] Can't create base directory: C:\Program Files\Google\GoogleUpdater
[7236:5288:0628/113041.419:ERROR:gpu_init.cc(486)] Passthrough is not supported, GL is disabled, ANGLE is
Here is my code python
self.pushButton_2.clicked.connect(self.code)
def code(self):
P = self.lineEdit_3.text()
U = open(P, mode = "r")
L = U.readline()
driver = webdriver.Chrome(executable_path='C:\Chormedriver\chromedriver.exe')
driver.set_window_size(700,800)
driver.get(L)
time.sleep(3000)
Hope everybody help please.

Running Test in Docker using Chrome and Chromedriver in Python

I am trying to run some tests in Docker using chromedriver and chrome in Python.
chrome_options = Options()
chrome_options.add_argument('--headless')
However, I used the add_argument('--headless') I have a returning error : Engine not supported, Your version currently configured does not support this"
But, if I do not used the add_argument('--headless'), I received this error:
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally. (unknown error: DevToolsActivePort file doesn't exist) (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Any tip?

Failed to read descriptor from node connection in Protractor with Typescript

When I'm trying to fetch the values from the database, I have received the below error. But the DB connection was a success.
ERROR:device_event_log_impl.cc(211)] [08:19:41.497] USB: usb_device_handle_win.cc:1020 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)

Adb protocol fault (couldn't read status)

I am using Mac OSX El Captain with Android Studio 2.2.
Android Studio start to don't show Android devices suddenly. I try to kill adb server and start it again and this errors appear on terminal.
List of devices attached
daemon not running. starting it now on port 5037 *
adb E 1165 84563 usb_osx.cpp:307] Could not clear pipe stall both ends: e0004051
adb E 1165 84563 usb_osx.cpp:289] Could not find device interface
daemon started successfully *
When I try to kill server twice for understanding the issue it gives this error message:
error: protocol fault (couldn't read status): Connection reset by peer
Try restarting your Mac and devices. I ran into a similar error and restart got rid of it :)

Resources