browser_commander/traces/
assets.rs1use std::sync::OnceLock;
8
9use serde::Deserialize;
10
11const ASSETS_JSON: &str = include_str!("assets.json");
12
13#[derive(Debug, Clone, Deserialize)]
15#[serde(rename_all = "camelCase")]
16pub struct CaptureAssets {
17 pub capture_snapshot: String,
19 pub install_mutation_recorder: String,
21 pub drain_mutations: String,
23 pub stop_mutation_recorder: String,
25}
26
27#[derive(Debug, Clone, Deserialize)]
29pub struct ViewerAssets {
30 pub style: String,
32 pub script: String,
34}
35
36#[derive(Debug, Clone, Deserialize)]
38#[serde(rename_all = "camelCase")]
39pub struct TraceAssets {
40 pub note: String,
42 pub recorder_global: String,
44 pub redacted: String,
46 pub capture: CaptureAssets,
48 pub viewer: ViewerAssets,
50}
51
52pub fn trace_assets() -> &'static TraceAssets {
54 static ASSETS: OnceLock<TraceAssets> = OnceLock::new();
55 ASSETS.get_or_init(|| {
56 serde_json::from_str(ASSETS_JSON).expect("rust/src/traces/assets.json is generated JSON")
57 })
58}
59
60#[cfg(test)]
61mod tests {
62 use super::*;
63
64 #[test]
65 fn assets_hold_the_in_page_functions() {
66 let assets = trace_assets();
67 assert_eq!(assets.recorder_global, "__browserCommanderTrace__");
68 assert_eq!(assets.redacted, super::super::redaction::REDACTED);
69 assert!(assets
70 .capture
71 .capture_snapshot
72 .starts_with("function captureSnapshotInPage(options)"));
73 assert!(assets
74 .capture
75 .drain_mutations
76 .starts_with("function drainMutationsInPage(globalName)"));
77 assert!(!assets.viewer.script.is_empty());
78 }
79}