use std::sync::OnceLock;
use serde::Deserialize;
const ASSETS_JSON: &str = include_str!("assets.json");
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CaptureAssets {
pub capture_snapshot: String,
pub install_mutation_recorder: String,
pub drain_mutations: String,
pub stop_mutation_recorder: String,
}
#[derive(Debug, Clone, Deserialize)]
pub struct ViewerAssets {
pub style: String,
pub script: String,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TraceAssets {
pub note: String,
pub recorder_global: String,
pub redacted: String,
pub capture: CaptureAssets,
pub viewer: ViewerAssets,
}
pub fn trace_assets() -> &'static TraceAssets {
static ASSETS: OnceLock<TraceAssets> = OnceLock::new();
ASSETS.get_or_init(|| {
serde_json::from_str(ASSETS_JSON).expect("rust/src/traces/assets.json is generated JSON")
})
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn assets_hold_the_in_page_functions() {
let assets = trace_assets();
assert_eq!(assets.recorder_global, "__browserCommanderTrace__");
assert_eq!(assets.redacted, super::super::redaction::REDACTED);
assert!(assets
.capture
.capture_snapshot
.starts_with("function captureSnapshotInPage(options)"));
assert!(assets
.capture
.drain_mutations
.starts_with("function drainMutationsInPage(globalName)"));
assert!(!assets.viewer.script.is_empty());
}
}