Skip to main content

rightkit_browser/
lib.rs

1//! Shared Chrome DevTools Protocol browser runtime for Right Suite products.
2//!
3//! * [`BrowserSession`] owns one Chrome process and any number of pages. Launch uses Chrome
4//!   for Testing ([`chrome_for_testing_path`]); the system browser only with
5//!   [`LaunchOptions::system_chrome`] or [`LaunchOptions::system_chrome_only`].
6//!   Shutdown and drop close gracefully (CDP
7//!   `Browser.close` / SIGTERM to the process group, bounded waits, SIGKILL last).
8//! * [`ProfileSpec`] selects a temporary, named persistent, or caller-owned directory profile.
9//! * Pointer and keyboard actions use real `Input.dispatch*Event` commands, so
10//!   `event.isTrusted`, `:hover`, focus, and default actions behave as for a user.
11//! * [`NetworkPolicy`] blocks loopback/link-local/private/reserved/`file:` targets
12//!   (redirects, subresources, and every proxied connection included) before they
13//!   reach the network; denials are typed ([`BrowserError::Blocked`]).
14//! * [`AdmissionHook`] then gates every effect before it happens.
15//! * [`BrowserEvent`] reports start/stop/crash/denied with session id, reason, and time.
16//! * [`BrowserPage::set_request_interceptor`] lets the caller continue, rewrite, fulfil or fail
17//!   every request after the network policy; [`BrowserPage::accessibility_tree`],
18//!   [`BrowserPage::exceptions`], [`BrowserPage::set_page_scale`] and
19//!   [`BrowserPage::set_download_behavior`] expose the matching CDP domains.
20//! * Real-session mode (consent-gated): [`default_browser`], [`UserConsentReceipt`],
21//!   [`ProfileSpec::ImportedFrom`] and [`BrowserSession::attach_user_browser`] reuse the user's
22//!   own sign-ins in a private copy, confined to the consented domains. See [`ImportSpec`].
23//! * [`cookies::parse_netscape`] reads a Netscape `cookies.txt` (bounded; values redacted in
24//!   `Debug` and errors) and [`BrowserPage::import_cookies`] sets the result in the profile.
25//!   With feature `cookie-export`, `CookieExport` goes the other way: it keeps the cookies of
26//!   declared domains and publishes them as a private Netscape file through rightkit-fs; an
27//!   empty or invalid export never replaces the previous file.
28//! * With feature `profile-vault`, `ProfileVault` and `LaunchOptions::encrypted_profile` keep
29//!   a persistent profile as one authenticated-encrypted file at rest: decrypted to a private
30//!   working directory for the session, re-sealed and wiped at stop, recovered after a crash, and
31//!   refused with a typed `VaultError` when the credential-store key is unavailable.
32//! * [`capture`] loads one real URL and returns a typed [`CaptureReport`]: load result, PNG,
33//!   metrics, console and (feature `axe`) axe-core output, each hashed and bound to the session,
34//!   process, profile, page, frame, loader and context that produced it, with the terminal
35//!   cleanup outcome ([`StopReport`]) of success, failure, timeout and cancellation alike.
36//! * [`BrowserPage::observe`] returns refs that are checked for staleness before use.
37//! * [`design_mode`] holds the element-picker primitives: an isolated-world binding bridge,
38//!   a one-shot native-gesture submit gate, device-pixel capture geometry and the picker script builder.
39// The source-only fixture browser is confined by macOS Seatbelt / the Windows sandbox; on other hosts its
40// constructors refuse and the rest of the fixture machinery is unreachable.
41#![cfg_attr(not(any(target_os = "macos", windows)), allow(dead_code))]
42mod capture;
43mod cdp_ext;
44mod config;
45#[cfg(feature = "cookie-export")]
46pub mod cookie_export;
47pub mod cookies;
48pub mod design_mode;
49mod error;
50mod fixture;
51mod fixture_protocol;
52mod fixture_server;
53#[cfg(feature = "install")]
54pub mod install;
55mod keys;
56mod page;
57#[cfg(windows)]
58mod pipe_transport;
59mod policy;
60mod proc;
61mod proxy;
62mod real_session;
63mod sandbox_access;
64mod session;
65#[cfg(feature = "profile-vault")]
66mod vault;
67mod visible;
68
69pub use capture::{
70    capture, AxeObservation, AxeSpec, AxeStatus, CaptureArtifact, CaptureBinding,
71    CaptureCancellation, CaptureIdentity, CaptureReport, CaptureRequest, CaptureStatus,
72    CleanupReport, ConsoleObservation, ConsoleRecord, LoadObservation, MetricsObservation,
73    ScreenshotArtifact, CAPTURE_SCHEMA, MAX_CAPTURE_AXE_BYTES, MAX_CAPTURE_CONSOLE_RECORDS,
74    MAX_CAPTURE_DEADLINE, MAX_CAPTURE_SCREENSHOT_BYTES, MAX_CAPTURE_VIEWPORT_EDGE,
75};
76#[cfg(feature = "axe")]
77pub use capture::{AXE_SHA256, AXE_VERSION};
78pub use cdp_ext::{
79    AxNode, AxSummary, ContinueOverrides, DownloadBehavior, ExceptionFrame, InterceptDecision,
80    InterceptFailure, InterceptStage, InterceptedRequest, PageException, RequestInterceptor,
81    MAX_EXCEPTIONS,
82};
83pub use config::{
84    chrome_for_testing_candidates, chrome_for_testing_path, find_chrome, LaunchOptions,
85    ManagedRoot, ProfileSpec, CHROME_FOR_TESTING_ENV, CHROME_FOR_TESTING_INSTALL_HINT,
86    CHROME_FOR_TESTING_ROOT_ENV,
87};
88#[cfg(feature = "cookie-export")]
89pub use cookie_export::{ClearOutcome, CookieExport, CookieExportError, ExportReport};
90pub use cookies::{
91    parse_netscape, CookieFieldError, CookieParseError, NetscapeCookie, MAX_COOKIES,
92    MAX_COOKIES_FILE_BYTES,
93};
94pub use error::{BrowserError, Result};
95pub use fixture::{
96    FixtureAttestation, FixtureCancellation, FixtureCleanupEvidence, FixtureConfinementBackend,
97    FixtureOutcome, FixtureOutcomeStatus, FixtureRunFailure, FixtureSession,
98};
99pub use fixture_protocol::{
100    actions_digest, FixtureAction, FixtureBundle, FixtureError, FixtureFile, FixtureIntent,
101    FixtureKey, FIXTURE_SCHEMA,
102};
103pub use fixture_server::FixtureServer;
104pub use page::{
105    BrowserPage, ConsoleLine, Observation, ObservedNode, Rect, ScreenshotClip, ScreenshotFormat,
106    ScreenshotOptions, Target, MAX_EXTRA_HEADERS, MAX_HEADER_VALUE_BYTES, MAX_USER_AGENT_BYTES,
107    OBSERVE_AX_DEPTH,
108};
109pub use policy::{
110    classify_ip, ActionKind, AddressClass, AdmissionHook, AdmissionRequest, AllowCallback,
111    BlockReason, BlockedRequest, BrowserEvent, BrowserRequest, Decision, EventSink, LifecycleKind,
112    NetworkPolicy, NetworkRequest, PolicyDecision, PolicyDenial, Resolver,
113};
114pub use proxy::PinnedConnection;
115pub use real_session::{
116    browser_executable, default_browser, list_profiles, purge_imported_profile, user_data_dir,
117    BrowserKind, BrowserSource, ConsentRevocation, ImportReport, ImportSpec, SourceProfile,
118    UserConsentReceipt, CONSENT_SCHEMA,
119};
120pub use session::{BrowserSession, PageSetup, StopReport};
121#[cfg(feature = "profile-vault")]
122pub use vault::{ProfileVault, VaultError};
123pub use visible::{run_visible_until_exit, VisibleExit, VisibleLaunch};