---
slug: "browser-use-selenium-remote-grid"
title: "[Outdated] Using Selenium Remote (Selenium Grid) with browser_use"
description: "This is sample code for using Selenium Remote Grid in headful mode with `browser_use`. The sample also includes specifying the browser window’s viewport size."
url: "https://www.ytyng.com/en/blog/browser-use-selenium-remote-grid"
publish_date: "2025-05-27T08:55:41Z"
created: "2025-05-27T08:55:41.337Z"
updated: "2026-02-27T10:00:39.410Z"
categories: ["Python"]
keywords: ""
featured_image_url: "https://media.ytyng.com/resize/20250611/1986ba72dbc44545b77d4195c77f4d23.png.webp?width=768"
has_video: true
has_music: true
video_urls: ["https://media.ytyng.net/ytyng-blog/323/featured-video-1.mp4", "https://media.ytyng.net/ytyng-blog/323/featured-video-2.mp4", "https://media.ytyng.net/ytyng-blog/323/featured-video-3.mp4"]
music_urls: ["https://media.ytyng.net/ytyng-blog/323/featured-music-323-1.mp3", "https://media.ytyng.net/ytyng-blog/323/featured-music-323-2.mp3"]
lang: "en"
---

# [Outdated] Using Selenium Remote (Selenium Grid) with browser_use

Note: This article is old.

This method can no longer be used with browser-use 0.2 and later. If you are using browser-use versions after that, you need to perform remote debugging via Chrome’s debugging port.

---

browser_use uses Playwright internally.

Since Playwright can use Selenium Remote (Selenium Grid), you can use a remote browser simply by setting the environment variable `SELENIUM_REMOTE_URL` to the Selenium Remote URL (a URL like `http://selenium-grid.example.com:4444`).

However, by default it runs in headless mode, and you can’t specify a context, so it’s not customizable.

If you create a customized Playwright instance and inject it into the Agent, you can use Playwright exactly the way you want.

# Sample code
```python
from langchain_openai import ChatOpenAI
from browser_use import Agent, Browser
from playwright.async_api import async_playwright
import asyncio
import os


os.environ['SELENIUM_REMOTE_URL'] = 'http://selenium-grid.example.com:4444'


prompt = f'''
* Please open https://www.example.com.
* The login button...
* In Email ...
'''

sync def main():
    async with async_playwright() as p:
        # Create and customize a Playwright browser
        playwright_browser = await p.chromium.launch(
            headless=False,  # Disable headless mode
        )
        browser_context = await playwright_browser.new_context(
            viewport={'width': 670, 'height': 377},  # Set viewport size
            locale='ja-JP',  # Language setting
            ignore_https_errors=True,  # Ignore certificate errors
        )
        # Create a browser_use Browser and inject the Playwright browser
        browser = Browser()
        browser.playwright_browser = playwright_browser
        browser.playwright = p
        
        # Inject the browser_use Browser into the Agent
        agent = Agent(
            task=prompt,
            llm=ChatOpenAI(model="gpt-4.1-mini"),
            browser=browser,
            browser_context=browser_context,
        )
        result = await agent.run(max_steps=5)
        print(result)


if __name__ == "__main__":
    asyncio.run(main())
```
