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 moreSource§impl Debug for CdpProtection
impl Debug for CdpProtection
Auto Trait Implementations§
impl Freeze for CdpProtection
impl RefUnwindSafe for CdpProtection
impl Send for CdpProtection
impl Sync for CdpProtection
impl Unpin for CdpProtection
impl UnsafeUnpin for CdpProtection
impl UnwindSafe for CdpProtection
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more