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:
- Identity & Profile Isolation: Each engine specifies an isolated user data directory (e.g.
GeminiProfile,ClaudeProfile) ensuring cookies, sessions, and active tabs never conflict. - URL Navigation & Chat IDs: Logic to generate new chat URLs, extract conversation identifiers, and safely navigate between threads.
- DOM Parsing & File Attachment: Extracting assistant output, detecting code blocks, normalizing markdown, and uploading local context files.
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:
- The user authenticates cleanly through an embedded native WebView2 window with full interactive support for multi-factor authentication (MFA) and Google security prompts.
- Upon successful login detection, the engine intercepts and transfers authenticated session cookies directly into the persistent Playwright automation profile.
- The active chat session is seamlessly resumed without requiring the user to re-enter credentials or restart their workflow.
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:
- Creating your dedicated engine folder under
Services/WebChat/Engines/<Provider>/. - Implementing
IChatWebEnginewith selector resolution and sanitization. - Registering the engine in
EngineRegistry.cs. - Writing contract tests with
ChatWebEngineContractTeststo guarantee 100% compliance.