seleniumbase / SeleniumBase

📊 Python's all-in-one framework for web crawling, scraping, testing, and reporting. Supports pytest. UC Mode provides stealth. Includes many tools.
https://seleniumbase.io
MIT License
4.45k stars 908 forks source link

get_window_size returns incorrect window size #2852

Closed SpiritXmas closed 2 weeks ago

SpiritXmas commented 2 weeks ago

I'm using the raw driver context, and attempting to call driver.get_window_size. On my main computer it returns the correct information, 1920x1080 however on my laptop it consistently returns {'width': 1536, 'height': 960} instead of the actual resolution being 1920x1200.

No special preparation is needed, although I do use uc = True parameter.

driver = Driver(uc = True)
driver.get("https://www.google.com")
print(driver.get_window_size())

I have a pause inbetween the get and window size call where I can full screen and maximize the window.

mdmintz commented 2 weeks ago

driver.get_window_size() comes from raw Selenium, not SeleniumBase:

https://github.com/SeleniumHQ/selenium/blob/f49c6157043e095c5f78f290cf8ab3e365090561/py/selenium/webdriver/remote/webdriver.py#L864

For future reference, please include the full script next time. You didn't specify how the window was maximized (manual vs automated), or how much of a pause there was between the actions.

SpiritXmas commented 2 weeks ago

Pause and the specification of if I manually or automatically maximized the window wasn't specified as it happened with in both cases. So do you recommend I create a git issue within the raw selenium, to get this fixed?

mdmintz commented 2 weeks ago

You could try reaching out to the Selenium Team, although the most-likely scenario is that they won't do anything about that, given that you weren't using pure selenium when reaching it.

It's also possible that you weren't on the window that you thought you were on when you got the window size. UC Mode will sometimes open URLs in new windows to avoid detection. And a maximized window can lead to detection: https://github.com/seleniumbase/SeleniumBase/discussions/2752#discussioncomment-9385844 (That's why you should never be maximizing a window anyway in UC Mode.)

SpiritXmas commented 2 weeks ago

Understood, more detection vectors when maximizing and playing around with the window. However, element locations on the window are provided assuming you are in a window mode. Should I instead just implement an offset based of how large the search bar is and subtract that from my MouseMove operations? Also I've noticed that the window is never center or in full screen to begin with, what can I safely do to put the window in full screen (not actually maximized into it, just so it covers the majority of my screen).

mdmintz commented 2 weeks ago

I would experiment around and see what works. I've been working on UC Mode updates that would avoid having to go around in all these loops trying to bypass detection via pyautogui.

SpiritXmas commented 2 weeks ago

I currently use pyautogui within my project to move mouse, click and scroll just to prevent any potential detection vectors. However, how would I go about experimenting what works in terms of detectability and window formatting. I found a really good detection script written in javascript, that I can share with you over email however it does not detect UC=True, so there isn't much more I can do.

mdmintz commented 2 weeks ago

If it doesn't detect uc=True, then it looks like UC Mode is working. I would suggest trying on actual CAPTCHA sites (eg. Pixelscan, Cloudflare, etc.) to make sure things are fully good.

SpiritXmas commented 2 weeks ago

Alright thanks, one last question I had. Can a browser detect if you turn off your monitor in any way, for instance if I'm botting on a website, with UC Mode, and for prolonged periods of time and i want to turn off my monitor. Would my mouse movement functions (pyautogui) and just the actual integrity of an undetected browser remain? Or does it open up more potential detection vetors