BrowserGym Core

0.14.3 · active · verified Sat Apr 11

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

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a `browsergym-core` environment for an open-ended task, perform a reset, take a sample action, and ensure proper cleanup. It uses `gymnasium` for the environment API and `playwright.sync_api` to manage the browser context.

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()

view raw JSON →