cloudscraper_rs/external_deps/interpreters/
mod.rs

1//! JavaScript interpreter infrastructure.
2//!
3//! Provides a shared trait and error type used by JavaScript-based challenge
4//! solvers, along with concrete runtime implementations.
5
6mod boa;
7
8pub use boa::BoaJavascriptInterpreter;
9
10use thiserror::Error;
11
12/// Abstraction over JavaScript runtimes capable of solving Cloudflare logic.
13pub trait JavascriptInterpreter: Send + Sync {
14    /// Evaluate a challenge page and return the solved answer formatted with
15    /// 10 decimal places.
16    fn solve_challenge(&self, page_html: &str, host: &str) -> Result<String, InterpreterError>;
17
18    /// Execute raw JavaScript within a pre-constructed environment.
19    fn execute(&self, script: &str, host: &str) -> Result<String, InterpreterError> {
20        let _ = (script, host);
21        Err(InterpreterError::Other("execute not implemented".into()))
22    }
23}
24
25/// Failures produced by JavaScript runtimes.
26#[derive(Debug, Error)]
27pub enum InterpreterError {
28    #[error("javascript execution failed: {0}")]
29    Execution(String),
30    #[error("javascript engine error: {0}")]
31    Other(String),
32}
33
34/// Convenience alias for runtime results.
35pub type InterpreterResult<T> = Result<T, InterpreterError>;