chromiumoxide/handler/
browser.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use chromiumoxide_cdp::cdp::browser_protocol::browser::BrowserContextId;

/// BrowserContexts provide a way to operate multiple independent browser
/// sessions. When a browser is launched, it has a single BrowserContext used by
/// default.
///
/// If a page opens another page, e.g. with a `window.open` call, the popup will
/// belong to the parent page's browser context.
#[derive(Debug, Clone, Default, Hash, Eq, PartialEq)]
pub struct BrowserContext {
    pub id: Option<BrowserContextId>,
}

impl BrowserContext {
    /// Whether the BrowserContext is incognito.
    pub fn is_incognito(&self) -> bool {
        self.id.is_some()
    }

    /// The identifier of this context
    pub fn id(&self) -> Option<&BrowserContextId> {
        self.id.as_ref()
    }

    pub(crate) fn take(&mut self) -> Option<BrowserContextId> {
        self.id.take()
    }
}

impl From<BrowserContextId> for BrowserContext {
    fn from(id: BrowserContextId) -> Self {
        Self { id: Some(id) }
    }
}