use chromiumoxide_cdp::cdp::js_protocol::runtime::ExecutionContextId;
#[derive(Debug, Clone, Default)]
pub struct DOMWorld {
execution_ctx: Option<ExecutionContextId>,
execution_ctx_unique_id: Option<String>,
detached: bool,
}
impl DOMWorld {
pub fn main_world() -> Self {
Self {
execution_ctx: None,
execution_ctx_unique_id: None,
detached: false,
}
}
pub fn secondary_world() -> Self {
Self {
execution_ctx: None,
execution_ctx_unique_id: None,
detached: false,
}
}
pub fn execution_context(&self) -> Option<ExecutionContextId> {
self.execution_ctx
}
pub fn execution_context_unique_id(&self) -> Option<&str> {
self.execution_ctx_unique_id.as_deref()
}
pub fn set_context(&mut self, ctx: ExecutionContextId, unique_id: String) {
self.execution_ctx = Some(ctx);
self.execution_ctx_unique_id = Some(unique_id);
}
pub fn take_context(&mut self) -> (Option<ExecutionContextId>, Option<String>) {
(
self.execution_ctx.take(),
self.execution_ctx_unique_id.take(),
)
}
pub fn is_detached(&self) -> bool {
self.detached
}
}
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub enum DOMWorldKind {
#[default]
Main,
Secondary,
}