use crate::{Result, WebCaptureError};
use tracing::info;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum BrowserEngine {
#[default]
Chromiumoxide,
}
impl std::fmt::Display for BrowserEngine {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Chromiumoxide => write!(f, "chromiumoxide"),
}
}
}
impl std::str::FromStr for BrowserEngine {
type Err = WebCaptureError;
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
match s.to_lowercase().as_str() {
"chromiumoxide" | "chromium" | "chrome" => Ok(Self::Chromiumoxide),
_ => Err(WebCaptureError::BrowserError(format!(
"Unknown browser engine: {s}"
))),
}
}
}
pub async fn render_html(url: &str) -> Result<String> {
info!("Rendering HTML for URL: {}", url);
let html = crate::html::fetch_html(url).await?;
info!("Successfully fetched HTML ({} bytes)", html.len());
Ok(html)
}
#[allow(clippy::unused_async)] pub async fn capture_screenshot(url: &str) -> Result<Vec<u8>> {
info!("Capturing screenshot for URL: {}", url);
Err(WebCaptureError::ScreenshotError(
"Screenshot capture requires Chrome/Chromium. Install it and enable browser-commander features.".to_string()
))
}