$ show Justson/AgentWeb
AgentWeb is an Android WebView wrapper library that provides a fluent builder API (AgentWeb.with()) to configure and manage WebView instances with features like progress indicators, file upload, JavaScript bridge, video fullscreen, URL interception, and security controls. The architecture follows a modular design with core (agentweb-core), file chooser (agentweb-filechooser), and optional third-party downloader modules. Key architectural patterns include: builder pattern for configuration, middleware/decorator pattern for WebViewClient and WebChromeClient interceptor chains, and a reflection-based decoupling approach for the file chooser to avoid mandatory dependencies. The library abstracts common WebView pain points such as lifecycle handling, memory leaks, multi-process support, and device-specific bugs (e.g., Huawei, Android 5.0/5.1). The accompanying sample app demonstrates 20+ use cases including pull-to-refresh, VasSonic pre-rendering, IPC with separate processes, and custom indicators. The codebase shows strong engineering practices with clean separation of interfaces and default implementations, though it relies on some deprecated Android APIs and reflection that may require ongoing maintenance.
The LLM identified 4 files worth highlighting for reuse:
Implements the middleware chain for WebChromeClient using an onion model. Allows multiple interceptors (e.g., progress, file chooser, custom dialogs) to be composed without inheritance. Can be extracted to wrap any Android WebChromeClient for feature separation.
Same middleware pattern for WebViewClient. Enables chaining of interceptors for URL loading, SSL errors, and page navigation. Reusable as a generic interceptor framework for any WebView-based project.
Provides a secure JavaScript-to-Java interface using the WebView's onJsPrompt() method. Validates URLs and JSON payloads to prevent injection attacks. Can be adapted as a standalone JS bridge in other Android WebView projects.
Handles file selection from camera, gallery, and documents with backward compatibility, supporting both old and new WebView file chooser APIs. Uses reflection to decouple from agentweb-core, making it loadable only when needed. Includes post-selection compression hooks. Demonstrates a robust pattern for handling runtime permissions and activity results.