WebBrowserAdapter

Trait WebBrowserAdapter 

Source
pub trait WebBrowserAdapter: Send + Sync {
Show 14 methods // Required methods fn connect<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = WebAdapterResult<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn disconnect<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = WebAdapterResult<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn is_connected(&self) -> bool; fn navigate<'life0, 'life1, 'async_trait>( &'life0 mut self, url: &'life1 str, options: NavigateOptions, ) -> Pin<Box<dyn Future<Output = WebAdapterResult<PageHandle>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn go_back<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = WebAdapterResult<PageHandle>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn go_forward<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = WebAdapterResult<PageHandle>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn reload<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = WebAdapterResult<PageHandle>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn extract_content<'life0, 'life1, 'async_trait>( &'life0 mut self, page: &'life1 PageHandle, options: ExtractOptions, ) -> Pin<Box<dyn Future<Output = WebAdapterResult<ExtractedContent>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn execute_js<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, page: &'life1 PageHandle, script: &'life2 str, ) -> Pin<Box<dyn Future<Output = WebAdapterResult<Value>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait; fn get_text<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, page: &'life1 PageHandle, selector: &'life2 str, ) -> Pin<Box<dyn Future<Output = WebAdapterResult<String>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait; fn capture_screenshot<'life0, 'life1, 'async_trait>( &'life0 mut self, page: &'life1 PageHandle, options: CaptureOptions, ) -> Pin<Box<dyn Future<Output = WebAdapterResult<CapturedPage>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn diagnostics(&self) -> Value; fn name(&self) -> &str; fn version(&self) -> &str;
}
Expand description

Web browser adapter trait for reasonkit-core

Provides abstraction for browser automation and content extraction. Implementations can use MCP servers, HTTP binding, FFI, or other mechanisms to communicate with reasonkit-web.

§Implementing the Trait

  • McpWebAdapter: Uses MCP stdio server (local or remote)
  • HttpWebAdapter: Uses HTTP JSON-RPC binding
  • LocalWebAdapter: Direct FFI binding for same-process usage

§Connection Lifecycle

  1. Create adapter with configuration
  2. Call connect() to establish connection
  3. Use navigation/extraction/capture methods
  4. Call disconnect() when done

Implementations MUST handle reconnection automatically on transient failures.

Required Methods§

Source

fn connect<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = WebAdapterResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Initialize and connect to the web browser service

§Errors

Returns WebAdapterError::NotConnected if service is unavailable.

§Implementation Notes
  • May start a browser process (headless Chrome, etc.)
  • May connect to an existing MCP server
  • May verify API compatibility
  • Should implement connection pooling if needed
Source

fn disconnect<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = WebAdapterResult<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Disconnect from web service and cleanup resources

§Implementation Notes
  • Should close browser processes gracefully
  • Should save cache/session state if applicable
  • Idempotent (safe to call multiple times)
Source

fn is_connected(&self) -> bool

Check if adapter is currently connected

Source

fn navigate<'life0, 'life1, 'async_trait>( &'life0 mut self, url: &'life1 str, options: NavigateOptions, ) -> Pin<Box<dyn Future<Output = WebAdapterResult<PageHandle>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Navigate to a URL and return a page handle

§Arguments
  • url - Target URL to navigate to
  • options - Navigation options (timeout, wait event, etc.)
§Errors

Returns:

  • WebAdapterError::InvalidUrl if URL is malformed
  • WebAdapterError::NavigationTimeout if timeout exceeded
  • WebAdapterError::NavigationFailed for other failures (network, SSL, 404, etc.)
§Implementation Notes
  • MUST validate URL before navigation
  • MUST respect timeout_ms in options
  • MUST wait for specified event (load, domcontentloaded, etc.)
  • SHOULD respect custom headers and user agent if provided
  • SHOULD inject JavaScript after load if provided
  • SHOULD handle redirects according to options
  • MUST return page handle with unique ID and current URL
Source

fn go_back<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = WebAdapterResult<PageHandle>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Go back in browser history

§Errors

Returns WebAdapterError::NavigationFailed if unable to go back.

Source

fn go_forward<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = WebAdapterResult<PageHandle>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Go forward in browser history

§Errors

Returns WebAdapterError::NavigationFailed if unable to go forward.

Source

fn reload<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = WebAdapterResult<PageHandle>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Reload current page

§Errors

Returns WebAdapterError::NavigationFailed if unable to reload.

Source

fn extract_content<'life0, 'life1, 'async_trait>( &'life0 mut self, page: &'life1 PageHandle, options: ExtractOptions, ) -> Pin<Box<dyn Future<Output = WebAdapterResult<ExtractedContent>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Extract content from a page

§Arguments
  • page - Page handle to extract from
  • options - Extraction options
§Errors

Returns:

  • WebAdapterError::ExtractionFailed if extraction fails
  • WebAdapterError::InvalidSelector if custom selector is invalid
  • WebAdapterError::JavaScriptError if custom JS fails
§Implementation Notes
  • MUST extract main content text
  • SHOULD auto-detect main content area if no selector provided
  • SHOULD extract links and images according to options
  • SHOULD execute custom JavaScript if provided
  • SHOULD detect language if requested
  • MUST include confidence score (0.0-1.0)
  • SHOULD normalize whitespace
  • SHOULD extract metadata (title, description, og tags)
Source

fn execute_js<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, page: &'life1 PageHandle, script: &'life2 str, ) -> Pin<Box<dyn Future<Output = WebAdapterResult<Value>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Execute custom JavaScript on page

§Arguments
  • page - Page to execute on
  • script - JavaScript code to execute
§Returns

Serialized result of JavaScript execution as JSON value

§Errors

Returns WebAdapterError::JavaScriptError if execution fails.

§Implementation Notes
  • MUST timeout execution if it takes too long (>30s)
  • MUST return JSON-serializable result
  • SHOULD return last expression value
Source

fn get_text<'life0, 'life1, 'life2, 'async_trait>( &'life0 mut self, page: &'life1 PageHandle, selector: &'life2 str, ) -> Pin<Box<dyn Future<Output = WebAdapterResult<String>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Get text content using CSS selector

§Arguments
  • page - Page to query
  • selector - CSS selector
§Errors

Returns:

  • WebAdapterError::InvalidSelector if selector is invalid
  • WebAdapterError::ExtractionFailed if element not found
Source

fn capture_screenshot<'life0, 'life1, 'async_trait>( &'life0 mut self, page: &'life1 PageHandle, options: CaptureOptions, ) -> Pin<Box<dyn Future<Output = WebAdapterResult<CapturedPage>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Capture page as screenshot or document

§Arguments
  • page - Page to capture
  • options - Capture options (format, quality, etc.)
§Errors

Returns:

  • WebAdapterError::CaptureFailed if capture fails
  • WebAdapterError::UnsupportedFormat if format not supported
§Implementation Notes
  • MUST support PNG, JPEG, PDF formats at minimum
  • MAY support MHTML, WebP if available
  • MUST respect quality setting for JPEG/WebP
  • MUST capture full page or viewport according to options
  • SHOULD wait for delay_ms before capturing
  • SHOULD execute custom JavaScript before capture if provided
  • MUST include capture metadata (viewport size, scale factor, etc.)
Source

fn diagnostics(&self) -> Value

Get connection status and diagnostics

§Returns

JSON object with connection info, statistics, etc.

Source

fn name(&self) -> &str

Get adapter name (for logging/debugging)

Source

fn version(&self) -> &str

Get adapter version

Implementors§