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    pub id: Option<BrowserContextId>,
12}
13
14impl BrowserContext {
15    /// Whether the BrowserContext is incognito.
16    pub fn is_incognito(&self) -> bool {
17        self.id.is_some()
18    }
19
20    /// The identifier of this context
21    pub fn id(&self) -> Option<&BrowserContextId> {
22        self.id.as_ref()
23    }
24
25    pub(crate) fn take(&mut self) -> Option<BrowserContextId> {
26        self.id.take()
27    }
28}
29
30impl From<BrowserContextId> for BrowserContext {
31    fn from(id: BrowserContextId) -> Self {
32        Self { id: Some(id) }
33    }
34}