selenium: [šŸ› Bug]: Message KeyError 'width' while trying to get_window_size() does not provide detailed information

What happened?

Image So from the user’s point of view, it is not clear on which side the error is, the webdriver itself or the remote web server.

How can we reproduce the issue?

It is hard to reproduce, but the remote web server used for the remote webdriver should be unreliable and return an error, as shown in the screenshot. In my case, it was BrowserStack Automate.

As requested in the comment: https://github.com/aikfiend/python-selenium-browserstack/tree/get-window-size-key-error

Please note that the code of the test provided does not reproduce the issue in 100% of cases, as the issue itself reproduces from time to time, depending on a remote web server. You may require hundreds or more retries.

In the period from 2025-03-11 to 2025-04-21, I was able to catch it 20 times running tests in 24/7 mode in Browserstack Automate. Commonly, it failed in Chrome and Safari on mobile devices.

Relevant log output

Let the sentry speak for itself

Operating System

Any

Selenium version

4.31.0 (trunk)

What are the browser(s) and version(s) where you see this issue?

Any

What are the browser driver(s) and version(s) where you see this issue?

Any

Are you using Selenium Grid?

No response

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 18 (11 by maintainers)

Commits related to this issue

Most upvoted comments

@aikfiend

And I’m already a bit tired of this chain

Same here.

from my point of view, it is better to provide a consistently reproducible issue with the session capabilities and PoC code, where anyone can get as many logs as they want.

Your reproduction code requires Browserstack credentials. I don’t work for Browserstack… I’ve never used Browserstack… I know nothing about Browserstack… I can’t run your code. All I am asking for is a simple reproducible example that I can run. If you can’t provide that, I would at least need logs to look at. I don’t fully understand the issue you are having, so I can’t fix it.

I prefer to write code.

If you want to provide a fix, I will review your code. Otherwise, I don’t like the tone of your complaints and will not be looking further into this… maybe somebody else will.

Oh flashback… When I started using Selenium/.NET within Browserstack as a browser provider, I developed simple test. But I didn’t put authentication token for Browserstack in my test. What, do you think, happened?.. Test was green!!! I am not kidding, it was literally green, meaning it successfully launched remote browser and navigated to website. I sniffed traffic, and observed that BS responded properly with Unauthenticated status, but for selenium it is not important.

Then I went through Selenium source code and observed, that bindings (probably all) don’t even validate HTTP Response Status Code. Surprise!

https://github.com/SeleniumHQ/selenium/pull/10807 - this is my beginning of contribution.

@cgoldberg we should treat unsuccessful http status code as error and raise exception in any case. Specification explicitly says about it: https://www.w3.org/TR/webdriver2/#errors