glass-browser 0.3.9

Local browser intelligence runtime with semantic memory, verified workflows, multi-surface understanding, CLI, TUI, MCP, and Rust APIs
Documentation
//! Policy-gated JavaScript evaluation for the active page route.

use super::*;

impl BrowserSession {
    /// Evaluate arbitrary JavaScript in the active page context.
    ///
    /// Policy-gated: requires the `Evaluate` capability. Invalidates the
    /// observation cache after execution since arbitrary JS may mutate DOM.
    pub async fn evaluate(&self, expression: &str) -> BrowserResult<Value> {
        self.policy.require(PolicyCapability::Evaluate)?;
        self.cdp
            .with_current_route(async {
                let result = self.evaluate_value(expression).await;
                // Arbitrary JavaScript may mutate DOM, styles, form state, or history.
                // Invalidate synchronously so the next cached observation cannot race
                // the asynchronous CDP mutation event stream.
                self.invalidate_observation().await;
                self.record_audit("evaluate", "javascript evaluation completed");
                result
            })
            .await
    }
}