Skip to content

chromium_arg parameter "--disable-features" passed to seleniumbase.Driver() being ignored. #2429

Closed
@agp22888

Description

@agp22888

I'm creating a driver instance with code:

dr = seleniumbase.Driver(uc=True,
                         proxy="user:pass@127.0.0.1:8090",
                         user_data_dir=user_data_dir,
                         extension_dir=ext_dirs,
                         agent=agent_string,
                         uc_subprocess=True,
                         chromium_arg='--disable-features=UserAgentClientHint')

https://httpbin.org/anything shows that --disable-features=UserAgentClientHint is ignored, since it shows Sec-Ch-* request headers:

  "headers": {
    ...
    "Sec-Ch-Ua": "\"Not_A Brand\";v=\"8\", \"Chromium\";v=\"120\"", 
    "Sec-Ch-Ua-Mobile": "?0", 
    "Sec-Ch-Ua-Platform": "\"Linux\"", 
    ...
  },

The same thing for browser launched with parameters chromium disable-features=UserAgentClientHint shows that there is no such headers sent with the request.

It seems that the problem is in function _set_chrome_options in seleniumbase/core/browser_launcher.py (line 1094 and so on):

if user_data_dir:
    chrome_options.add_argument(
        "--disable-features=OptimizationHintsFetching,Translate,"
        "OptimizationTargetPrediction,PrivacySandboxSettings4,"
        "DownloadBubble,DownloadBubbleV2"
    )
else:
    chrome_options.add_argument(
        "--disable-features=OptimizationHintsFetching,Translate,"
        "OptimizationTargetPrediction,DownloadBubble,DownloadBubbleV2"
    )

So, driver instance's ChromeOptions has double --disable-features arguments:

dr = seleniumbase.Driver(uc=True,
                         proxy="user:pass@127.0.0.1:8090",
                         user_data_dir=user_data_dir,
                         extension_dir=ext_dirs,
                         agent=agent_string,
                         uc_subprocess=True,
                         chromium_arg='--disable-features=UserAgentClientHint')
print('\n'.join(dr.options.arguments))

Output:

--window-size=1280,840
...
--disable-features=UserAgentClientHint
...
--disable-features=OptimizationHintsFetching,Translate,OptimizationTargetPrediction,PrivacySandboxSettings4,DownloadBubble,DownloadBubbleV2
...

As a test, i've added UserAgentClientHint to disabled features in browser_laucher.py:

    if user_data_dir:
        chrome_options.add_argument(
            "--disable-features=OptimizationHintsFetching,Translate,"
            "OptimizationTargetPrediction,PrivacySandboxSettings4,"
            "DownloadBubble,DownloadBubbleV2,UserAgentClientHint"
        )
    else:
        chrome_options.add_argument(
            "--disable-features=OptimizationHintsFetching,Translate,"
            "OptimizationTargetPrediction,DownloadBubble,DownloadBubbleV2,UserAgentClientHint"
        )

and everything works as it should.

Metadata

Metadata

Assignees

Labels

bugUh oh... Something needs to be fixed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions