Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust
Rust ai-agentsai-toolsbrowserbrowser-automationcloud-browserheadlessheadless-browserkitesurfplaywrightpuppeteerrustservoweb-crawlerweb-crawlingweb-scraperweb-scraping
feat: support layout and resource env flags
ldm0458fa83e7384
diff --git a/README.md b/README.mdindex a2632d1ea..457060898 100644--- a/README.md+++ b/README.md@@ -200,6 +200,11 @@ Moli keeps expensive browser work explicit rather than silently enabling it:| `--image`, `--font`, `--audio`, `--video`, `--media`, `--text-track` | Enable one specific optional resource family || `--profile-dir`, `--http-cache-dir`, `--cookie-file` | Opt into whatever persistence the workload needs |+`MOLI_LAYOUT=true` and `MOLI_RESOURCE=true` provide environment-variable+fallbacks for `--layout` and `--resource`. Explicit command-line flags take+priority over their environment-variable values. The environment values must+be `true` or `false`.+Layout is sampled, not continuously retained: a cold geometry request buildsone full pass from the current DOM/style and keeps only the latest`LayoutPassOutput`. Ordinary geometry reads may reuse that snapshot afterdiff --git a/moli/Cargo.toml b/moli/Cargo.tomlindex 8051ba8ad..10594dcc1 100644--- a/moli/Cargo.toml+++ b/moli/Cargo.toml@@ -17,7 +17,7 @@ anyhow = "1.0.100"axum = { version = "0.8.6", features = ["ws"] }base64 = "0.22"cidr = "0.3.2"-clap = { version = "4.5.39", features = ["derive"] }+clap = { version = "4.5.39", features = ["derive", "env"] }flate2 = "1.1.9"futures-util = "0.3.31"moli-browser-profile = { path = "../moli-browser-profile" }diff --git a/moli/src/cli.rs b/moli/src/cli.rsindex c587a2e66..6ef9696e0 100644--- a/moli/src/cli.rs+++ b/moli/src/cli.rs@@ -315,7 +315,7 @@ pub struct CommonArgs {/// Fetch every optional image, font, audio, video, media, and text-track/// resource family.- #[arg(long)]+ #[arg(long, env = "MOLI_RESOURCE")]pub resource: bool,#[arg(long)]@@ -325,7 +325,7 @@ pub struct CommonArgs {////// Without this flag Moli keeps deterministic compatibility/// geometry and does not construct layout or paint output.- #[arg(long)]+ #[arg(long, env = "MOLI_LAYOUT")]pub layout: bool,#[arg(long = "cookie-file")]diff --git a/moli/tests/cli.rs b/moli/tests/cli.rsindex a5b857db5..808345a82 100644--- a/moli/tests/cli.rs+++ b/moli/tests/cli.rs@@ -1,5 +1,5 @@use clap::Parser;-use std::num::NonZeroU32;+use std::{num::NonZeroU32, process::Command};use moli::cli::{Cli, Commands, CommonArgs, DumpFormat, FetchArgs, FetchWaitUntil, LogFormat, LogLevel, McpArgs,@@ -985,6 +985,51 @@ fn layout_selects_on_demand_policy_for_fetch_and_serve() {}}+#[test]+fn env_flags_are_fallbacks_and_cli_flags_take_priority() {+ for (case, layout, resource) in [+ ("env-enables", "true", "true"),+ ("env-disables", "false", "false"),+ ("cli-overrides-env", "false", "false"),+ ] {+ let output = Command::new(std::env::current_exe().unwrap())+ .args(["--exact", "parse_env_flags_in_child_process", "--nocapture"])+ .env("MOLI_TEST_ENV_FLAG_CASE", case)+ .env("MOLI_LAYOUT", layout)+ .env("MOLI_RESOURCE", resource)+ .output()+ .unwrap();++ assert!(+ output.status.success(),+ "environment flag case {case:?} failed\nstdout:\n{}\nstderr:\n{}",+ String::from_utf8_lossy(&output.stdout),+ String::from_utf8_lossy(&output.stderr),+ );+ }+}++#[test]+fn parse_env_flags_in_child_process() {+ let Ok(case) = std::env::var("MOLI_TEST_ENV_FLAG_CASE") else {+ return;+ };++ let args = if case == "cli-overrides-env" {+ vec!["moli", "serve", "--layout", "--resource"]+ } else {+ vec!["moli", "serve"]+ };+ let cli = Cli::try_parse_from(normalize_args_for_compat(args)).unwrap();+ let Commands::Serve(args) = cli.command else {+ panic!("expected serve command");+ };+ let expected = case != "env-disables";++ assert_eq!(args.common.layout, expected);+ assert_eq!(args.common.resource, expected);+}+#[test]fn removed_long_form_flags_are_rejected() {for flag in [