How to beginner · 3 min read

Browser Use multi-tab support

Quick answer
The browser-use package supports multi-tab browsing by creating separate Agent instances for each tab, each maintaining its own state and context. Manage multiple tabs by instantiating multiple Agent objects and running them asynchronously or sequentially to simulate multi-tab interactions.

PREREQUISITES

  • Python 3.8+
  • pip install browser-use
  • pip install langchain-openai
  • OpenAI API key (free tier works)

Setup

Install the browser-use package and langchain-openai for LLM integration. Set your OpenAI API key as an environment variable.

bash
pip install browser-use langchain-openai
output
Collecting browser-use
Collecting langchain-openai
Successfully installed browser-use langchain-openai

Step by step

Create multiple Agent instances to represent different browser tabs. Each agent maintains its own browsing context. Run them asynchronously to simulate multi-tab browsing.

python
import os
import asyncio
from browser_use import Agent
from langchain_openai import ChatOpenAI

async def main():
    # Initialize two separate browser tabs as agents
    tab1 = Agent(
        task="Search for AI news on google.com",
        llm=ChatOpenAI(model="gpt-4o-mini", openai_api_key=os.environ["OPENAI_API_KEY"])
    )
    tab2 = Agent(
        task="Check weather forecast on weather.com",
        llm=ChatOpenAI(model="gpt-4o-mini", openai_api_key=os.environ["OPENAI_API_KEY"])
    )

    # Run both tabs concurrently
    results = await asyncio.gather(tab1.run(), tab2.run())

    print("Tab 1 result:", results[0])
    print("Tab 2 result:", results[1])

if __name__ == "__main__":
    asyncio.run(main())
output
Tab 1 result: AI news summary from google.com
Tab 2 result: Weather forecast details from weather.com

Common variations

  • Use synchronous calls by running agent.run_sync() instead of async agent.run().
  • Switch to different LLM models by changing ChatOpenAI(model=...) to other supported models like gpt-4o-mini.
  • Manage more tabs by creating additional Agent instances and running them concurrently.
python
import os
from browser_use import Agent
from langchain_openai import ChatOpenAI

def main():
    tab1 = Agent(
        task="Search for AI news",
        llm=ChatOpenAI(model="gpt-4o-mini", openai_api_key=os.environ["OPENAI_API_KEY"])
    )
    tab2 = Agent(
        task="Check weather forecast",
        llm=ChatOpenAI(model="gpt-4o-mini", openai_api_key=os.environ["OPENAI_API_KEY"])
    )

    result1 = tab1.run_sync()
    result2 = tab2.run_sync()

    print("Tab 1 result:", result1)
    print("Tab 2 result:", result2)

if __name__ == "__main__":
    main()
output
Tab 1 result: AI news summary
Tab 2 result: Weather forecast details

Troubleshooting

  • If you see ModuleNotFoundError, ensure browser-use and langchain-openai are installed.
  • If OPENAI_API_KEY is missing, set it in your environment: export OPENAI_API_KEY='your_key'.
  • For concurrency issues, verify you are using asyncio.run() properly and your Python version supports async.

Key Takeaways

  • Use separate Agent instances to simulate multiple browser tabs in browser-use.
  • Run agents asynchronously with asyncio.gather() for concurrent multi-tab browsing.
  • Set your OpenAI API key in environment variables and install required packages before running.
  • Switch between synchronous and asynchronous execution depending on your application needs.
Verified 2026-04 · gpt-4o-mini
Verify ↗