Skip to content

Process Management

github-actions[bot] edited this page Nov 21, 2026 · 5 revisions

Process management

Role. Start each browser in a known, isolated state, and never leave one behind: not a process, not a profile, not a cache. Module process, package internal/process.

Inputs and outputs

  • In: a discovered browser (executable, family), a root for temp dirs, and per family a few options (font parity, viewport, a template profile).
  • Out: a running browser the drivers can talk to (Blink, Gecko, WebKit for WebKitGTK, WPE and Safari), each with a Close that kills the whole tree and deletes its temp dir.

How it works

One launch

Every browser starts through spawn:

  1. A fresh temp dir <root>/omnisnap-<pid>-<n>/ with an owner.lock naming omnisnap's pid, and a group.lock naming the browser's pid, which is its process group id (profile.go). The profile lives inside it; never the user's profile (Chrome 136 and later also refuse remote debugging on the default data dir).
  2. The browser leads its own process group on Unix (pgroup_unix.go), so renderers, the zygote and utility processes can be signalled at once. On Windows it goes into a Job Object with JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE (job_windows.go).
  3. The last 16 KB of its output are kept for error messages.

Handle.Close kills the tree (the group, or the job), waits for the exit, and only then removes the temp dir.

Per family

Family Launch
Blink --headless=new --hide-scrollbars --no-first-run --no-default-browser-check --force-device-scale-factor=1 --disk-cache-size=1 --media-cache-size=1 --remote-debugging-port=0 --user-data-dir=<temp> (blink.go). OMNISNAP_NO_SANDBOX=1 adds --no-sandbox --disable-dev-shm-usage for restricted hosts (CI containers, Ubuntu 24.04+ AppArmor); the product never sets it itself.
Gecko headless, --remote-debugging-port=0, a profile whose user.js sets overlay scrollbars, devPixelsPerPx 1.0, no disk cache, and the font-parity font.name.<generic>.<lang> prefs (prefs.go). Snap Firefox gets its profile under ~/snap/firefox/common/, because its /tmp is private.
WebKitGTK (Linux) WebKitWebDriver on a free port; MiniBrowser with font-family arguments, on a private Weston headless display started for it (webkit.go). No GPU and no desktop session: GSK_RENDERER=cairo, WEBKIT_DISABLE_DMABUF_RENDERER=1, GDK_DEBUG=no-portals. Without Weston, or with WEBKIT_HEADLESS=0, the windows are visible.
WPE (Linux) WPEWebDriver; MiniBrowser --headless --size=<viewport> and a config file carrying the font families (wpe.go). No compositor; the viewport is exact.
Safari (macOS) safaridriver on a free port (safari_darwin.go); a visible window by design.

Branded browsers start from a copy of a warmed template profile (template.go, Branded browsers). Only the branded checks start Blink with a window (StartBlinkVisible); the product always runs it headless.

Three cleanup layers

  1. Normal exit. The CLI closes every engine with defer (run.go): sessions, the process tree, the temp dir.
  2. Abnormal exit. SIGINT, SIGTERM and SIGHUP cancel the job's context (root.go, signals_unix.go), and the same defer runs. On Windows, if omnisnap is killed outright, the kernel closes the Job Object handle and kills every browser in it.
  3. The next start. Before any command other than version and help, the sweeper removes omnisnap-* temp dirs whose owner.lock names a process that is gone, and kills the process group in their group.lock (sweep.go, root.go). This is what recovers from SIGKILL and power loss. Foreign directories, and the current process's own, are never touched.

No disk caches are kept: a crawl would otherwise write hundreds of MB per session, and on WSL the virtual disk never gives the space back.

Failure handling

A browser that does not come up (no DevTools endpoint, a driver that does not answer GET /status) returns an error with its output tail; the CLI skips that engine with the reason. A crashed browser during a job is replaced once by the CLI's restartable wrapper (CLI and orchestration, Capture pipeline).

Tests

Where the code differs from the spec

  • No cap on live browsers. The spec asks for "a configurable cap on concurrently live browsers (default 3)". There is none in the code; the number is bounded only by one browser per engine per job.
  • Weston per WebKitGTK launch, not per process. The spec has one private Weston per omnisnap process, started lazily. StartWebKit starts a display for each WebKitGTK launch and stops it on Close. In a job that is one display, since there is one browser per engine; a relaunched WebKitGTK gets a new one.

Spec

specs/SPEC-process.md.

Source files

Clone this wiki locally