pub struct BrowserSession { /* private fields */ }Expand description
One Chrome process with any number of pages.
Implementations§
Source§impl BrowserSession
impl BrowserSession
pub async fn launch(opts: LaunchOptions) -> Result<Self>
Sourcepub async fn attach_user_browser(
consent: UserConsentReceipt,
root: impl Into<PathBuf>,
opts: LaunchOptions,
) -> Result<Self>
pub async fn attach_user_browser( consent: UserConsentReceipt, root: impl Into<PathBuf>, opts: LaunchOptions, ) -> Result<Self>
Start a visible session that reuses the user’s own browser sign-ins, with consent.
Chrome 136+ ignores a debugging port on the browser’s default user-data directory and a
profile in use is locked, so the user’s running browser is not driven in place: the
consented profile’s sign-in files are copied into a private RightKit profile under root
and the same browser (same executable, so its sign-in key applies) is launched on that
copy over a debugging pipe. The consented domains confine every action, passwords are
refused, and consent is checked at launch and before each action.
Chromium-family browsers only (Chrome, Edge, Brave, Chromium); Safari and Firefox return
BrowserError::Unsupported. opts supplies timeouts, network policy and the admission
hook (which runs after the consent check); its profile, executable and window mode are
replaced.
Sourcepub async fn attach_user_browser_revocable(
consent: UserConsentReceipt,
revocation: ConsentRevocation,
root: impl Into<PathBuf>,
opts: LaunchOptions,
) -> Result<Self>
pub async fn attach_user_browser_revocable( consent: UserConsentReceipt, revocation: ConsentRevocation, root: impl Into<PathBuf>, opts: LaunchOptions, ) -> Result<Self>
Self::attach_user_browser with a live crate::ConsentRevocation: revoking it
makes the session’s next action fail.
pub fn id(&self) -> &str
Sourcepub fn process_id(&self) -> Option<u32>
pub fn process_id(&self) -> Option<u32>
OS process id of the Chrome child this session owns.
Sourcepub fn pinned_connections(&self) -> Vec<PinnedConnection>
pub fn pinned_connections(&self) -> Vec<PinnedConnection>
Connections the pinning proxy made, with the address it pinned for each.
pub fn is_headless(&self) -> bool
pub fn profile_dir(&self) -> &Path
pub fn download_dir(&self) -> &Path
Sourcepub async fn new_page(&self, url: &str) -> Result<Arc<BrowserPage>>
pub async fn new_page(&self, url: &str) -> Result<Arc<BrowserPage>>
Open a new page (tab), make it current, and navigate to url.
Sourcepub async fn new_page_with(
&self,
url: &str,
setup: PageSetup,
) -> Result<Arc<BrowserPage>>
pub async fn new_page_with( &self, url: &str, setup: PageSetup, ) -> Result<Arc<BrowserPage>>
Open a new page, install setup (request interceptor, download behaviour) before its
first navigation, then navigate to url. Unlike new_page followed by goto, the
interceptor sees the very first request: the tab’s own about:blank commit is waited out
first, and url is only requested once the setup is in place. about:blank opens a
page with the setup installed and no navigation.
pub fn pages(&self) -> Vec<Arc<BrowserPage>>
pub fn page(&self, id: &str) -> Result<Arc<BrowserPage>>
Sourcepub fn current(&self) -> Result<Arc<BrowserPage>>
pub fn current(&self) -> Result<Arc<BrowserPage>>
The page actions default to.
Sourcepub async fn select_page(&self, id: &str) -> Result<Arc<BrowserPage>>
pub async fn select_page(&self, id: &str) -> Result<Arc<BrowserPage>>
Make id current and bring it to the front.
pub async fn close_page(&self, id: &str) -> Result<()>
Sourcepub fn downloads(&self) -> HashSet<PathBuf>
pub fn downloads(&self) -> HashSet<PathBuf>
Completed files currently in the download directory.
Sourcepub async fn wait_download(
&self,
before: &HashSet<PathBuf>,
timeout: Duration,
) -> Result<PathBuf>
pub async fn wait_download( &self, before: &HashSet<PathBuf>, timeout: Duration, ) -> Result<PathBuf>
Wait for a download not in before to finish (no .crdownload, stable size).
Sourcepub async fn set_permission(
&self,
origin: Option<&str>,
name: &str,
granted: bool,
) -> Result<()>
pub async fn set_permission( &self, origin: Option<&str>, name: &str, granted: bool, ) -> Result<()>
Set a W3C permission (geolocation, notifications, clipboard-read,
midi, …) to granted or denied for origin, or every origin when None.
pub async fn reset_permissions(&self) -> Result<()>
Sourcepub async fn shutdown(&self)
pub async fn shutdown(&self)
Close Chrome gracefully: CDP Browser.close and up to 5 s for exit, then SIGTERM to
the process group and up to 5 s more, then SIGKILL (job termination on Windows).
Safe to call twice. A temporary profile is deleted once Chrome has exited.
Sourcepub async fn close(&self) -> Result<()>
pub async fn close(&self) -> Result<()>
Self::shutdown that reports failure. Err when Chrome’s process tree did not stop
cleanly (BrowserError::Stop) or the profile was not released: a temporary profile that
still exists, or an encrypted profile (ProfileSpec::Encrypted, feature profile-vault)
that could not be sealed or whose plaintext working directory could not be wiped (the tree
is then left in place and the next start recovers it). A profile failure is reported first.
Sourcepub async fn cancel(&self)
pub async fn cancel(&self)
Cancel: kill the owned Chrome now and wait for it to exit. Helper processes exit with their parent; none are detached.
Sourcepub async fn shutdown_report(&self) -> StopReport
pub async fn shutdown_report(&self) -> StopReport
Self::shutdown that returns the terminal outcome of every cleanup step instead of
discarding it: whether Chrome’s process tree stopped without error and whether the profile
was released (temporary profile deleted, encrypted profile sealed and wiped). A Stop
lifecycle event is not evidence of either; this report is.
Sourcepub async fn cancel_report(&self) -> StopReport
pub async fn cancel_report(&self) -> StopReport
Self::cancel with the same terminal StopReport.