glass/browser/session/evaluate.rs
1//! Policy-gated JavaScript evaluation for the active page route.
2
3use super::*;
4
5impl BrowserSession {
6 /// Evaluate arbitrary JavaScript in the active page context.
7 ///
8 /// Policy-gated: requires the `Evaluate` capability. Invalidates the
9 /// observation cache after execution since arbitrary JS may mutate DOM.
10 pub async fn evaluate(&self, expression: &str) -> BrowserResult<Value> {
11 self.policy.require(PolicyCapability::Evaluate)?;
12 self.cdp
13 .with_current_route(async {
14 let result = self.evaluate_value(expression).await;
15 // Arbitrary JavaScript may mutate DOM, styles, form state, or history.
16 // Invalidate synchronously so the next cached observation cannot race
17 // the asynchronous CDP mutation event stream.
18 self.invalidate_observation();
19 self.record_audit("evaluate", redact_diagnostic_text(expression));
20 result
21 })
22 .await
23 }
24}