< Back to Logs
Published on 22 November 2026 • Written by MarckDWN

Under the Hood: The Pluggable Multi-WebChat Architecture Behind DWN.Bridge

From day one, the core mission of DWN.BRIDGE has been unequivocal: empower developers to leverage free web-tier LLMs for fully autonomous, local agentic workflows with zero API token costs and zero data leakage.

In our initial releases, the automation layer was tightly coupled with Google Gemini's web interface. While effective, building a long-term, community-driven platform demanded a deeper architectural evolution. Modern web frontends change unpredictably, and developers should have the freedom to drive their favorite AI web interfaces—be it Gemini, Claude, ChatGPT, or DeepSeek.

Today, we are lifting the hood on the newly refactored Modular Multi-WebChat Engine Architecture: a pluggable, decoupled design engineered for resilient browser automation, rapid selector healing without app recompilation, and frictionless community extensibility.

Key Milestone: Google Gemini is active and ready out-of-the-box. The underlying core is now completely provider-agnostic, featuring an extensible IChatWebEngine contract that makes adding new webchat providers as simple as implementing a single C# class.

The Decoupled System Architecture

Instead of mixing Playwright page control, DOM scraping, and local tool execution in a monolithic class, the new architecture divides responsibilities across specialized, testable components:

graph TD
    subgraph "Core Orchestration"
        VM[MainViewModel / Agents] -->|ILlmService| Sync[ChatSyncEngine]
        Sync -->|Orchestrates| Driver[HumanInputDriver]
        Sync -->|Monitors| Tracker[StreamingStabilityTracker]
    end

    subgraph "Engine Abstraction Layer"
        Host[BrowserHost (Playwright + WebView2)] -->|Executes via| Engine[IChatWebEngine]
        Registry[EngineRegistry] -->|Resolves by ID| Engine
        Resolver[SelectorLayerResolver] -->|Dynamic Selectors| Engine
    end

    subgraph "Pluggable Engines"
        Engine --> Gemini[GeminiWebEngine (Active)]
        Engine -.-> Claude[ClaudeWebEngine (Extensible)]
        Engine -.-> ChatGPT[ChatGPTWebEngine (Extensible)]
        Engine -.-> DeepSeek[DeepSeekWebEngine (Extensible)]
    end

    subgraph "Selector Resolution Cascade"
        L1[1. Code Defaults] --> Resolver
        L2[2. OTA Server Config] --> Resolver
        L3[3. Local JSON Override] --> Resolver
    end

    style VM fill:#3B82F6,stroke:#1E3A8A,stroke-width:2px,color:#fff
    style Sync fill:#2563EB,stroke:#1D4ED8,stroke-width:2px,color:#fff
    style Host fill:#0284C7,stroke:#0369A1,stroke-width:2px,color:#fff
    style Gemini fill:#10B981,stroke:#047857,stroke-width:2px,color:#fff
    style Claude fill:#64748B,stroke:#475569,stroke-width:2px,stroke-dasharray: 4 4,color:#fff
    style ChatGPT fill:#64748B,stroke:#475569,stroke-width:2px,stroke-dasharray: 4 4,color:#fff
    style DeepSeek fill:#64748B,stroke:#475569,stroke-width:2px,stroke-dasharray: 4 4,color:#fff
    style Resolver fill:#F59E0B,stroke:#D97706,stroke-width:2px,color:#fff
            

1. The IChatWebEngine Contract
Every AI provider is encapsulated behind a strict interface. The engine defines:

2. BrowserHost & Stealth Execution
The engine does not create browser processes directly. BrowserHost manages the Chromium lifecycle, handles stealth headers, viewport configuration, and bridges native WPF events with Playwright's execution context.

3-Tier Selector Resolution: Healing Without Recompiling

The single greatest operational vulnerability of browser-based automation is DOM churn. When a provider changes a CSS class from .input-area to div[role='textbox'], traditional clients crash until an engineer publishes an update.

To eliminate this bottleneck, DWN.BRIDGE introduces a 3-tier cascading selector resolution system:

1. Hardcoded Defaults in Engine  <  2. Over-The-Air (OTA) Server Config  <  3. Local JSON Override

How Local JSON Overrides Work

Whenever you need to adjust or fix a broken button, you don't even need to touch Visual Studio or wait for a git commit. You simply drop or edit a JSON file in your local AppData directory:

%LocalAppData%\AIBridge\selectors\{engineId}.json

For example, to hot-fix the Gemini stop button or prompt textarea, create gemini.json:

{
  "StopButton": "button[aria-label*='Interrompi'], button[data-testid='stop-btn']",
  "TextArea": "div[role='textbox'][contenteditable='true']"
}

The client detects and applies the overrides on the fly with automatic hot-reload. If a JSON file is syntactically invalid, the engine safely falls back to OTA or default selectors without crashing.

Live DOM Diagnostics: SelfTestAsync

How do you know if an engine's selectors are healthy before submitting an important prompt? The new architecture introduces a proactive self-test diagnostic tool:

var report = await engine.SelfTestAsync(page);
// Returns: CriticalOK=True | TextArea=OK(1), SendButton=OK(1), StopButton=MISSING (optional)

If critical selectors fail to resolve, the engine alerts the user with precise debugging output, distinguishing between fatal issues (missing prompt textarea) and contextual elements (stop button only visible during active token generation).

Native WebView2 Authentication Flow

Automating browser sessions often runs into sophisticated CAPTCHAs and OAuth verification walls. Instead of fighting automated login screens, DWN.BRIDGE implements a hybrid flow:

Contribute a Provider: The Step-by-Step Guide

Because the engine is now modular, extending DWN.BRIDGE to support new providers is a straightforward developer task. Whether you want to add Anthropic Claude, ChatGPT, DeepSeek, or a custom internal web interface, everything is documented.

We have published a comprehensive guide in the repository:

👉 Docs/HowTo_Add_WebChat_Engine.md

The guide walks you through:

  1. Creating your dedicated engine folder under Services/WebChat/Engines/<Provider>/.
  2. Implementing IChatWebEngine with selector resolution and sanitization.
  3. Registering the engine in EngineRegistry.cs.
  4. Writing contract tests with ChatWebEngineContractTests to guarantee 100% compliance.

Build the Future of Zero-Cost Local AI

DWN.BRIDGE is open-source, private, and community-driven. Compile from source, test the modular engine, or contribute a new webchat provider today.

Download Client GitHub Repo Discord Community