chromiumoxide/handler/
domworld.rs1use chromiumoxide_cdp::cdp::js_protocol::runtime::ExecutionContextId;
2
3#[derive(Debug, Clone, Default)]
4pub struct DOMWorld {
5 execution_ctx: Option<ExecutionContextId>,
6 execution_ctx_unique_id: Option<String>,
7 detached: bool,
8}
9
10impl DOMWorld {
11 pub fn main_world() -> Self {
12 Self {
13 execution_ctx: None,
14 execution_ctx_unique_id: None,
15 detached: false,
16 }
17 }
18
19 pub fn secondary_world() -> Self {
20 Self {
21 execution_ctx: None,
22 execution_ctx_unique_id: None,
23 detached: false,
24 }
25 }
26
27 pub fn execution_context(&self) -> Option<ExecutionContextId> {
28 self.execution_ctx
29 }
30
31 pub fn execution_context_unique_id(&self) -> Option<&str> {
32 self.execution_ctx_unique_id.as_deref()
33 }
34
35 pub fn set_context(&mut self, ctx: ExecutionContextId, unique_id: String) {
36 self.execution_ctx = Some(ctx);
37 self.execution_ctx_unique_id = Some(unique_id);
38 }
39
40 pub fn take_context(&mut self) -> (Option<ExecutionContextId>, Option<String>) {
41 (
42 self.execution_ctx.take(),
43 self.execution_ctx_unique_id.take(),
44 )
45 }
46
47 pub fn is_detached(&self) -> bool {
48 self.detached
49 }
50}
51
52#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
63pub enum DOMWorldKind {
64 #[default]
67 Main,
68 Secondary,
70}