tests — browser-automation

Module: tests-browser-automation Cohesion: 0.80 Members: 0

tests — browser-automation

This documentation covers the core browser automation capabilities provided by the system, as revealed and verified by the tests/browser-automation module. These components enable programmatic control, data management, and network interaction with web browsers, primarily for testing, scraping, or automated workflows.

The browser automation suite is designed to be modular, allowing different aspects of browser control to be managed independently.

Core Capabilities

The browser-automation module provides the following key functionalities:

  1. Browser Instance Management: Orchestrates browser launches, connections, and lifecycle, including managing unique references for interactive elements.
  2. Browser Profile Management: Handles saving and loading browser-specific user data (cookies, local storage, session storage) to persist browser state across sessions.
  3. Network Request Interception: Allows defining rules to block, mock, modify, or log network requests made by the browser.
  4. Screenshot Annotation: Adds visual overlays to screenshots, typically to highlight and number interactive elements.
  5. Chrome Endpoint Discovery: Automatically detects a running Chrome instance's debugging endpoint.
  6. Built-in Profiles: Provides predefined browser configurations for common use cases.

Architecture Overview

The BrowserManager acts as the central orchestrator for browser interactions. It leverages other specialized modules for specific tasks like profile persistence, network control, and visual feedback.

graph TD
    subgraph Browser Automation Core
        BM[BrowserManager]
        CD[Chrome Discovery]
        BP[Built-in Profiles]
        RPM[BrowserProfileManager]
        RI[RouteInterceptor]
        SA[Screenshot Annotator]
    end

    CD -- Provides CDP URL --> BM
    BP -- Provides default configs --> BM
    BM -- Manages browser instances --> PlaywrightAPI
    BM -- Saves/Loads user data --> RPM
    BM -- Applies network rules --> RI
    BM -- Generates annotated images --> SA

    RPM -- Persists profiles --> FileSystem
    RI -- Intercepts requests --> BrowserNetwork
    SA -- Processes images --> SharpLibrary

Key Components

1. Browser Instance Management (src/browser-automation/browser-manager.ts)

The BrowserManager class is responsible for managing browser instances and their associated state.

2. Browser Profile Management (src/browser-automation/profile-manager.ts)

The BrowserProfileManager handles the persistence of browser user data, allowing for consistent browser sessions.

3. Network Request Interception (src/browser-automation/route-interceptor.ts)

The RouteInterceptor provides a mechanism to control and observe network requests made by the browser. It's built on top of Playwright's routing capabilities.

4. Screenshot Annotation (src/browser-automation/screenshot-annotator.ts)

The annotateScreenshot function enhances browser screenshots by adding visual markers.

5. Chrome Endpoint Discovery (src/browser-automation/chrome-discovery.ts)

This module helps locate a running Chrome instance for remote debugging.

6. Built-in Profiles (src/browser-automation/builtin-profiles.ts)

This module defines standard, pre-configured browser profiles.

How to Contribute

When contributing to the browser-automation module: