browser-use: Chrome >= v136 no longer supports being driven over CDP while using the default `--user-data-dir` profile

Bug Description

It fails to connect to a Chrome profile but, It works properly with Chromium only LLM Model : AzureOpenAI

ERROR : INFO [agent] 📍 Step 1 ERROR [browser] ❌ Failed to start a new Chrome instance: BrowserType.connect_over_cdp: connect ECONNREFUSED ::1:9222 Call log:

ERROR [browser] Failed to initialize Playwright browser: To start chrome in Debug mode, you need to close all existing Chrome instances and try again otherwise we can not connect to the instance. ERROR [browser] ❌ Failed to create new browser session: To start chrome in Debug mode, you need to close all existing Chrome instances and try again otherwise we can not connect to the instance. (did the browser process quit?) WARNING [browser] ⚠️ Page load failed, continuing…

Reproduction Steps

One week ago the agent work as expected, I’m having issue with it since today :

  1. Launch code
  2. Run the following task : Visit google.com
  3. see error (above)

Code Sample

browser = Browser(
    config=BrowserConfig(
        chrome_instance_path='/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
        new_context_config=context_cfg,
        headless=False       # run in headful mode for debugging
    )
)

Version

Version: 0.1.41rc2

LLM Model

Other (specify in description)

Operating System

macOS 13.1

Relevant Log Output


About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 9
  • Comments: 29 (12 by maintainers)

Most upvoted comments

+1, I’m seeing the same issue

In case you don’t want to mess up with your file system, I got it running by providing the --user-data-dir argument through the extra_browser_args.

browser = Browser(
    config=BrowserConfig(
        browser_binary_path="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
        extra_browser_args=[
            "--user-data-dir=/Users/<YOUR_USERNAME>/Library/Application Support/Google/Chrome/Default",
        ]
    )
)

Note: You have to replace <YOUR_USERNAME> with your username. If you don’t know, what your username is, run the following command in a terminal window: whoami.

@maghazouani, exactly. In my case, I did something like this:

mkdir -p ~/tmp/user-data-dir
cp -r /Users/<username>/Library/Application\ Support/Google/Chrome/Default ~/tmp/user-data-dir/
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222 --user-data-dir=/Users/<username>/tmp/user-data-dir/

This got me today, too. Looks to be due to this change that rolled out in Chrome 136. You need to specify a custom --user-data-dir when using --remote-debugging-port now.

I am surprised that no one has come up with a simple solution to this yet. Add this flag --disable-features=DevToolsDebuggingRestrictions and voila … it works 😃.

An alternative is using chrome for testing, the --user-data-dir update apparently doesn’t affect these binaries. So far it works. https://developer.chrome.com/blog/chrome-for-testing

For Mac and Chrome > 136.0

browser = Browser(
    config=BrowserConfig(
        browser_binary_path="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
        extra_browser_args=[
            "--user-data-dir=remote-debug-profile",
        ],
        headless=False,
    )
)

This works fine. Note that it creates a directory called remote-debug-profile in the same directory as where the script is. As this is a new profile, it won’t have your logins; based on the Chrome link linked above this is very intentional.

A trick to get the logins to work is what @maghazouani mentioned above; you copy the default profile to the new directory; and then use the new directory

Or you can start fresh and open "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" --user-data-dir=remote-debug-profile from the same directory as the script and login to the websites you want to be logged into

ah brutal, this is going to cause us a lot of trouble. copying a user-data-dir is rough, they can be multiple gigabytes and then we’d just leave those duplicate files on the person’s system after browser-use exits?

Perhaps as a temporary workaround we can just create a symlink somewhere in a tmp dir pointing to the original user_data_dir, maybe that’s enough to trick chrome into thinking it’s a non-default location? Then later once we come up with a proper security strategy around importing live cookies we can improve this.

Hi I’m also affected by this,

Due to this recent change - https://developer.chrome.com/blog/remote-debugging-port 

–user-data-dir will no longer support pointing to any real profiles in Chrome Data Directory.

I have been using it like this prior to this change 
user-data-dir=f"{local_app_data}\Google\Chrome\User Data"

I’m trying to automate a browser session that i created by another application. 

If i specify a non default profile from Chrome Data Directory, it will not be able to automate that session created by the application as they will be using 2 separate profiles. 

The application opens up the default web browser.

I’ve tried using Chrome for Testing but it is not considered an actual web browser hence it does not actually open that browser. 

 I do not have any control on how the application opens the chrome.exe hence i won’t be able to pass in -remote-debugging-port arguments to connect to the particular session to automate it. 

Any suggestions on how can i work around this?

@JoeDo I tried that solution and didn’t worked, it does for you ?

I succeeded to make it work with this workaround on my side : duplicate the user profile with a different directory’ :

Create a new folder for debugging

mkdir -p ~/chrome-debug-profile

Copy everything from your Default profile into it

cp -R \
  ~/Library/"Application Support"/Google/Chrome/Default \
  ~/chrome-debug-profile/Default

I’ve tried various approaches, but I’m still unable to persist the Chrome user profile. Every time I run the automation, I’m prompted to log in again (e.g., for Gmail or other Google services).

Environment:

Machine: macOS

Browser: Google Chrome

Has anyone faced and resolved this issue? Any help would be appreciated.

I lied it doesn’t work

Interesting. Thanks for the reference! It did seem like its an issue on chrome and not browser-use…