Setting Up Browser Use with Botright
Automating web browsing while remaining undetected is critical for various use cases like scraping, testing, or automation. This guide shows you how to set up Browser Use with Botright, a robust library for stealth browsing and captcha solving.
Why Use Botright?
Botright enhances stealth browsing by leveraging techniques like fingerprint masking and AI-driven captcha solving. It integrates seamlessly with Playwright, making it perfect for stealthy automation tasks.
Prerequisites
Ensure the following tools and dependencies are installed:
- Python 3.11 or Higher: Install from python.org.
- pip: Included with Python.
- Browser Use: The main framework.
- Botright: For stealth features and advanced automation.
Install Required Packages
Run the following commands to set up your environment:
# Clone the repository
git clone https://github.com/browser-use/browser-use
cd browser-use
# Install uv for environment management
pip install uv
# Create a virtual environment
uv venv --python 3.11
# Activate the virtual environment
source .venv/bin/activate # For Linux/macOS
.venv\Scripts\activate # For Windows
# Install Browser Use with development dependencies
uv pip install . ."[dev]"
# Install Botright
pip install botright
playwright install
Implementation
Follow these steps to integrate Botright with Browser Use:
1. Update main.py
Replace the Playwright browser initialization with Botright’s initialization. Here’s the updated main.py
:
import asyncio
import botright
async def main():
# Initialize Botright with enhanced stealth options
botright_client = await botright.Botright(headless=False)
# Launch a browser instance
browser = await botright_client.new_browser()
# Open a new page
page = await browser.new_page()
# Navigate to a website
await page.goto("https://example.com")
# Perform browser actions (e.g., take a screenshot)
await page.screenshot(path="screenshot.png")
print("Screenshot saved!")
# Close the browser and Botright client
await browser.close()
await botright_client.close()
if __name__ == "__main__":
asyncio.run(main())
2. Configure Environment Variables
Set up required API keys by copying the example environment file:
cp .env.example .env
Add the following to your .env
file:
BOTRIGHT_API_KEY=your_botright_api_key
3. Run the Script
Run your updated main.py
script:
python main.py
4. What Happens?
- Browser Initialization: Botright launches a Chromium-based browser instance with stealth enhancements.
- Website Navigation: The browser navigates to the specified URL (
https://example.com
). - Screenshot Capture: A screenshot is taken and saved as
screenshot.png
.
Debugging Tips
- Botright Logs:
Use
print
statements or Botright's built-in logging for debugging. - Browser Errors: Verify the installed version of Playwright and Botright.
- Environment Issues:
Ensure your
.env
file contains the correct API keys.
Advanced Features
Captcha Solving
To solve captchas, use Botright's built-in methods. Example:
await page.solve_captcha()
Fingerprint Masking
Botright automatically handles fingerprint masking. To customize this, refer to the Botright documentation.
Conclusion
By integrating Botright with Browser Use, you unlock advanced stealth browsing capabilities ideal for sensitive automation tasks. This setup provides a solid foundation for further enhancements, such as integrating AI-based analysis or multi-page navigation workflows.