This guide solves one specific task: configuring Chrome so an AI agent can open websites, click buttons, fill in forms, and read results on its own — without manual browser control. It works on Windows 10/11, macOS, and Linux with Chrome/Chromium installed. All you need is a terminal, Python, and an API key for any LLM (for example, OpenAI or a local model). We use a Playwright + Chrome DevTools Protocol (CDP) combo — CDP is the protocol that lets external programs send commands to the browser.
pip install playwright
playwright install chromium
chrome --remote-debugging-port=9222 --user-data-dir=/tmp/chrome-debug
python connect.py
Details and verification are in the steps below.

chrome://version page).Example: on the chrome://version page you'll see a string like 126.0.6478.126. Write it down — if something goes wrong, the version number makes it much easier to search for a fix.

Playwright is a browser automation tool that works with Chrome over the CDP protocol. Open a terminal and run:
pip install playwrightExpected result: at the end you'll see a line like Successfully installed playwright-1.4x.x. If pip isn't found, check that Python is installed correctly (the python --version command).
Example: on macOS with Python 3.11 this command takes 30–60 seconds and installs the package into the system site-packages folder.
Next you need to download the separate Chromium inside Playwright — that's the engine the agent will actually use:
playwright install chromiumExpected result: a 100% download progress bar and a message saying the install finished. This is a separate browser; it doesn't conflict with your regular Chrome.
Why it works: Playwright doesn't touch your personal Chrome profile; it launches a clean engine — automation is safer and the outcome is predictable.
The agent has to connect to the browser over a port. Close Chrome and start it with this command:
chrome --remote-debugging-port=9222 --user-data-dir=/tmp/chrome-debugchrome: C:\Program Files\Google\Chrome\Application\chrome.exe.--user-data-dir= creates a separate profile so your passwords and bookmarks stay untouched.Expected result: a regular Chrome window opens, and the terminal shows a line like DevTools listening on ws://127.0.0.1:9222/devtools/browser/....
Example: open http://localhost:9222/json in any browser — you'll see a JSON list of open tabs. That means the port is working.
Create a file connect.py with this content:
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
# Connect to the already running Chrome without restarting it
browser = p.chromium.connect_over_cdp("http://localhost:9222")
page = browser.contexts[0].pages[0] # take the first open tab
page.goto("https://example.com")
page.click("a") # click the first link
print("Title:", page.title())
browser.close()Run it with python connect.py.
Expected result: the Chrome tab navigates to example.com, the click happens, and the terminal prints the page title. This is where automation begins.
Why it works: connect_over_cdp talks to port 9222 and finds the open tabs — you don't need to spin up the browser again every time.
To let the neural network control the browser, give it a set of functions: open a page, click, type text, read the content. In code this looks like a list of tools the LLM calls when answering. The detailed scheme for turning a regular LLM chat into a full-fledged agent is described in a separate guide.
Expected result: the agent gets an array of available actions and decides on its own which one to call — for example, "go to a page" → page.goto(), "submit a form" → page.click("button[type=submit]").
Give the agent a real task: "Open a search engine, type the query, print the first result to the console." Run the script and watch the Chrome tab.
Expected result: the browser performs all the actions by itself and the agent prints the answer — without your involvement. If anything crashes, jump to the troubleshooting section below.

1. Connection refused on localhost:9222. Symptom: the script throws an exception when started, Chrome doesn't respond. Fix: make sure Chrome is running with the --remote-debugging-port=9222 flag (the port isn't opened in normal mode). If the port is taken by another process, run lsof -i :9222 on macOS/Linux or netstat -ano | findstr 9222 on Windows and switch to another port, e.g. 9333.
2. Target page, context or browser has been closed. Symptom: the script worked partially and broke off. Cause — the computer went to sleep or the tab was closed manually. Fix: disable automatic sleep for the duration of the test and add reconnection to your code via try/except with a repeated connect_over_cdp call.
3. Playwright can't find the installed engine. Symptom: a message like Executable doesn't exist. Fix: run playwright install chromium again — the download may have been interrupted on the first run. Check write permissions for your user profile folder.
Do I need Python, or can I automate with JavaScript?
JavaScript works too: install playwright via npm and use the chromium.connectOverCDP() function. The principle is the same, only the syntax differs.
Is this free?
The automation itself is free: Playwright and Chromium are open-source projects. You only pay for the LLM API key if you use a paid model. Local models work without any payment.
Can I automate a regular Chrome without a separate profile?
You can, but it's not recommended: without --user-data-dir you give the agent access to your saved passwords and cookies. Always use an isolated profile instead.
Is this safe for my data?
Yes, if you follow the rules: a separate profile, minimal permissions for the script (don't run it as root), and checking the agent's actions on a test site before a real task. The agent only executes the commands you described in its tool list.
--remote-debugging-port=9222 flaghttp://localhost:9222/json opens in a browserpip list | grep playwright)playwright install chromium finished without errors)connect.py opened a tab and printed a titleDone: after completing all the steps you have a full "neural network + browser" setup. The agent can collect data, test forms, and handle routine operations in Chrome. From here, extend the tool set — add screenshots, file downloads, or cookie handling.
Status: practical guide. Some statements come from vendors; verify in your environment.
A step-by-step guide to connecting AI agents to Chrome via extensions and APIs for automating actions in background tabs.
Machine data: Citation Map JSON · JSON-LD · Semantic Embeddings — separate stage.
| Entity | Type | Role |
|---|---|---|
| AI agent in Chrome | тема/инструмент | упоминается в заголовке, TL;DR или разделах гайда |
| AI browser automation | тема/инструмент | упоминается в заголовке, TL;DR или разделах гайда |
| AI agent browser automation | тема/инструмент | упоминается в заголовке, TL;DR или разделах гайда |
| Python | платформа/технология | упоминается в заголовке, TL;DR или разделах гайда |
No independent confirmation is provided; source claims and editorial conclusions are separated below.
| Source | Type | Role |
|---|---|---|
| example.com | внешний источник | ссылка из тела гайда |
Cite as: AI Release. Как подключить ИИ-агента к Chrome: настройка автоматизации браузера. ai-release.org.