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; [`BrowserPage::act`]
37//!   runs one action on a ref (epoch, document, tag, role and name checked first) and returns the diff,
38//!   and stops a run that repeats the same no-effect action ([`BrowserError::ActionLoop`]).
39//! * [`design_mode`] holds the element-picker primitives: an isolated-world binding bridge,
40//!   a one-shot native-gesture submit gate, device-pixel capture geometry and the picker script builder.
41// The source-only fixture browser is confined by macOS Seatbelt / the Windows sandbox; on other hosts its
42// constructors refuse and the rest of the fixture machinery is unreachable.
43#![cfg_attr(not(any(target_os = "macos", windows)), allow(dead_code))]
44mod act;
45mod capture;
46mod cdp_ext;
47mod config;
48#[cfg(feature = "cookie-export")]
49pub mod cookie_export;
50pub mod cookies;
51pub mod design_mode;
52mod error;
53mod fixture;
54mod fixture_protocol;
55mod fixture_server;
56#[cfg(feature = "install")]
57pub mod install;
58mod keys;
59mod page;
60#[cfg(windows)]
61mod pipe_transport;
62mod policy;
63mod proc;
64mod proxy;
65mod real_session;
66mod sandbox_access;
67mod session;
68#[cfg(feature = "profile-vault")]
69mod vault;
70mod visible;
71
72pub use act::{
73    ActResult, NodeChange, NodeState, ObservationDiff, RefAction, DEFAULT_ACTION_LOOP_LIMIT,
74};
75pub use capture::{
76    capture, AxeObservation, AxeSpec, AxeStatus, CaptureArtifact, CaptureBinding,
77    CaptureCancellation, CaptureIdentity, CaptureReport, CaptureRequest, CaptureStatus,
78    CleanupReport, ConsoleObservation, ConsoleRecord, LoadObservation, MetricsObservation,
79    ScreenshotArtifact, CAPTURE_SCHEMA, MAX_CAPTURE_AXE_BYTES, MAX_CAPTURE_CONSOLE_RECORDS,
80    MAX_CAPTURE_DEADLINE, MAX_CAPTURE_SCREENSHOT_BYTES, MAX_CAPTURE_VIEWPORT_EDGE,
81};
82#[cfg(feature = "axe")]
83pub use capture::{AXE_SHA256, AXE_VERSION};
84pub use cdp_ext::{
85    AxNode, AxSummary, ContinueOverrides, DownloadBehavior, ExceptionFrame, InterceptDecision,
86    InterceptFailure, InterceptStage, InterceptedRequest, PageException, RequestInterceptor,
87    MAX_EXCEPTIONS,
88};
89pub use config::{
90    chrome_for_testing_candidates, chrome_for_testing_path, find_chrome, LaunchOptions,
91    ManagedRoot, ProfileSpec, CHROME_FOR_TESTING_ENV, CHROME_FOR_TESTING_INSTALL_HINT,
92    CHROME_FOR_TESTING_ROOT_ENV,
93};
94#[cfg(feature = "cookie-export")]
95pub use cookie_export::{ClearOutcome, CookieExport, CookieExportError, ExportReport};
96pub use cookies::{
97    parse_netscape, CookieFieldError, CookieParseError, NetscapeCookie, MAX_COOKIES,
98    MAX_COOKIES_FILE_BYTES,
99};
100pub use error::{BrowserError, Result};
101pub use fixture::{
102    FixtureAttestation, FixtureCancellation, FixtureCleanupEvidence, FixtureConfinementBackend,
103    FixtureOutcome, FixtureOutcomeStatus, FixtureRunFailure, FixtureSession,
104};
105pub use fixture_protocol::{
106    actions_digest, FixtureAction, FixtureBundle, FixtureError, FixtureFile, FixtureIntent,
107    FixtureKey, FIXTURE_SCHEMA,
108};
109pub use fixture_server::FixtureServer;
110pub use page::{
111    BrowserPage, ConsoleLine, Observation, ObservedNode, Rect, ScreenshotClip, ScreenshotFormat,
112    ScreenshotOptions, Target, MAX_EXTRA_HEADERS, MAX_HEADER_VALUE_BYTES, MAX_USER_AGENT_BYTES,
113    OBSERVE_AX_DEPTH,
114};
115pub use policy::{
116    classify_ip, ActionKind, AddressClass, AdmissionHook, AdmissionRequest, AllowCallback,
117    BlockReason, BlockedRequest, BrowserEvent, BrowserRequest, Decision, EventSink, LifecycleKind,
118    NetworkPolicy, NetworkRequest, PolicyDecision, PolicyDenial, Resolver,
119};
120pub use proxy::PinnedConnection;
121pub use real_session::{
122    browser_executable, default_browser, list_profiles, purge_imported_profile, user_data_dir,
123    BrowserKind, BrowserSource, ConsentRevocation, ImportReport, ImportSpec, SourceProfile,
124    UserConsentReceipt, CONSENT_SCHEMA,
125};
126pub use session::{BrowserSession, PageSetup, StopReport};
127#[cfg(feature = "profile-vault")]
128pub use vault::{ProfileVault, VaultError};
129pub use visible::{run_visible_until_exit, VisibleExit, VisibleLaunch};