VOOZH about

URL: https://dzone.com/articles/build-ai-browser-agent-llms-playwright-browser-use

⇱ Build an AI Browser Agent With LLMs, Playwright, Browser-Use


Related

  1. DZone
  2. Coding
  3. Tools
  4. Build an AI Browser Agent With LLMs, Playwright, Browser Use

Build an AI Browser Agent With LLMs, Playwright, Browser Use

A guide on how to build an AI browser agent using LLMs, Playwright, and Browser Use to automate web interactions, extract data, and navigate sites efficiently.

Likes
Comment
Save
18.2K Views

Join the DZone community and get the full member experience.

Join For Free

Browser Use is a tool or platform designed to enable AI agents (such as OpenAI’s GPT models or other large language models) to interact with and control web browsers in an intelligent and automated way. It essentially bridges the gap between AI capabilities and real-world browser interactions, making it possible for AI systems to perform tasks like navigating websites, extracting data, filling out forms, clicking buttons, and more — just as a human user would.

The primary goal of Browser Use is to make websites accessible and actionable for AI agents by abstracting away the complexities of browser automation. Instead of requiring developers to write intricate scripts to locate and interact with webpage elements, Browser Use simplifies this process by extracting all interactive elements (like buttons, input fields, links, etc.) and providing a structured interface for AI agents to interact with.

Key Characteristics of Browser Use

AI-Driven Automation

Browser Use leverages AI to understand and interact with web pages. For example, it can analyze the content of a webpage, identify relevant actions (like clicking a button or filling out a form), and execute those actions autonomously.

Vision + HTML Extraction

It combines visual understanding (recognizing elements on the screen) with HTML structure extraction (parsing the underlying code of a webpage). This dual approach ensures that AI agents can interact with both static and dynamic web elements, even if they don’t have clear identifiers like IDs or classes.

Multi-Tab Management

Browser Use can handle multiple browser tabs simultaneously, allowing AI agents to perform complex workflows that involve interacting with several web pages at once.

The tool tracks the exact actions performed by the AI agent (e.g., clicking a button or filling out a form) and can replicate those actions consistently, even if the website layout changes slightly. This is particularly useful for creating self-healing tests in QA automation.

Custom Actions

Users can extend Browser Use by adding custom actions, such as saving data to files, performing database operations, sending notifications, or handling human input during specific steps in the automation process.

Self-Correcting

Browser Use includes intelligent error handling and automatic recovery mechanisms. If something goes wrong during automation (e.g., a missing element or a network timeout), the tool can detect the issue and attempt to recover automatically, ensuring that workflows continue without interruption.

Compatibility With Multiple LLMs

Browser Use supports various large language models (LLMs), including OpenAI’s GPT-4, Anthropic’s Claude, and Meta’s Llama 2. This flexibility allows users to choose the best AI model for their specific needs.

How Browser Use Works

Browser Use scans a webpage and extracts all interactive elements (buttons, input fields, links, forms, etc.). It then provides a structured representation of these elements that AI agents can understand and interact with.

AI Interaction

Once the interactive elements are identified, AI agents can perform actions like clicking buttons, filling out forms, navigating between pages, or extracting data. The AI agent can also analyze the content of the webpage and make decisions based on the information it finds.

Automation Workflows

Browser Use allows users to create complex automation workflows. For example, an AI agent could navigate through an e-commerce site, add items to a shopping cart, and complete a purchase — all without human intervention.

Error Handling and Recovery

If something goes wrong during the automation process (e.g., a missing element or a slow-loading page), Browser Use can detect the issue and attempt to recover automatically. This ensures that workflows continue smoothly, even in unpredictable environments.

Installation Guide

Getting started with Browser Use is straightforward, but it requires some initial setup to ensure everything runs smoothly. Below is a detailed installation guide based on the prerequisites and steps you’ve provided. This guide will walk you through setting up Browser Use locally on your machine.

Prerequisites

Before you begin, ensure that your system meets the following requirements:

  • Python 3.11 or higher. You can check your Python version by running the command:
    Python
    python --version
    
  • Git. Git is required to clone the repository

Local Installation

Step 1: Clone the Repository

Shell
git clone https://github.com/browser-use/web-ui.git
cd web-ui


Step 2: Set Up Python Environment

We recommend using uv for managing the Python environment (recommended for Mac):

Shell
curl -LsSf https://astral.sh/uv/install.sh | sh



1. Create a virtual environment. Run the following command to create a virtual environment with Python 3.11:
Shell
uv venv -- python 3.11



2. Activate the virtual environment.
  • Windows (command prompt):
    Shell
    .venv\Scripts\activate
  • macOS/Linux:
    Shell
    source .venv/bin/activate

Once activated, you should see .venv in your terminal prompt, indicating that the virtual environment is active.

Step 3: Install Dependencies

Now that your environment is set up, it’s time to install the necessary dependencies.

Install Python packages. Use the following command to install the required Python packages listed in requirements.txt:

Shell
uv pip install -r requirements.txt


Step 4: Install Playwright

Playwright is a browser automation library used by Browser Use.

To install it, run the command:

Shell
playwright install


Local Setup Guide for Browser Use WebUI

Once you’ve completed the installation steps for Browser Use, you can start running the WebUI locally. This guide will walk you through launching the application, customizing its settings, and configuring it to use your own browser if needed.

Running the WebUI

After completing the installation steps, you can start the Browser Use WebUI by running the following command:

Shell
python webui.py --ip 127.0.0.1 --port 7788


The WebUI provides several options to customize its behavior. Here’s a breakdown of the available flags:

  • --ip– the IP address to bind the WebUI to
    • Default – 127.0.0.1 (localhost)
  • --port– the port to bind the WebUI to
    • Default – 7788
  • --theme – the theme for the user interface

Accessing the WebUI

Once the WebUI is running, open your web browser and navigate to:

Plain Text
http://127.0.0.1:7788



Once the above command is executed, you should see the Browser Use interface, where you can interact with the tool and configure AI-driven browser automation tasks.


LLM Configuration

In LLM configuration, select a language model, e.g., gemini. Gemini provides the free API key.

Generate the API keys from the link attached below.


In the screenshot below, you can see we have added the API keys generated with the above link.

Run Agent

In Run agent, let's give the prompt "go to amazon.in and type 'Playwright' click search and give me the first URL."


In the screenshot below, you can see that when we run the prompt, it will open the Chromium browser and interact with the whole DOM of the page.


Finally, it will enter the value Playwright in the search box, and you can see the below screenshot.


In the below screenshot, you can see it gives us the first URL.


In the backend, you can see all the logs are executed; whatever agent is performing its log, all logs are in the backend.


Result

In the result tab, you can see the final result, model action, model thoughts, trace file, and agent history.


Video

You can download the video by clicking on the link provided. You can also see the attached video under the Recordings tab. When you run the video, you will see all the steps the agent has performed.

Below are some screenshots of the video.


Conclusion

The integration of LLMs, Playwright, and Browser Use represents a new leap in browser automation and AI-driven workflows. Combining these tools will allow you to create intelligent browser agents capable of performing complex tasks with minimal human intervention. From automating repetitive processes to enabling dynamic QA testing and real-time decision-making, the possibilities are endless.

Reference

AI UI large language model Tool

Opinions expressed by DZone contributors are their own.

Related

  • Production Checklist for Tool-Using AI Agents in Enterprise Apps
  • MCP vs Skills vs Agents With Scripts: Which One Should You Pick?
  • AI Agents vs LLMs: Choosing the Right Tool for AI Tasks
  • Model Context Protocol Vs Agent2Agent: Practical Integration with Enterprise Data

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

Let's be friends: