pub struct CdpProtection {
pub mode: CdpFixMode,
pub source_url: Option<String>,
}Expand description
Configuration and script-building for CDP leak protection.
Build via CdpProtection::from_env or CdpProtection::new, then call
CdpProtection::build_injection_script to obtain the JavaScript that
should be injected with Page.addScriptToEvaluateOnNewDocument.
§Example
use stygian_browser::cdp_protection::{CdpProtection, CdpFixMode};
let protection = CdpProtection::new(CdpFixMode::AddBinding, Some("app.js".to_string()));
let script = protection.build_injection_script();
assert!(script.contains("app.js"));Fields§
§mode: CdpFixModeActive fix mode.
source_url: Option<String>Custom source URL injected into Function.prototype.toString patch.
None = use default ("app.js").
Some("0") = disable source URL patching.
Implementations§
Source§impl CdpProtection
impl CdpProtection
Sourcepub const fn new(mode: CdpFixMode, source_url: Option<String>) -> Self
pub const fn new(mode: CdpFixMode, source_url: Option<String>) -> Self
Construct with explicit values.
§Example
use stygian_browser::cdp_protection::{CdpProtection, CdpFixMode};
let p = CdpProtection::new(CdpFixMode::AddBinding, None);
assert_eq!(p.mode, CdpFixMode::AddBinding);Sourcepub fn from_env() -> Self
pub fn from_env() -> Self
Read configuration from environment variables.
STYGIAN_CDP_FIX_MODE→CdpFixMode::from_envSTYGIAN_SOURCE_URL→ custom source URL string (0to disable)
Sourcepub fn build_injection_script(&self) -> String
pub fn build_injection_script(&self) -> String
Build the JavaScript injection script for the configured mode.
The returned string should be passed to
Page.addScriptToEvaluateOnNewDocument so it runs before any page
code executes.
Returns an empty string when CdpFixMode::None is active.
§Example
use stygian_browser::cdp_protection::{CdpProtection, CdpFixMode};
let p = CdpProtection::new(CdpFixMode::AddBinding, Some("bundle.js".to_string()));
let script = p.build_injection_script();
assert!(script.contains("bundle.js"));
assert!(!script.is_empty());Sourcepub fn is_active(&self) -> bool
pub fn is_active(&self) -> bool
Whether protection is active (mode is not CdpFixMode::None).
Trait Implementations§
Source§impl Clone for CdpProtection
impl Clone for CdpProtection
Source§fn clone(&self) -> CdpProtection
fn clone(&self) -> CdpProtection
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more