SeleniumBase icon indicating copy to clipboard operation
SeleniumBase copied to clipboard

UC Mode: 24-30 MB of idle traffic per browser start from the Optimization Guide

Open alkaz-nodemaven opened this issue 3 months ago • 3 comments

What happens

A browser started by SeleniumBase and left completely idle downloads 24-30 MB from optimizationguide-pa.googleapis.com before it has navigated anywhere. It is the Optimization Guide fetching an on-device model. Nothing in a test reads it, and a fresh profile pays it again on every start.

CONTRIBUTING says to open an issue rather than a PR, so this is an issue. The one-line change is at the bottom and I have it on a branch if you would rather have a PR.

Reproduction

seleniumbase 4.52.4 at 58796978, Windows 10, Chrome 149.0.7827.201, Python 3.11. Bytes are counted at a loopback CONNECT proxy and attributed per authority, so this is the socket rather than anything reported inside the browser.

driver = Driver(browser="chrome", headless=True, proxy=proxy, uc=True)
driver.get("about:blank")
time.sleep(60)          # nothing else happens
driver.quit()
total over 60 s optimizationguide-pa.googleapis.com
4.52.4, run 1 24.35 MB 24.27 MB
4.52.4, run 2 30.21 MB 30.09 MB
with the change below, run 1 0.10 MB absent
with the change below, run 2 0.10 MB absent

The remaining 0.10 MB is www.google.com, mtalk.google.com, android.clients.google.com, accounts.google.com, update.googleapis.com and clients2.google.com, all under 30 KB each.

Why the flags already there do not cover it

browser_launcher.py disables OptimizationHintsFetching, OptimizationTargetPrediction and OptimizationGuideModelDownloading, and all three are genuinely on the command line - I read them off the running process rather than off the options object:

--disable-features=OptimizationHintsFetching,Translate,ComponentUpdater,
OmniboxUIFeedback,OmniboxPopupShortcut,OptimizationTargetPrediction,
OptimizationGuideModelDownloading,...

They are sub-features of a service that is still constructed. OptimizationHints is the master switch, and it is the one name missing. --disable-background- networking is also already on the command line and does not reach this either; disabling it alone still fetched 39.19 MB in a separate engine on this host.

The change

OptimizationHints added to included_disabled_features. Three sites carry the list:

  • seleniumbase/core/browser_launcher.py:2790 (Chrome)
  • seleniumbase/core/browser_launcher.py:4835 (Edge)
  • seleniumbase/undetected/cdp_driver/config.py:322 (CDP Mode)
included_disabled_features = []
included_disabled_features.append("OptimizationHints")      # <- added
included_disabled_features.append("OptimizationHintsFetching")

The numbers above are from the Chrome site patched in a checkout, not from chromium_arg, so it is the code path rather than a user-side override.

Notes

  • Not page-visible. I sampled 31 fingerprint probes with and without the flag on the same engine - the navigator prototype property list (83 names), all 1232 window own-property names, plugins, mimeTypes, WebGL vendor, renderer and extension list, userAgentData, Intl.resolvedOptions, screen metrics, PerformanceObserver.supportedEntryTypes - and they are identical. Patchright ships OptimizationHints in its own default list.
  • The fetch does not fire on every start. Seven of eight unflagged runs across engines fetched and one was quiet, so a single quiet run is not evidence. Each row above is one of two runs.

alkaz-nodemaven avatar Aug 25 '26 20:08 alkaz-nodemaven

You can always set that option via method arg: disable_features="OptimizationHints" or via command-line option when running your script: --disable-features=OptimizationHints.

It's deliberately not included as a default option because it causes Chromium 151+ to crash. More info on the crash: https://github.com/seleniumbase/SeleniumBase/issues/4393#issuecomment-4711386190

Separately, I noticed that you called driver.get(url) from UC Mode in your demo script: That keeps the instance in UC Mode, rather than starting CDP Mode. (UC Mode without CDP Mode is less stealthy, although staying in UC Mode may be necessary for you if you still want to use raw Selenium commands with basic stealth.)

mdmintz avatar Aug 25 '26 21:08 mdmintz

Thank you - that is the answer, and I should have found it myself. cb03afab removed exactly the line I proposed adding, so what I sent was a revert of your fix rather than a new suggestion. git log -L on that line would have shown it in ten seconds and I did not run it. Sorry for the noise.

Two things that may still be worth something to you.

I could not reproduce the crash on current 151. Every arm below started and reached a page. Chrome 151.0.7922.137, Ubuntu 24.04.4, kernel 6.8, headful under xvfb-run, SeleniumBase 4.51.12, each flagged arm paired with its own unflagged control in the same process:

engine headless headful
Driver(uc=True), disable_features="OptimizationHints" control ok, flag ok control ok, flag ok
zendriver 0.16.0 control ok, flag ok control ok, flag ok
botasaurus-driver 4.0.101 control ok, flag ok control ok, flag ok

Bare google-chrome --headless=new --disable-features=OptimizationHints --dump-dom about:blank also exits 0.

That is 12 of 12, but it is one platform and one build, and your report is from 2026-06-15 when 151 was new. A patch release fixing it, or the crash being Windows or macOS only, would both look exactly like this from where I am sitting, so I am not claiming it is gone. If you remember the build number or the OS you saw it on, I will go and reproduce it properly - I have the harness set up for it now, and I would rather have the real answer than my one negative result, because I have proposed this flag to two other projects and I need to know whether to withdraw it.

On the demo script - you are right, and it changes the numbers. I called driver.get(), so that measurement is UC Mode without CDP Mode, which is the weaker of the two and not what a user chasing stealth would run. The 24-30 MB figure is still socket-counted and still real for that configuration, but I should have measured CDP Mode as well before quoting it as "UC mode". I will redo it that way.

For anyone who finds this issue later: the option already exists and does not need a code change, per your answer - disable_features="OptimizationHints" as a method arg, or --disable-features=OptimizationHints on the command line, with the crash caveat above attached to it.

alkaz-nodemaven avatar Aug 25 '26 21:08 alkaz-nodemaven

The crash from before was with unbranded Chromium (not Google Chrome).

You can force the crash to happen like this:

from seleniumbase import Driver

driver = Driver(uc=True, use_chromium=True, disable_features="OptimizationHints")

print("Made it past startup!")  # Not reached if browser crashes in previous step

That's why OptimizationHints was removed from --disable-features default options. (But anyone can add it back via optional options, which is fine if not using unbranded Chromium.)

mdmintz avatar Aug 25 '26 21:08 mdmintz