Skip to content

window.screen width and height values aren't changed to the profile's emulation values #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nradosevic opened this issue Mar 16, 2023 · 7 comments
Labels
bug Something isn't working dev Development for dev branch enhancement New feature or request Todo Changes needed, but not yet implemented

Comments

@nradosevic
Copy link

nradosevic commented Mar 16, 2023

Describe the bug
window.screen width and height values aren't changed to the profile's emulation values. Might actually be undetected chromedriver's fault because it doesn't support mobileEmulation experimental option, but anyway would be really meaningful to find a workaround

To Reproduce
Run the code from the example, using any profile (Desktop or Android) and check the window.screen values in dev tools

Expected behavior or error-message
window.screen width and height values should get the value

Environment (please complete the following information):

  • MacOS
  • Monterey
  • Google Chrome
  • Selenium-Profiles Version 2.2.5
@nradosevic
Copy link
Author

Actually, it seems that this line return self.driver.execute_cdp_cmd('Emulation.setDeviceMetricsOverride', emulation) should do it, for some reason it doesn't

@nradosevic
Copy link
Author

nradosevic commented Mar 16, 2023

When I execute this directly on the driver instance after mydriver.start finishes it changes those values

driver.execute_cdp_cmd("Emulation.setDeviceMetricsOverride", {
    "deviceScaleFactor": 3,
    "width": 390,
    "height": 844,
    "screenWidth": 390,
    "screenHeight": 844,
    "mobile": True
})

@kaliiiiiiiiii
Copy link
Owner

kaliiiiiiiiii commented Mar 16, 2023

Actually, it seems that this line return self.driver.execute_cdp_cmd('Emulation.setDeviceMetricsOverride', emulation) should do it, for some reason it doesn't

Wonder why it doesn't work. Stack trace should be driver.py==>scripts/profiles.py==>scripts/cdp_tools.py

Noticed some time ago, that after initializing the driver, it needs to wait some time bevore executing all the cdp_cmd commands. Solved that in driver.py by just getting some url.

EDIT:
Couldn't reproduce the issue. Even when using uc_driver=True and profiles.Android, the window.screen size properties in javascript are correct in my case:
image

@nradosevic Or do you mean, that the window on your Desktop is to big? I that case, yes, that's a bug, undetected-chromedriver#1100 in undetected-chromedriver at undetected_chromedriver/init.py#L379, because it adds some arguments by default.

@kaliiiiiiiiii kaliiiiiiiiii pinned this issue Mar 17, 2023
@kaliiiiiiiiii kaliiiiiiiiii unpinned this issue Mar 17, 2023
@nradosevic
Copy link
Author

I am puzzled how window.screen values are correct in your case. In my case I found a problem. Problem is that the emulation object in the default profiles is lacking those options: screenWidth, screenHeight, because they are needed to set the correct screen size when using driver.execute_cdp_cmd("Emulation.setDeviceMetricsOverride"

After adding those to the default profiles, it works for me too

@kaliiiiiiiiii
Copy link
Owner

kaliiiiiiiiii commented Mar 20, 2023

I am puzzled how window.screen values are correct in your case. In my case I found a problem. Problem is that the emulation object in the default profiles is lacking those options: screenWidth, screenHeight, because they are needed to set the correct screen size when using driver.execute_cdp_cmd("Emulation.setDeviceMetricsOverride"

After adding those to the default profiles, it works for me too

Oh I see
In that case, I'll implement following in some time:

  • If the keys don't exist in profile, copy fom height and with

Also, this likely doesn't have anything to do with with undetected-chromedriver. I assuem it's some inconsistency in in the chrome-developer-protocoll implementation of chromedriver nur or Chromium

@kaliiiiiiiiii kaliiiiiiiiii added bug Something isn't working enhancement New feature or request dev Development for dev branch Todo Changes needed, but not yet implemented labels Mar 20, 2023
@AlexPaiva
Copy link

I am puzzled how window.screen values are correct in your case. In my case I found a problem. Problem is that the emulation object in the default profiles is lacking those options: screenWidth, screenHeight, because they are needed to set the correct screen size when using driver.execute_cdp_cmd("Emulation.setDeviceMetricsOverride"
After adding those to the default profiles, it works for me too

Oh I see In that case, I'll implement following in some time:

* If the keys don't exist in `profile`, copy fom `height` and `with`

Also, this likely doesn't have anything to do with with undetected-chromedriver. I assuem it's some inconsistency in in the chrome-developer-protocoll implementation of chromedriver nur or Chromium

Not sure because I remember on UC discussions people complaining regarding this, but might be as you said so both packages suffer from this

@kaliiiiiiiiii
Copy link
Owner

I am puzzled how window.screen values are correct in your case. In my case I found a problem. Problem is that the emulation object in the default profiles is lacking those options: screenWidth, screenHeight, because they are needed to set the correct screen size when using driver.execute_cdp_cmd("Emulation.setDeviceMetricsOverride"
After adding those to the default profiles, it works for me too

Oh I see In that case, I'll implement following in some time:

  • If the keys don't exist in profile, copy fom height and with

Also, this likely doesn't have anything to do with with undetected-chromedriver. I assuem it's some inconsistency in in the chrome-developer-protocoll implementation of chromedriver nur or Chromium

Implemented with 6f25990

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dev Development for dev branch enhancement New feature or request Todo Changes needed, but not yet implemented
Projects
None yet
Development

No branches or pull requests

3 participants