Enhancements for Windows 11: Remote Debugging Setup for Chrome
Enhancements for Using on Windows 11
Changes Made
- Update Configuration File:
- Updated
config/config.tomlto add settings for using Chrome in remote debugging mode. - Set
cdp_urltohttp://localhost:9222to utilize the remote debugging port.
- Updated
# Optional configuration for specific browser settings
[browser]
# Whether to run the browser in headless mode (default: false)
headless = false
# Disable browser security features (default: true)
disable_security = true
# Chrome DevTools Protocol URL - URL for connecting to manually launched Chrome
cdp_url = "http://localhost:9222"
# Path to the Chrome executable
chrome_instance_path = "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"
# Browser arguments for launching in remote debugging mode
extra_chromium_args = [
"--user-data-dir=C:\\Users\\\\username\\AppData\\Local\\Google\\Chrome\\User Data",
"--profile-directory=profile_name",
"--remote-debugging-port=9222",
"--no-first-run",
"--no-default-browser-check",
]
Create Helper Script:
- Added
start_chrome_debug.py, a script to launch Chrome in remote debugging mode.
- Added
Update Test Script:
- Updated
test_browser.pyto perform tests for verifying browser connection and operations.
- Updated
Usage
1. Launch Chrome in Remote Debugging Mode
First, run start_chrome_debug.py to start Chrome in remote debugging mode.
python start_chrome_debug.pyKeep the terminal window open after running this command. Chrome will launch with remote debugging enabled on port 9222.
2. Run the Main Application
In a separate terminal window, run the main application.
python run_flow.pyrun_flow.py executes the main flow of OpenManus and accepts user input.
3. Run the Test Script (Optional)
To verify browser connection and operations, you can also run test_browser.py.
python test_browser.pyThis script navigates to Google's homepage and retrieves the page title as a test.
Notes
Since Chrome is launched in remote debugging mode, it is recommended to close any existing Chrome processes before running start_chrome_debug.py. Ensure that the settings in config/config.toml are correct.
Created Files
start_chrome_debug.py
import subprocess
import sys
import time
import os
def start_chrome_debug():
"""Launch Chrome with a remote debugging port"""
print("Starting Chrome in remote debugging mode...")
# Path to Chrome and the user data directory
chrome_path = "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"
user_data_dir = "C:\\Users\\[usernmae]\\AppData\\Local\\Google\\Chrome\\User Data"
# Terminate existing Chrome processes (optional)
# Note: This may end your current session.
"""
try:
subprocess.run(["taskkill", "/f", "/im", "chrome.exe"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
time.sleep(1)
except Exception as e:
print(f"Failed to terminate Chrome processes: {e}")
"""
# Launch Chrome in remote debugging mode
try:
chrome_process = subprocess.Popen(
[
chrome_path,
f"--user-data-dir={user_data_dir}",
"--profile-directory=default",
"--remote-debugging-port=9222",
"--no-first-run",
"--no-default-browser-check",
]
)
print("Chrome started (PID: {})".format(chrome_process.pid))
print("CDP endpoint: http://localhost:9222")
print("Keep this window open.")
print("Press Ctrl+C to exit.")
# Wait for the process to exit
chrome_process.wait()
except KeyboardInterrupt:
print("\nTerminating Chrome...")
chrome_process.terminate()
except Exception as e:
print(f"An error occurred: {e}")
return 1
return 0
if __name__ == "__main__":
sys.exit(start_chrome_debug())
test_browser.py
import asyncio
import os
import subprocess
import time
from browser_use import Browser, BrowserConfig
from browser_use.browser.context import BrowserContext, BrowserContextConfig
async def main():
print("Starting browser test")
# Check if Chrome is already running
try:
# Manually start Chrome (with remote debugging port)
chrome_path = "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"
user_data_dir = "C:\\Users\\[username]\\AppData\\Local\\Google\\Chrome\\User Data"
print("Manually launching Chrome...")
chrome_process = subprocess.Popen(
[
chrome_path,
f"--user-data-dir={user_data_dir}",
"--profile-directory=default",
"--remote-debugging-port=9222",
"--no-first-run",
"--no-default-browser-check",
]
)
# Wait for Chrome to start
print("Waiting for Chrome to launch...")
time.sleep(5)
# Initialize the browser with custom configuration
browser_config = BrowserConfig(
headless=False,
disable_security=True,
cdp_url="http://localhost:9222", # Connect to the manually started Chrome
)
try:
print("Initializing the browser...")
browser = Browser(browser_config)
print("Creating a new context...")
context = await browser.new_context(BrowserContextConfig())
print("Navigating to Google...")
await context.navigate_to("https://www.google.com")
print("Retrieving the page title...")
title = await context.execute_javascript("document.title")
print(f"Page title: {title}")
# Retrieve current state
print("Getting the current browser state...")
state = await context.get_state()
print(f"Current URL: {state.url}")
print(f"Number of tabs: {len(state.tabs)}")
# Retrieve clickable elements
print("Interactive elements:")
if hasattr(state, "element_tree") and state.element_tree:
print(state.element_tree.clickable_elements_to_string())
print("Closing the browser...")
await browser.close()
print("Test completed!")
return True
except Exception as e:
print(f"An error occurred: {e}")
return False
finally:
# Terminate Chrome
try:
chrome_process.terminate()
except:
pass
except Exception as e:
print(f"Error launching Chrome: {e}")
return False
if __name__ == "__main__":
asyncio.run(main())
Source: FoundationAgents/OpenManus