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
- Create adapter with configuration
- Call
connect()to establish connection - Use navigation/extraction/capture methods
- Call
disconnect()when done
Implementations MUST handle reconnection automatically on transient failures.
Required Methods§
Sourcefn connect<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = WebAdapterResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
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
Sourcefn disconnect<'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,
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)
Sourcefn is_connected(&self) -> bool
fn is_connected(&self) -> bool
Check if adapter is currently connected
Navigate to a URL and return a page handle
§Arguments
url- Target URL to navigate tooptions- Navigation options (timeout, wait event, etc.)
§Errors
Returns:
WebAdapterError::InvalidUrlif URL is malformedWebAdapterError::NavigationTimeoutif timeout exceededWebAdapterError::NavigationFailedfor 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
Sourcefn 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_back<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = WebAdapterResult<PageHandle>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Sourcefn 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 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.
Sourcefn 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 reload<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = WebAdapterResult<PageHandle>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Sourcefn 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 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 fromoptions- Extraction options
§Errors
Returns:
WebAdapterError::ExtractionFailedif extraction failsWebAdapterError::InvalidSelectorif custom selector is invalidWebAdapterError::JavaScriptErrorif 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)
Sourcefn 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 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 onscript- 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
Sourcefn 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 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,
Sourcefn 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 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 captureoptions- Capture options (format, quality, etc.)
§Errors
Returns:
WebAdapterError::CaptureFailedif capture failsWebAdapterError::UnsupportedFormatif 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.)