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//! * [`DestinationFilter`] (installed with [`NetworkPolicy::with_destination_filter`]) closes the list
15//! by resource class, so script, worker, fetch, XHR and socket destinations are filtered, not only
16//! page addresses.
17//! * [`AdmissionHook`] then gates every effect before it happens.
18//! * [`BrowserEvent`] reports start/stop/crash/denied with session id, reason, and time.
19//! * [`BrowserPage::set_request_interceptor`] lets the caller continue, rewrite, fulfil or fail
20//! every request after the network policy; [`BrowserPage::accessibility_tree`],
21//! [`BrowserPage::exceptions`], [`BrowserPage::set_page_scale`] and
22//! [`BrowserPage::set_download_behavior`] expose the matching CDP domains.
23//! * Real-session mode (consent-gated): [`default_browser`], [`UserConsentReceipt`],
24//! [`ProfileSpec::ImportedFrom`] and [`BrowserSession::attach_user_browser`] reuse the user's
25//! own sign-ins in a private copy, confined to the consented domains. See [`ImportSpec`].
26//! * [`cookies::parse_netscape`] reads a Netscape `cookies.txt` (bounded; values redacted in
27//! `Debug` and errors) and [`BrowserPage::import_cookies`] sets the result in the profile.
28//! With feature `cookie-export`, `CookieExport` goes the other way: it keeps the cookies of
29//! declared domains and publishes them as a private Netscape file through rightkit-fs; an
30//! empty or invalid export never replaces the previous file.
31//! * With feature `profile-vault`, `ProfileVault` and `LaunchOptions::encrypted_profile` keep
32//! a persistent profile as one authenticated-encrypted file at rest: decrypted to a private
33//! working directory for the session, re-sealed and wiped at stop, recovered after a crash, and
34//! refused with a typed `VaultError` when the credential-store key is unavailable.
35//! `ProfileVault::for_agent` gives each agent its own profile and key from an `AgentProfileId`.
36//! * [`capture`] loads one real URL and returns a typed [`CaptureReport`]: load result, PNG,
37//! metrics, console and (feature `axe`) axe-core output, each hashed and bound to the session,
38//! process, profile, page, frame, loader and context that produced it, with the terminal
39//! cleanup outcome ([`StopReport`]) of success, failure, timeout and cancellation alike.
40//! * [`BrowserPage::observe`] returns refs that are checked for staleness before use; [`BrowserPage::act`]
41//! runs one action on a ref (epoch, document, tag, role and name checked first) and returns the diff,
42//! and stops a run that repeats the same no-effect action ([`BrowserError::ActionLoop`]).
43//! * [`design_mode`] holds the element-picker primitives: an isolated-world binding bridge,
44//! a one-shot native-gesture submit gate, device-pixel capture geometry and the picker script builder.
45// The source-only fixture browser is confined by macOS Seatbelt / the Windows sandbox; on other hosts its
46// constructors refuse and the rest of the fixture machinery is unreachable.
47#![cfg_attr(not(any(target_os = "macos", windows)), allow(dead_code))]
48mod act;
49mod capture;
50mod cdp_ext;
51mod config;
52#[cfg(feature = "cookie-export")]
53pub mod cookie_export;
54pub mod cookies;
55pub mod design_mode;
56mod error;
57mod fixture;
58mod fixture_protocol;
59mod fixture_server;
60#[cfg(feature = "install")]
61pub mod install;
62mod keys;
63mod page;
64mod pipe_transport;
65mod policy;
66mod proc;
67mod proxy;
68mod real_session;
69mod sandbox_access;
70mod session;
71#[cfg(feature = "profile-vault")]
72mod vault;
73mod visible;
74
75pub use act::{
76 ActResult, NodeChange, NodeState, ObservationDiff, RefAction, DEFAULT_ACTION_LOOP_LIMIT,
77};
78pub use capture::{
79 capture, AxeObservation, AxeSpec, AxeStatus, CaptureArtifact, CaptureBinding,
80 CaptureCancellation, CaptureIdentity, CaptureReport, CaptureRequest, CaptureStatus,
81 CleanupReport, ConsoleObservation, ConsoleRecord, LoadObservation, MetricsObservation,
82 ScreenshotArtifact, CAPTURE_SCHEMA, MAX_CAPTURE_AXE_BYTES, MAX_CAPTURE_CONSOLE_RECORDS,
83 MAX_CAPTURE_DEADLINE, MAX_CAPTURE_SCREENSHOT_BYTES, MAX_CAPTURE_VIEWPORT_EDGE,
84};
85#[cfg(feature = "axe")]
86pub use capture::{AXE_SHA256, AXE_VERSION};
87pub use cdp_ext::{
88 AxNode, AxSummary, ContinueOverrides, DownloadBehavior, ExceptionFrame, InterceptDecision,
89 InterceptFailure, InterceptStage, InterceptedRequest, PageException, RequestInterceptor,
90 MAX_EXCEPTIONS,
91};
92pub use config::{
93 chrome_for_testing_candidates, chrome_for_testing_path, find_chrome, LaunchOptions,
94 ManagedRoot, ProfileSpec, CHROME_FOR_TESTING_INSTALL_HINT,
95};
96#[cfg(feature = "host-env")]
97pub use config::{CHROME_FOR_TESTING_ENV, CHROME_FOR_TESTING_ROOT_ENV};
98#[cfg(feature = "cookie-export")]
99pub use cookie_export::{ClearOutcome, CookieExport, CookieExportError, ExportReport};
100pub use cookies::{
101 parse_netscape, CookieFieldError, CookieParseError, NetscapeCookie, MAX_COOKIES,
102 MAX_COOKIES_FILE_BYTES,
103};
104pub use error::{BrowserError, Result};
105pub use fixture::{
106 FixtureAttestation, FixtureCancellation, FixtureCleanupEvidence, FixtureConfinementBackend,
107 FixtureOutcome, FixtureOutcomeStatus, FixtureRunFailure, FixtureSession,
108};
109pub use fixture_protocol::{
110 actions_digest, FixtureAction, FixtureBundle, FixtureError, FixtureFile, FixtureIntent,
111 FixtureKey, FIXTURE_SCHEMA,
112};
113pub use fixture_server::FixtureServer;
114pub use page::{
115 BrowserPage, ConsoleLine, Observation, ObservedNode, Rect, ScreenshotClip, ScreenshotFormat,
116 ScreenshotOptions, Target, MAX_EXTRA_HEADERS, MAX_HEADER_VALUE_BYTES, MAX_USER_AGENT_BYTES,
117 OBSERVE_AX_DEPTH,
118};
119pub use policy::{
120 classify_ip, ActionKind, AddressClass, AdmissionHook, AdmissionRequest, AllowCallback,
121 BlockReason, BlockedRequest, BrowserEvent, BrowserRequest, Decision, DestinationFilter,
122 DestinationRule, EventSink, LifecycleKind, NetworkPolicy, NetworkRequest, PolicyDecision,
123 PolicyDenial, Resolver, ResourceClass,
124};
125pub use proxy::PinnedConnection;
126pub use real_session::{
127 browser_executable, default_browser, list_profiles, purge_imported_profile, user_data_dir,
128 BrowserKind, BrowserSource, ConsentRevocation, ImportReport, ImportSpec, SourceProfile,
129 UserConsentReceipt, CONSENT_SCHEMA,
130};
131pub use session::{BrowserSession, PageSetup, StopReport};
132#[cfg(feature = "profile-vault")]
133pub use vault::{ProfileVault, VaultError};
134pub use visible::{run_visible_until_exit, VisibleExit, VisibleLaunch};