rightkit-browser
Shared Chrome DevTools Protocol browser runtime for Right Suite products. BrowserSession owns one Chrome process and any number of pages. Input is real Input.dispatch*Event input, so event.isTrusted, :hover, focus and default actions behave as they do for a user. Sessions run headless, muted and on a temporary profile by default; headed and persistent profiles are opt-in.
Catalog capability: browser-automation.
What it owns
BrowserSession: one Chrome process, multi-page sessions, graceful shutdown and drop.ProfileSpec: a temporary profile, a named persistent profile (named_profile(root, name)), or a caller-owned directory (profile_dir(path)).NetworkPolicy: blocks loopback, link-local, private, reserved andfile:targets, including redirects, subresources and proxied connections. Denials are typed (BrowserError::Blocked).AdmissionHook: gates each effect before it runs.BrowserEventreports start, stop, crash and denied events.BrowserPage::observe: returns element refs that are checked for staleness before use.- Chrome for Testing resolution (
chrome_for_testing_path) and the explicit system-browser modes.
When to use it
- Use it to drive a real Chromium page from Rust with trusted input, for QA, scraping or product automation.
- Use it when pages must be reached through an SSRF-safe network policy.
Do not use it to drive Safari or Firefox, or desktop apps (see rightkit-automation and rightkit-qa-driver).
Cargo features
install (off by default): install::ensure_chrome_for_testing; pulls rightkit-models, rightkit-fs and zip. Dependencies include chromiumoxide 0.9, tokio, url, and rightkit-child-process for owned child processes.
cookie-export (off by default): CookieExport, which keeps the cookies of declared domains and publishes them as a private Netscape cookies.txt through rightkit-fs; an empty or invalid export never replaces the previous file, and CookieExport::clear_with removes the file and then runs a callback so the caller can invalidate an engine authentication snapshot. Build cookies with NetscapeCookie::new.
profile-vault (off by default): ProfileVault and ProfileSpec::Encrypted; pulls rightkit-credentials and rightkit-crypto. See "Encrypted profile".
host-env (off by default): the two environment overrides of Chrome resolution, RIGHTKIT_CHROME_FOR_TESTING (an executable) and RIGHTKIT_CHROME_FOR_TESTING_ROOT (the managed root), and the public names CHROME_FOR_TESTING_ENV and CHROME_FOR_TESTING_ROOT_ENV. Without it no environment variable selects the Chrome executable or its managed folder, and neither name is in the compiled code or in CHROME_FOR_TESTING_INSTALL_HINT: a release binary carries no S3 selector from this crate. Tests, QA runners and development tools enable it; a shipped app does not.
axe (off by default): compiles in the vendored axe-core 4.14.0 for capture (see "Capture").
Usage
Taken from the crate README and from LaunchOptions in src/config.rs. Illustrative: it is a no_run example.
use ;
# async
Loopback fixtures are blocked by default. tests/e2e.rs opts in for a local test server with LaunchOptions::default().network(NetworkPolicy::default().allow_host("127.0.0.1")).
Interception, accessibility, exceptions, scale, downloads
set_request_interceptor(Some(hook)):hook(InterceptedRequest) -> BoxFuture<InterceptDecision>runs for every request afterNetworkPolicy(policy refusals are final). AnswerContinue,ContinueWith(ContinueOverrides),Fulfill { status, headers, body, phrase }orFail(InterceptFailure). Redirect hops are separate requests (redirected_fromset): pin an origin by checkingurlon each. No answer in 30 s fails the request.accessibility_tree()returns the root frame'sVec<AxNode>;accessibility_tree_with(depth)cuts it off belowdepth.frames()lists CDP frame ids;target_id()is the tab's CDP target id (stable tab identity;id()is the session's own sequence).scroll_by(target, dx, dy)runsscrollByon an element, a point or the window, for cases where a wheel event at the element is wrong.set_transparent_background(true)withscreenshot_with(ScreenshotOptions { omit_background: true })captures a transparent PNG.BrowserSession::new_page_with(url, PageSetup { interceptor, download })installs the interceptor and download behaviour before the first request.act(ref, &RefAction)runs one action on a ref and returns anObservationDiff; the ref check compares epoch, document (frame and loader), tag, role and name (StaleRefon any mismatch); the watchdog refuses the identical no-diff action afterDEFAULT_ACTION_LOOP_LIMITrepeats (ActionLoop) untilreset_action_watch().observenodes carrysensitive,frame_id(the main frame; iframe content is not observed), andstable_id; the observation carriesax, a depth-bounded accessibility summary.design_modeholds the element-picker primitives (isolated-world binding bridge, one-shot native-gesture submit gate, capture geometry),build_design_mode_script(nonce)andBrowserPage::enable_design_mode. Observation covers the main document only; iframe observation is not implemented.exceptions()/subscribe_exceptions()returnPageExceptions fromRuntime.exceptionThrown, collected from page creation.set_page_scale(f64)sets the pinch-zoom page scale.set_download_behavior(&DownloadBehavior)sets deny, allow into an explicit directory, allow named by GUID, or default.
Chrome resolution
Launch resolves Chrome for Testing (chrome_for_testing_path) in this order: LaunchOptions::chrome_path, then (feature host-env only) the RIGHTKIT_CHROME_FOR_TESTING environment variable, then the RightKit-managed current folder (one fixed path, with a single current.previous kept for rollback; legacy per-version folders are tried after it, newest first), app installs, and the newest Puppeteer or Playwright cache builds.
| Platform | Managed executable |
|---|---|
| macOS ARM64 | ~/Library/Application Support/Orthic Labs/shared/chrome-for-testing/current/chrome-mac-arm64/Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing |
| macOS x64 | ~/Library/Application Support/Orthic Labs/shared/chrome-for-testing/current/chrome-mac-x64/Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing |
| Windows | %LOCALAPPDATA%\Orthic Labs\shared\chrome-for-testing\current\chrome-win64\chrome.exe |
| Linux | $XDG_DATA_HOME/Orthic Labs/shared/chrome-for-testing/current/chrome-linux64/chrome (XDG_DATA_HOME defaults to ~/.local/share) |
The install cargo feature adds install::ensure_chrome_for_testing(&ManagedRoot, &PinnedChrome) for an app's installer or updater step: it downloads through rightkit-models, checks the pinned SHA-256 before extracting, extracts to current.staging, swaps into current and keeps current.previous. A pin whose digest is Sha256Pin::Todo is refused.
- With feature
host-env,RIGHTKIT_CHROME_FOR_TESTING_ROOToverrides only the managed root; without it the managed root is always the suite-wide default. An explicit executable override keeps priority. - If Chrome for Testing is missing, launch returns
BrowserError::ChromeForTestingNotFoundwith install instructions. LaunchOptions::system_chrome()keeps the Chrome for Testing preference and falls back tofind_chrome()only when that resolution fails.LaunchOptions::system_chrome_only()resolves only throughfind_chrome(), including itsCHROMEoverride. It ignoreschrome_pathand Chrome for Testing discovery. If no system Chrome, Chromium or Edge exists, it returnsBrowserError::ChromeNotFound.- The last selection builder wins.
- The Windows fixture (AppContainer) launches
chrome-headless-shell.exefrom<version>/chrome-headless-shell-win64/beside the resolved Chrome (else any managed version;RIGHTKIT_CHROME_HEADLESS_SHELLnames it explicitly), notchrome.exe: Chrome's browser process always starts the crashpad handler, which cannot create its named pipe inside an AppContainer. Fixture only. - On macOS, a killed Chrome instance can leave a code-sign clone of its bundle behind when it does not shut down cleanly (
src/config.rs).
Profiles
profile_dir(path)selectsProfileSpec::Directory. Launch checks that the path is absolute, exists and is a directory, without creating it. Any existing directory is accepted, including real Chrome user-data directories, paths with spaces, and Unicode names. Named-profile validation stays exclusive tonamed_profile(root, name).- The caller owns that directory. This mode creates no RightKit profile lock, and shutdown, cancellation, failed launch or drop never removes it.
- Downloads go to
<profile>/rightkit-downloadsfor named and caller-owned profiles, and to<profile>/downloadsfor a temporary profile (src/session.rs:61,:81,:89), or toLaunchOptions::download_dirwhen it is set. The directory is created at launch.
Encrypted profile (feature profile-vault)
LaunchOptions::default().encrypted_profile(ProfileVault::new(store, root, "agent-login")?) keeps the persistent login profile as one authenticated-encrypted file, <root>/<name>.rkvault, and nothing readable on disk after a clean stop.
- Start: lock the vault (
VaultError::InUseif open elsewhere), read the key from the OS credential store throughrightkit-credentials(VaultError::KeyUnavailableand nothing touched when it cannot be read), recover a crashed session, decrypt into the private<root>/<name>.workdirectory and point Chrome at it. - Stop (
shutdown,close,cancel,Drop): after Chrome exits, archive and encrypt the tree to a temporary file, replace the vault atomically, then wipe the working directory.close()returnsErrwhen sealing or wiping failed; the tree then stays and the next start recovers it. - Crash recovery: a leftover working directory is sealed into the vault when its state file says
open, otherwise wiped; the sealed file is never replaced by a partial tree. - Key lost: a vault whose key is gone is
VaultError::KeyLostand untouched;ProfileVault::discardis the explicit way to start over. An earlier plaintextNamedprofile is refused withPlaintextProfilePresentuntilProfileVault::migrate_plaintextmoves it in. - Archive format (version 1, decision record in
src/vault.rs): headerRKPVAULT | version | cipher | chunk size | profile id | salt, then 1 MiB AES-256-GCM chunks with the header and a final flag as associated data; key = HKDF-SHA256(credential-store key, per-file salt, profile id). The plaintext stream holds directories and regular files only; Chrome'sSingleton*files,rightkit-downloadsand the lock file are skipped; a symlink elsewhere is refused. Downloads go to<root>/<name>.downloads, outside the vault. - Chrome also uses the real OS keychain now (no
--use-mock-keychainor--password-store=basic). - Limits: wiping overwrites files up to 16 MiB then deletes them; on flash or copy-on-write storage that does not guarantee the old blocks are gone, so full-disk encryption remains the defence for a stolen powered-off disk. The master key stays in memory for the session. Not verified live: Keychain prompts on first launch, Windows Credential Manager, behaviour of the macOS fixture sandbox without Keychain access.
Capture (typed, session-bound)
capture(CaptureRequest::new(url, CaptureBinding { plan_digest, source_digest, probe_digest, action_digest }, output_root), &CaptureCancellation::new()) launches its own session on a real page and returns a CaptureReport: load result (HTTP status), PNG, navigation and paint metrics (unavailable values are null), console and exceptions, and with feature axe the axe-core violations for the requested tags (AxeSpec::wcag2_aa()). Each artifact is written under a private directory with length and SHA-256; identity binds them to the browser session id, PID, profile, page, target, frame, loader and main-world context, to the request digest and to the caller's four digests. cleanup.stop is the session's StopReport (process tree stopped, profile released), present for success, failure, timeout and cancellation alike. status is Complete only when the page loaded below HTTP 400, every requested observation was whole and cleanup succeeded; otherwise Incomplete (with reasons), Failed, TimedOut or Cancelled, with whatever was collected.
- Decision (#821, option 2): built on
BrowserSessionand real pages, notFixtureSession: a fixture serves a sealed synthetic bundle with no script, while live surfaces are real pages (Adrian: no fixtures or dummy data). No script evaluation is exposed; observations run in an isolated execution world so the page cannot replace them. - The default network policy refuses loopback and private hosts; allow a dev server's host in
CaptureRequest::network. - axe-core 4.14.0 is MPL-2.0 and vendored unmodified in
third-party/axe-core/behind featureaxe:NOTICE.mdrecords the upstream tag, the SHA-256 (20c09fe157a8a34a30e241aaa1fcdade657734f08ab379ecfbeb7d45cc46e878, also theAXE_SHA256constant checked before every use) and the MPL-2.0 text. The workspacedeny.tomlalready allowsMPL-2.0for unmodified third-party code; the crate's own code staysMIT OR Apache-2.0, the same layout asrightkit-ffmpeg/third-party. - Not covered by the report: the network proxy has no stop receipt (it is dropped with the session), and there is no fixture server in this route.
Real session (the user's own sign-ins, with consent)
BrowserSession::attach_user_browser(consent, root, opts) opens a visible Chrome or Edge window on a private copy of the user's consented profile, so the agent starts signed in. It never drives the live browser in place (a running profile is locked, and Chrome 136+ ignores remote debugging on the default user-data directory).
default_browser()detects the default browser;list_profiles(kind)feeds the consent screen.UserConsentReceipt(browser, profile, domains, grant/expiry/revoke times) is what the app persists and shows.ConsentRevocationstops a running session at its next action;purge_imported_profiledeletes the copy.ProfileSpec::ImportedFrom(LaunchOptions::imported_profile) does the copy without attaching: cookie database, local storage andLocal Stateonly; neverLogin Data,Web Dataor history.ImportSpec::reimport()copies again.- Actions are confined to the consented domains and refuse password fields: passwords stay in the browser's own password manager.
- Chrome and Edge only. Safari and Firefox return
BrowserError::Unsupported(drive Safari throughrightkit-automation). - Not verified live: whether a copied profile's cookies decrypt (Windows app-bound encryption, macOS keychain key). Per-domain import counts are not available.
Shutdown
shutdown_report() and cancel_report() return a StopReport (process stopped, profile released, with errors); close() is shutdown() that fails on either. shutdown() closes gracefully: CDP Browser.close, then SIGTERM to the process group, then SIGKILL, each step bounded at 5 s. Drop sends SIGTERM, waits up to 5 s, then sends SIGKILL. A temporary profile is removed once Chrome has exited. On macOS and Linux Chrome is also tied to the host process: if the host dies without running Drop (a crash or SIGKILL), Chrome's whole process group receives SIGTERM and then SIGKILL two seconds later (rightkit-child-process kill_on_parent_exit, tied for the life of the process by a dedicated launcher thread); on Windows the job object does the same.
Platform support
Chrome or Edge through chromiumoxide. Platform-specific paths are in the resolution table above. Process-group signalling uses Unix signals, so the shutdown sequence described above applies on Unix hosts.
Tests
tests/e2e.rs: real headless Chrome against a local static page, including Netscape cookie import. Assertions read page state produced by trusted input.tests/policy_e2e.rs: network-policy behaviour.tests/cft_close.rs: Chrome for Testing close behaviour.tests/fixture_session.rs: native confined fixture session (Windows AppContainer / macOS Seatbelt).tests/managed_root_public.rs: publicManagedRootconstruction forinstall.- Cookie export unit tests live in
src/cookie_export.rs&src/cookies.rs(featurecookie-export).
Version and changes
Published version: see INDEX.md. Version history: CHANGELOG.md.