chromiumoxide/handler/
browser.rs

1use chromiumoxide_cdp::cdp::browser_protocol::browser::BrowserContextId;
2
3/// BrowserContexts provide a way to operate multiple independent browser
4/// sessions. When a browser is launched, it has a single BrowserContext used by
5/// default.
6///
7/// If a page opens another page, e.g. with a `window.open` call, the popup will
8/// belong to the parent page's browser context.
9#[derive(Debug, Clone, Default, Hash, Eq, PartialEq)]
10pub struct BrowserContext {
11    /// The browser context ID.
12    pub id: Option<BrowserContextId>,
13}
14
15impl BrowserContext {
16    /// Whether the BrowserContext is incognito.
17    pub fn is_incognito(&self) -> bool {
18        self.id.is_some()
19    }
20
21    /// The identifier of this context
22    pub fn id(&self) -> Option<&BrowserContextId> {
23        self.id.as_ref()
24    }
25
26    pub(crate) fn take(&mut self) -> Option<BrowserContextId> {
27        self.id.take()
28    }
29}
30
31impl From<BrowserContextId> for BrowserContext {
32    fn from(id: BrowserContextId) -> Self {
33        Self { id: Some(id) }
34    }
35}