Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web-ui can't take control of User's chrome browser. connect_over_cdp: connect ECONNREFUSED ::1:9222 #409

Open
LuD1161 opened this issue Mar 17, 2025 · 7 comments

Comments

@LuD1161
Copy link

LuD1161 commented Mar 17, 2025

I am using google chrome canary and getting the same error -

ERROR    [browser] Failed to start a new Chrome instance.: BrowserType.connect_over_cdp: connect ECONNREFUSED ::1:9222
Call log:
  - <ws preparing> retrieving websocket url from http://localhost:9222

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.

Version :

  1. Chrome : 136.0.7073.0 (Official Build) canary (arm64)
  2. browser-use : browser-use==0.1.37
  3. web-ui - latest pull, 17th March - 33ca5e0bbb5c147c7fbbde15de9434d98209b013

Earlier it was able to get the chrome browser, but not after this pull.

@warmshao
Copy link
Collaborator

  1. You need to close all chrome windows and check whether port 9222 is occupied?
  2. You can try to use the latest code, and uv pip install -r requirements.txt, now it supports browser-use==0.1.40

@LuD1161
Copy link
Author

LuD1161 commented Mar 18, 2025

Hey @warmshao 👋
Thanks for the quick reply.

I've updated the code to track the main branch of web-ui.

Image

And also checked for port 9222 being occupied by any other service. That's also not true.

It still opens multiple chrome canary windows but is not able to connect to CDP.

Image

I am attaching the log here, in case that helps -

Stacktrace:
Traceback (most recent call last):
  File "/Users/aseemshrey/Repos/web-ui/.venv/lib/python3.11/site-packages/browser_use/browser/browser.py", line 171, in _setup_browser_with_instance
    browser = await playwright.chromium.connect_over_cdp(
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aseemshrey/Repos/web-ui/.venv/lib/python3.11/site-packages/playwright/async_api/_generated.py", line 14793, in connect_over_cdp
    await self._impl_obj.connect_over_cdp(
  File "/Users/aseemshrey/Repos/web-ui/.venv/lib/python3.11/site-packages/playwright/_impl/_browser_type.py", line 174, in connect_over_cdp
    response = await self._channel.send_return_as_dict("connectOverCDP", params)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aseemshrey/Repos/web-ui/.venv/lib/python3.11/site-packages/playwright/_impl/_connection.py", line 67, in send_return_as_dict
    return await self._connection.wrap_api_call(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aseemshrey/Repos/web-ui/.venv/lib/python3.11/site-packages/playwright/_impl/_connection.py", line 528, in wrap_api_call
    raise rewrite_error(error, f"{parsed_st['apiName']}: {error}") from None
playwright._impl._errors.Error: BrowserType.connect_over_cdp: connect ECONNREFUSED 127.0.0.1:9222
Call log:
  - <ws preparing> retrieving websocket url from http://localhost:9222


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/aseemshrey/Repos/web-ui/src/agent/custom_agent.py", line 307, in step
    state = await self.browser_context.get_state()
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aseemshrey/Repos/web-ui/.venv/lib/python3.11/site-packages/browser_use/browser/context.py", line 676, in get_state
    session = await self.get_session()
              ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aseemshrey/Repos/web-ui/.venv/lib/python3.11/site-packages/browser_use/browser/context.py", line 302, in get_session
    return await self._initialize_session()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aseemshrey/Repos/web-ui/.venv/lib/python3.11/site-packages/browser_use/utils.py", line 36, in wrapper
    result = await func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aseemshrey/Repos/web-ui/.venv/lib/python3.11/site-packages/browser_use/browser/context.py", line 238, in _initialize_session
    playwright_browser = await self.browser.get_playwright_browser()
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aseemshrey/Repos/web-ui/.venv/lib/python3.11/site-packages/browser_use/browser/browser.py", line 96, in get_playwright_browser
    return await self._init()
           ^^^^^^^^^^^^^^^^^^
  File "/Users/aseemshrey/Repos/web-ui/.venv/lib/python3.11/site-packages/browser_use/utils.py", line 36, in wrapper
    result = await func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aseemshrey/Repos/web-ui/.venv/lib/python3.11/site-packages/browser_use/browser/browser.py", line 104, in _init
    browser = await self._setup_browser(playwright)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aseemshrey/Repos/web-ui/.venv/lib/python3.11/site-packages/browser_use/browser/browser.py", line 217, in _setup_browser
    return await self._setup_browser_with_instance(playwright)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aseemshrey/Repos/web-ui/.venv/lib/python3.11/site-packages/browser_use/browser/browser.py", line 178, in _setup_browser_with_instance
    raise RuntimeError(
RuntimeError:  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.

DEBUG    [browser_use] --handle_step_error (agent) Execution time: 0.00 seconds
DEBUG    [browser_use] --step Execution time: 24.28 seconds
ERROR    [src.agent.custom_agent] ❌ Stopping due to 3 consecutive failures
WARNING  [agent] No history to create GIF from
DEBUG    [browser] Closing browser context
DEBUG    [browser_use] --close Execution time: 0.00 seconds

Please let me know, how can I fix this.

@LuD1161
Copy link
Author

LuD1161 commented Mar 18, 2025

It works when I start a chrome canary browser in remote debugging mode already, like this - "/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary" --remote-debugging-port=9222 --no-first-run --no-default-browser-check --user-data-dir=/tmp/ch1

So web-ui hooks to this browser's debugging port.

@warmshao
Copy link
Collaborator

It works when I start a chrome canary browser in remote debugging mode already, like this - "/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary" --remote-debugging-port=9222 --no-first-run --no-default-browser-check --user-data-dir=/tmp/ch1

So web-ui hooks to this browser's debugging port.

yes, you need to start a chrome browser in remote debugging mode

@LuD1161
Copy link
Author

LuD1161 commented Mar 19, 2025

How do I pass this --remote-debugging-port option when I have the CHROME_PATH set in environment variables in the .env file ? Earlier I just had the path for chrome in .env file and it automatically started chrome when the agent was run and hooked to it.

Now that's failing. Here's the .env file :

.
.
.
# Chrome settings
CHROME_PATH="/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary"
CHROME_USER_DATA=
CHROME_DEBUGGING_PORT=9222
CHROME_DEBUGGING_HOST=localhost
# Set to true to keep browser open between AI tasks
CHROME_PERSISTENT_SESSION=false

# Display settings
# Format: WIDTHxHEIGHTxDEPTH
RESOLUTION=1920x1080x24
# Width in pixels
RESOLUTION_WIDTH=1920
# Height in pixels
RESOLUTION_HEIGHT=1080

# VNC settings
VNC_PASSWORD=youvncpassword

@garfield5200
Copy link

I got a same problems.

@LuD1161
Copy link
Author

LuD1161 commented Mar 22, 2025

I am on Mac version Sequoia 15.3.2 (24D81).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants