Skip to main content

Make websites accessible for AI agents

Project description

Browser Use Logo

GitHub stars License: MIT Python 3.11+ Discord

Make websites accessible for AI agents 🤖.

Browser use is the easiest way to connect your AI agents with the browser. If you have used Browser Use for your project feel free to show it off in our Discord.

Quick start

With pip:

pip install browser-use

(optional) install playwright:

playwright install

Spin up your agent:

from langchain_openai import ChatOpenAI
from browser_use import Agent
import asyncio

async def main():
    agent = Agent(
        task="Find a one-way flight from Bali to Oman on 12 January 2025 on Google Flights. Return me the cheapest option.",
        llm=ChatOpenAI(model="gpt-4o"),
    )
    result = await agent.run()
    print(result)

if __name__ == "__main__":
    asyncio.run(main())

And don't forget to add your API keys to your .env file.

OPENAI_API_KEY=
ANTHROPIC_API_KEY=

Demos

Prompt: Read my CV & find ML jobs, save them to a file, and then start applying for them in new tabs, if you need help, ask me.' (8x speed)

https://github.com/user-attachments/assets/171fb4d6-0355-46f2-863e-edb04a828d04

Prompt: Find flights on kayak.com from Zurich to Beijing from 25.12.2024 to 02.02.2025. (8x speed)

flight search 8x 10fps

Prompt: Solve the captcha. (2x speed)
Solving Captcha
Prompt: Look up models with a license of cc-by-sa-4.0 and sort by most likes on Hugging face, save top 5 to file. (1x speed)

https://github.com/user-attachments/assets/de73ee39-432c-4b97-b4e8-939fd7f323b3

Features ⭐

  • Vision + html extraction
  • Automatic multi-tab management
  • Extract clicked elements XPaths and repeat exact LLM actions
  • Add custom actions (e.g. save to file, push to database, notify me, get human input)
  • Self-correcting
  • Use any LLM supported by LangChain (e.g. gpt4o, gpt4o mini, claude 3.5 sonnet, llama 3.1 405b, etc.)

Register custom actions

If you want to add custom actions your agent can take, you can register them like this:

You can use BOTH sync or async functions.

from browser_use.agent.service import Agent
from browser_use.browser.service import Browser
from browser_use.controller.service import Controller

# Initialize controller first
controller = Controller()

@controller.action('Ask user for information')
def ask_human(question: str, display_question: bool) -> str:
	return input(f'\n{question}\nInput: ')

Or define your parameters using Pydantic

class JobDetails(BaseModel):
  title: str
  company: str
  job_link: str
  salary: Optional[str] = None

@controller.action('Save job details which you found on page', param_model=JobDetails, requires_browser=True)
async def save_job(params: JobDetails, browser: Browser):
	print(params)

  # use the browser normally
  page = browser.get_current_page()
	page.go_to(params.job_link)

and then run your agent:

model = ChatAnthropic(model_name='claude-3-5-sonnet-20240620', timeout=25, stop=None, temperature=0.3)
agent = Agent(task=task, llm=model, controller=controller)

await agent.run()

Get XPath history

To get the entire history of everything the agent has done, you can use the output of the run method:

history: list[AgentHistory] = await agent.run()

print(history)

Browser configuration

You can configure the browser using the BrowserConfig class.

The most important options are:

  • headless: Whether to run the browser in headless mode
  • keep_open: Whether to keep the browser open after the script finishes
  • disable_security: Whether to disable browser security features (very useful if dealing with cross-origin requests like iFrames)
  • cookies_file: Path to a cookies file for persistence
  • minimum_wait_page_load_time: Minimum time to wait before getting the page state for the LLM input
  • wait_for_network_idle_page_load_time: Time to wait for network requests to finish before getting the page state
  • maximum_wait_page_load_time: Maximum time to wait for the page to load before proceeding anyway

More examples

For more examples see the examples folder or join the Discord and show off your project.

Telemetry

We collect anonymous usage data to help us understand how the library is being used and to identify potential issues. There is no privacy risk, as no personal information is collected. We collect data with PostHog.

You can opt out of telemetry by setting the ANONYMIZED_TELEMETRY=false environment variable.

Contributing

Contributions are welcome! Feel free to open issues for bugs or feature requests.

Local Setup

  1. Create a virtual environment and install dependencies:
# To install all dependencies including dev
pip install . ."[dev]"
  1. Add your API keys to the .env file:
cp .env.example .env

or copy the following to your .env file:

OPENAI_API_KEY=
ANTHROPIC_API_KEY=

You can use any LLM model supported by LangChain by adding the appropriate environment variables. See langchain models for available options.

Building the package

hatch build

Feel free to join the Discord for discussions and support.


Star ⭐ this repo if you find it useful!
Made with ❤️ by the Browser-Use team

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

browser_use-0.1.14.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

browser_use-0.1.14-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file browser_use-0.1.14.tar.gz.

File metadata

  • Download URL: browser_use-0.1.14.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for browser_use-0.1.14.tar.gz
Algorithm Hash digest
SHA256 678baf69680ed0c041862daab6f4b0821606a96e6c8c1e303fd707a01c2f40e4
MD5 543b3c9911a3d1d69626f2076e080625
BLAKE2b-256 7b173e00993d510595f58542f5389e194ee3fbece3d1690c25105012a96ec5aa

See more details on using hashes here.

File details

Details for the file browser_use-0.1.14-py3-none-any.whl.

File metadata

  • Download URL: browser_use-0.1.14-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for browser_use-0.1.14-py3-none-any.whl
Algorithm Hash digest
SHA256 2bb3b2165e1c5cc0e66c024df86ae05489780fa7c0cbe4dc045dc54e65c7a1e5
MD5 9815b28827e9421e33eb4c3b4d5f9edf
BLAKE2b-256 a1049c0f44444670c0256acbce9c27d7fc9f0e218aeafd4dd6d6b2a57ffffde5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page