BrowserGym Core
BrowserGym Core (version 0.14.3) is a Python library that provides the fundamental Gymnasium environment for web task automation within the Chromium browser. It serves as the base for various web agent benchmarks and is designed for researchers and developers evaluating and building web agents, particularly those leveraging Large Language Models (LLMs) for web interaction tasks. The project is under active development with a rapid release cadence.
Warnings
- gotcha BrowserGym requires Playwright and its Chromium browser to be installed separately. Missing `playwright install chromium` is a common setup error.
- gotcha BrowserGym is explicitly stated as a research tool and not a consumer product. Users should be aware it's under active development and may have rough edges.
- gotcha Timeout errors are frequently encountered when interacting with web pages. These can be due to slow loading, complex elements, or agent actions that don't complete in time.
- gotcha When integrating `browsergym-core` with specific benchmarks (e.g., WebArena), additional environment variables (e.g., `WA_PORT`) or benchmark-specific setup steps are often required to correctly configure task URLs and instances.
- breaking Following Gymnasium API changes, `env.reset()` now returns `(observation, info)` and `env.step()` returns `(observation, reward, terminated, truncated, info)`. Older `(observation, info)` from `reset()` or `(observation, reward, done, info)` from `step()` patterns are deprecated.
Install
-
pip install browsergym-core -
playwright install chromium
Imports
- gym
import gymnasium as gym
- BrowserEnv
from browsergym.core.env import BrowserEnv
- AbstractBrowserTask
from browsergym.core.task import AbstractBrowserTask
Quickstart
import gymnasium as gym
from playwright.sync_api import sync_playwright
# Register the 'openended' task provided by browsergym-core
import browsergym.core
# It's good practice to install playwright chromium if not already done:
# playwright install chromium
with sync_playwright() as p:
# Initialize the BrowserGym environment for an open-ended task
# 'headless=True' runs the browser without a visible UI
env = gym.make(
"browsergym/openended",
headless=True,
task_kwargs={'start_url': 'about:blank'}
)
try:
obs, info = env.reset()
print(f"Initial observation keys: {obs.keys()}")
print(f"Initial info: {info}")
# Example: taking a no-op step
action = env.action_space.sample()
obs, reward, terminated, truncated, info = env.step(action)
print(f"Reward after one step: {reward}")
print(f"Terminated: {terminated}, Truncated: {truncated}")
finally:
# Ensure the browser environment is closed properly
env.close()