# ttlns/undetected-playwright-python architecture

> Architecture diagram of the GitHub repository ttlns/undetected-playwright-python, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ttlns/undetected-playwright-python
- Repository: https://github.com/ttlns/undetected-playwright-python

## Overview

This repository is a Python patch of Playwright focused on Chromium automation. The main workflow is that a Python caller enters the async or sync API, launches a browser, creates a page, and navigates or interacts with it; the README demonstrates both API styles. Internally, API objects send commands through a connection and transport, while page/frame and locator objects expose browser interaction. The README documents Chromium-only patching, but the sampled excerpts do not show its implementation. Other subsystems are represented where the source index or excerpts support them; unsampled details and links are omitted.

Main entry points: [`undetected_playwright/_impl/_connection.py`](https://github.com/ttlns/undetected-playwright-python/blob/main/undetected_playwright/_impl/_connection.py) (Protocol connection), [`undetected_playwright/_impl/_frame.py`](https://github.com/ttlns/undetected-playwright-python/blob/main/undetected_playwright/_impl/_frame.py) (Frame operations), [`undetected_playwright/_impl/_browser_context.py`](https://github.com/ttlns/undetected-playwright-python/blob/main/undetected_playwright/_impl/_browser_context.py) (Browser context), [`undetected_playwright/async_api/__init__.py`](https://github.com/ttlns/undetected-playwright-python/blob/main/undetected_playwright/async_api/__init__.py) (Async API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Python APIs"]
  node_async_api["Async API<br/>[__init__.py]"]
  node_sync_api["Sync API<br/>[__init__.py]"]
  node_async_context["Async context"]
  node_sync_context["Sync context"]
end

subgraph group_runtime["Browser Runtime"]
  node_driver["Driver startup<br/>[_driver.py]"]
  node_playwright["Playwright root<br/>[_playwright.py]"]
  node_connection["Protocol connection<br/>[_connection.py]"]
  node_transport["Protocol transport<br/>[_transport.py]"]
  node_stealth_patch["Chromium patch"]
end

subgraph group_interaction["Page Interaction"]
  node_context["Browser context"]
  node_page["Page and frames<br/>[_page.py]"]
  node_frame["Frame operations<br/>[_frame.py]"]
  node_locator["Locators<br/>[_locator.py]"]
  node_element["Element handles<br/>[_element_handle.py]"]
end

subgraph group_network["Network and Checks"]
  node_network["Network routing<br/>[_network.py]"]
  node_api_request["API requests<br/>[_fetch.py]"]
  node_assertions["Assertions<br/>[_assertions.py]"]
end

subgraph group_shared["Shared Internals"]
  node_structures["API structures<br/>[_api_structures.py]"]
  node_helpers["Runtime helpers<br/>[_helper.py]"]
  node_waiter["Wait coordination<br/>[_waiter.py]"]
  node_errors["Error types<br/>[_errors.py]"]
end

node_caller(("Python caller"))
node_chromium["Chromium browser"]

node_caller -->|"uses async"| node_async_api
node_caller -->|"uses sync"| node_sync_api
node_async_api -->|"enters context"| node_async_context
node_sync_api -->|"enters context"| node_sync_context
node_async_context -->|"starts driver"| node_driver
node_sync_context -->|"starts driver"| node_driver
node_async_context -->|"creates connection"| node_connection
node_sync_context -->|"creates connection"| node_connection
node_connection -->|"sends protocol"| node_transport
node_connection -->|"creates objects"| node_playwright
node_playwright -->|"launches browser"| node_chromium
node_chromium -.->|"creates context"| node_context
node_context -->|"manages pages"| node_page
node_page -->|"uses frames"| node_frame
node_frame -->|"sends commands"| node_connection
node_locator -->|"delegates actions"| node_frame
node_locator -->|"returns handles"| node_element
node_context -->|"handles routes"| node_network
node_page -->|"routes requests"| node_network
node_api_request -->|"sends fetch"| node_connection
node_async_api -->|"exposes assertions"| node_assertions
node_sync_api -->|"exposes assertions"| node_assertions
node_assertions -->|"checks locators"| node_locator
node_frame -.->|"coordinates waits"| node_waiter
node_context -->|"uses options"| node_structures
node_frame -->|"matches URLs"| node_helpers
node_connection -->|"parses errors"| node_errors
node_caller -->|"uses patched Chromium"| node_stealth_patch

click node_async_api "https://github.com/ttlns/undetected-playwright-python/blob/main/undetected_playwright/async_api/__init__.py"
click node_sync_api "https://github.com/ttlns/undetected-playwright-python/blob/main/undetected_playwright/sync_api/__init__.py"
click node_async_context "https://github.com/ttlns/undetected-playwright-python/blob/main/undetected_playwright/async_api/_context_manager.py"
click node_sync_context "https://github.com/ttlns/undetected-playwright-python/blob/main/undetected_playwright/sync_api/_context_manager.py"
click node_driver "https://github.com/ttlns/undetected-playwright-python/blob/main/undetected_playwright/_impl/_driver.py"
click node_playwright "https://github.com/ttlns/undetected-playwright-python/blob/main/undetected_playwright/_impl/_playwright.py"
click node_connection "https://github.com/ttlns/undetected-playwright-python/blob/main/undetected_playwright/_impl/_connection.py"
click node_transport "https://github.com/ttlns/undetected-playwright-python/blob/main/undetected_playwright/_impl/_transport.py"
click node_context "https://github.com/ttlns/undetected-playwright-python/blob/main/undetected_playwright/_impl/_browser_context.py"
click node_page "https://github.com/ttlns/undetected-playwright-python/blob/main/undetected_playwright/_impl/_page.py"
click node_frame "https://github.com/ttlns/undetected-playwright-python/blob/main/undetected_playwright/_impl/_frame.py"
click node_locator "https://github.com/ttlns/undetected-playwright-python/blob/main/undetected_playwright/_impl/_locator.py"
click node_element "https://github.com/ttlns/undetected-playwright-python/blob/main/undetected_playwright/_impl/_element_handle.py"
click node_network "https://github.com/ttlns/undetected-playwright-python/blob/main/undetected_playwright/_impl/_network.py"
click node_api_request "https://github.com/ttlns/undetected-playwright-python/blob/main/undetected_playwright/_impl/_fetch.py"
click node_assertions "https://github.com/ttlns/undetected-playwright-python/blob/main/undetected_playwright/_impl/_assertions.py"
click node_structures "https://github.com/ttlns/undetected-playwright-python/blob/main/undetected_playwright/_impl/_api_structures.py"
click node_helpers "https://github.com/ttlns/undetected-playwright-python/blob/main/undetected_playwright/_impl/_helper.py"
click node_waiter "https://github.com/ttlns/undetected-playwright-python/blob/main/undetected_playwright/_impl/_waiter.py"
click node_errors "https://github.com/ttlns/undetected-playwright-python/blob/main/undetected_playwright/_impl/_errors.py"
click node_stealth_patch "https://github.com/ttlns/undetected-playwright-python/tree/main/undetected_playwright/_impl"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_async_api,node_sync_api,node_async_context,node_sync_context,node_chromium toneBlue
class node_driver,node_playwright,node_connection,node_transport,node_stealth_patch toneAmber
class node_context,node_page,node_frame,node_locator,node_element toneMint
class node_network,node_api_request,node_assertions toneRose
class node_structures,node_helpers,node_waiter,node_errors,node_caller toneIndigo
```

## Components

### Python APIs

- [Async API](https://github.com/ttlns/undetected-playwright-python/blob/main/undetected_playwright/async_api/__init__.py): `undetected_playwright/async_api/__init__.py`
- [Sync API](https://github.com/ttlns/undetected-playwright-python/blob/main/undetected_playwright/sync_api/__init__.py): `undetected_playwright/sync_api/__init__.py`
- [Async context](https://github.com/ttlns/undetected-playwright-python/blob/main/undetected_playwright/async_api/_context_manager.py): `undetected_playwright/async_api/_context_manager.py`
- [Sync context](https://github.com/ttlns/undetected-playwright-python/blob/main/undetected_playwright/sync_api/_context_manager.py): `undetected_playwright/sync_api/_context_manager.py`

### Browser Runtime

- [Driver startup](https://github.com/ttlns/undetected-playwright-python/blob/main/undetected_playwright/_impl/_driver.py): `undetected_playwright/_impl/_driver.py`
- [Playwright root](https://github.com/ttlns/undetected-playwright-python/blob/main/undetected_playwright/_impl/_playwright.py): `undetected_playwright/_impl/_playwright.py`
- [Protocol connection](https://github.com/ttlns/undetected-playwright-python/blob/main/undetected_playwright/_impl/_connection.py): `undetected_playwright/_impl/_connection.py`
- [Protocol transport](https://github.com/ttlns/undetected-playwright-python/blob/main/undetected_playwright/_impl/_transport.py): `undetected_playwright/_impl/_transport.py`
- [Chromium patch](https://github.com/ttlns/undetected-playwright-python/tree/main/undetected_playwright/_impl): `undetected_playwright/_impl`

### Page Interaction

- [Browser context](https://github.com/ttlns/undetected-playwright-python/blob/main/undetected_playwright/_impl/_browser_context.py): `undetected_playwright/_impl/_browser_context.py`
- [Page and frames](https://github.com/ttlns/undetected-playwright-python/blob/main/undetected_playwright/_impl/_page.py): `undetected_playwright/_impl/_page.py`
- [Frame operations](https://github.com/ttlns/undetected-playwright-python/blob/main/undetected_playwright/_impl/_frame.py): `undetected_playwright/_impl/_frame.py`
- [Locators](https://github.com/ttlns/undetected-playwright-python/blob/main/undetected_playwright/_impl/_locator.py): `undetected_playwright/_impl/_locator.py`
- [Element handles](https://github.com/ttlns/undetected-playwright-python/blob/main/undetected_playwright/_impl/_element_handle.py): `undetected_playwright/_impl/_element_handle.py`

### Network and Checks

- [Network routing](https://github.com/ttlns/undetected-playwright-python/blob/main/undetected_playwright/_impl/_network.py): `undetected_playwright/_impl/_network.py`
- [API requests](https://github.com/ttlns/undetected-playwright-python/blob/main/undetected_playwright/_impl/_fetch.py): `undetected_playwright/_impl/_fetch.py`
- [Assertions](https://github.com/ttlns/undetected-playwright-python/blob/main/undetected_playwright/_impl/_assertions.py): `undetected_playwright/_impl/_assertions.py`

### Shared Internals

- [API structures](https://github.com/ttlns/undetected-playwright-python/blob/main/undetected_playwright/_impl/_api_structures.py): `undetected_playwright/_impl/_api_structures.py`
- [Runtime helpers](https://github.com/ttlns/undetected-playwright-python/blob/main/undetected_playwright/_impl/_helper.py): `undetected_playwright/_impl/_helper.py`
- [Wait coordination](https://github.com/ttlns/undetected-playwright-python/blob/main/undetected_playwright/_impl/_waiter.py): `undetected_playwright/_impl/_waiter.py`
- [Error types](https://github.com/ttlns/undetected-playwright-python/blob/main/undetected_playwright/_impl/_errors.py): `undetected_playwright/_impl/_errors.py`

### Other components

- **Python caller**
- **Chromium browser**

## Connections

- Python caller → Async API: uses async (evidence: `README.md`)
- Python caller → Sync API: uses sync (evidence: `README.md`)
- Async API → Async context: enters context (evidence: `undetected_playwright/async_api/__init__.py`)
- Sync API → Sync context: enters context (evidence: `undetected_playwright/sync_api/__init__.py`)
- Async context → Driver startup: starts driver (evidence: `undetected_playwright/async_api/_context_manager.py`)
- Sync context → Driver startup: starts driver (evidence: `undetected_playwright/sync_api/_context_manager.py`)
- Async context → Protocol connection: creates connection (evidence: `undetected_playwright/async_api/_context_manager.py`)
- Sync context → Protocol connection: creates connection (evidence: `undetected_playwright/sync_api/_context_manager.py`)
- Protocol connection → Protocol transport: sends protocol (evidence: `undetected_playwright/_impl/_connection.py`)
- Protocol connection → Playwright root: creates objects (evidence: `undetected_playwright/_impl/_connection.py`)
- Playwright root → Chromium browser: launches browser (evidence: `README.md`)
- Chromium browser → Browser context: creates context
- Browser context → Page and frames: manages pages (evidence: `undetected_playwright/_impl/_browser_context.py`)
- Page and frames → Frame operations: uses frames (evidence: `undetected_playwright/_impl/_page.py`)
- Frame operations → Protocol connection: sends commands (evidence: `undetected_playwright/_impl/_frame.py`)
- Locators → Frame operations: delegates actions (evidence: `undetected_playwright/_impl/_locator.py`)
- Locators → Element handles: returns handles (evidence: `undetected_playwright/_impl/_locator.py`)
- Browser context → Network routing: handles routes (evidence: `undetected_playwright/_impl/_browser_context.py`)
- Page and frames → Network routing: routes requests (evidence: `undetected_playwright/_impl/_page.py`)
- API requests → Protocol connection: sends fetch (evidence: `undetected_playwright/_impl/_fetch.py`)
- Async API → Assertions: exposes assertions (evidence: `undetected_playwright/async_api/__init__.py`)
- Sync API → Assertions: exposes assertions (evidence: `undetected_playwright/sync_api/__init__.py`)
- Assertions → Locators: checks locators (evidence: `undetected_playwright/_impl/_assertions.py`)
- Frame operations → Wait coordination: coordinates waits (evidence: `undetected_playwright/_impl/_frame.py`)
- Browser context → API structures: uses options (evidence: `undetected_playwright/_impl/_browser_context.py`)
- Frame operations → Runtime helpers: matches URLs (evidence: `undetected_playwright/_impl/_frame.py`)
- Protocol connection → Error types: parses errors (evidence: `undetected_playwright/_impl/_connection.py`)
- Python caller → Chromium patch: uses patched Chromium (evidence: `README.md`)
