1

I have the latest version of the drivers (chromedriver=2.44.609551), selenium package(3.141.0) and the (headless chrome=70.0.3538.110). (on windows)

I am opening multiple windows with the browser. Using firefox, my script is always fast. But on chrome, after switching to a window (with the page already loaded), when I try to get anything from the browser (like driver.page_source or any find_element), I get a 4s-ish delay.

Am I doing something wrong?

[driver.execute_script('window.open(arguments[0]);', url) for url in urls]
for window in driver.window_handles[1:]:
    driver.switch_to.window(window)
    driver.page_source                                #it takes 4s here
    driver.find_elements_by_class_name('class_name')  #regular speed here (fast)
    break

If i switch driver.page_source with driver.find_elements_by_class_name('class_name'), the first one will be always slow.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

1 Answers1

2

As you mentioned in your question GeckoDriver / Firefox combination is faster then ChromeDriver / Chrome at this point it is worth to mention that diferent browsers render the HTML DOM in a different way.

You can find a detailed discussion in Chrome & Firefox on Windows vs Linux (selenium)

Moreover, there had been a lot of discussion going around about the unpredictable CPU and Memory Consumption by Chrome Headless sessions.

As per the discussion Building headless for minimum cpu+mem usage the CPU + Memory usage can be optimized by:

  • Using either a custom proxy or C++ ProtocolHandlers you could return stub 1x1 pixel images or even block them entirely.
  • Chromium Team is working on adding a programmatic control over when frames are produced. Currently headless chrome is still trying to render at 60 fps which is rather wasteful. Many pages do need a few frames (maybe 10-20 fps) to render properly (due to usage of requestAnimationFrame and animation triggers) but we expect there are a lot of CPU savings to be had here.
  • MemoryInfra should help you determine which component is the biggest consumer of memory in your setup.
  • An usage can be:

    $ headless_shell --remote-debugging-port=9222 --trace-startup=*,disabled-by-default-memory-infra http://www.chromium.org
    
  • Chromium is always going to use as much resources as are available to it. If you want to effectively limit it's utilization, you should look into using cgroups

You can find a detailed discussion in Limit chrome headless CPU and memory usage

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352