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;
60mod pipe_transport;
61mod policy;
62mod proc;
63mod proxy;
64mod real_session;
65mod sandbox_access;
66mod session;
67#[cfg(feature = "profile-vault")]
68mod vault;
69mod visible;
70
71pub use act::{
72 ActResult, NodeChange, NodeState, ObservationDiff, RefAction, DEFAULT_ACTION_LOOP_LIMIT,
73};
74pub use capture::{
75 capture, AxeObservation, AxeSpec, AxeStatus, CaptureArtifact, CaptureBinding,
76 CaptureCancellation, CaptureIdentity, CaptureReport, CaptureRequest, CaptureStatus,
77 CleanupReport, ConsoleObservation, ConsoleRecord, LoadObservation, MetricsObservation,
78 ScreenshotArtifact, CAPTURE_SCHEMA, MAX_CAPTURE_AXE_BYTES, MAX_CAPTURE_CONSOLE_RECORDS,
79 MAX_CAPTURE_DEADLINE, MAX_CAPTURE_SCREENSHOT_BYTES, MAX_CAPTURE_VIEWPORT_EDGE,
80};
81#[cfg(feature = "axe")]
82pub use capture::{AXE_SHA256, AXE_VERSION};
83pub use cdp_ext::{
84 AxNode, AxSummary, ContinueOverrides, DownloadBehavior, ExceptionFrame, InterceptDecision,
85 InterceptFailure, InterceptStage, InterceptedRequest, PageException, RequestInterceptor,
86 MAX_EXCEPTIONS,
87};
88pub use config::{
89 chrome_for_testing_candidates, chrome_for_testing_path, find_chrome, LaunchOptions,
90 ManagedRoot, ProfileSpec, CHROME_FOR_TESTING_ENV, CHROME_FOR_TESTING_INSTALL_HINT,
91 CHROME_FOR_TESTING_ROOT_ENV,
92};
93#[cfg(feature = "cookie-export")]
94pub use cookie_export::{ClearOutcome, CookieExport, CookieExportError, ExportReport};
95pub use cookies::{
96 parse_netscape, CookieFieldError, CookieParseError, NetscapeCookie, MAX_COOKIES,
97 MAX_COOKIES_FILE_BYTES,
98};
99pub use error::{BrowserError, Result};
100pub use fixture::{
101 FixtureAttestation, FixtureCancellation, FixtureCleanupEvidence, FixtureConfinementBackend,
102 FixtureOutcome, FixtureOutcomeStatus, FixtureRunFailure, FixtureSession,
103};
104pub use fixture_protocol::{
105 actions_digest, FixtureAction, FixtureBundle, FixtureError, FixtureFile, FixtureIntent,
106 FixtureKey, FIXTURE_SCHEMA,
107};
108pub use fixture_server::FixtureServer;
109pub use page::{
110 BrowserPage, ConsoleLine, Observation, ObservedNode, Rect, ScreenshotClip, ScreenshotFormat,
111 ScreenshotOptions, Target, MAX_EXTRA_HEADERS, MAX_HEADER_VALUE_BYTES, MAX_USER_AGENT_BYTES,
112 OBSERVE_AX_DEPTH,
113};
114pub use policy::{
115 classify_ip, ActionKind, AddressClass, AdmissionHook, AdmissionRequest, AllowCallback,
116 BlockReason, BlockedRequest, BrowserEvent, BrowserRequest, Decision, EventSink, LifecycleKind,
117 NetworkPolicy, NetworkRequest, PolicyDecision, PolicyDenial, Resolver,
118};
119pub use proxy::PinnedConnection;
120pub use real_session::{
121 browser_executable, default_browser, list_profiles, purge_imported_profile, user_data_dir,
122 BrowserKind, BrowserSource, ConsentRevocation, ImportReport, ImportSpec, SourceProfile,
123 UserConsentReceipt, CONSENT_SCHEMA,
124};
125pub use session::{BrowserSession, PageSetup, StopReport};
126#[cfg(feature = "profile-vault")]
127pub use vault::{ProfileVault, VaultError};
128pub use visible::{run_visible_until_exit, VisibleExit, VisibleLaunch};