Skip to content

The headless browser for AI agents and web scraping

docs: document ES module timeout budgets

lisa0314f318e05c7430
diff --git a/README.md b/README.md
index 724732a0..2540f43f 100644
--- a/README.md
+++ b/README.md
@@ -411,6 +411,14 @@ Obscura caps the page's script-execution phase so one slow or hung page cannot s
OBSCURA_SCRIPT_DEADLINE_MS=60000 obscura serve --port 9222
```
+Modules that enhance an already-rendered page have a separate 3s per-module budget so one non-essential module cannot hold navigation open. Raise it for legitimate long-running modules such as a Vite HMR client:
+
+```bash
+OBSCURA_MODULE_BUDGET_MS=10000 obscura serve --port 9222
+```
+
+An unmounted SPA shell already gives its app modules the full `OBSCURA_SCRIPT_DEADLINE_MS` budget. `OBSCURA_FETCH_TIMEOUT_MS` controls the module's network request, not its evaluation time. See [Environment variables](docs/Environment-variables.md) for the complete timeout model.
+
### `obscura serve`
Start a CDP WebSocket server.
diff --git a/docs/Architecture-overview.md b/docs/Architecture-overview.md
index f0e835c5..5a78cdbf 100644
--- a/docs/Architecture-overview.md
+++ b/docs/Architecture-overview.md
@@ -58,7 +58,7 @@ This is why `Target.createTarget` from many concurrent clients works: each `newP
## Robustness
-One page cannot hang or crash the process. `obscura-js/runtime.rs` provides a V8 termination watchdog (`arm_watchdog`, `run_event_loop_bounded`) that terminates the isolate from a separate thread when synchronous work overruns a budget, because `tokio::time::timeout` cannot preempt synchronous V8. It bounds the post-load settle, the navigation event-loop pumps, and `--eval`. `obscura-js/cdp_watchdog.rs` is a single shared watchdog the dispatcher arms around every CDP command, so a runaway page cannot hold the V8 lock and wedge other sessions (tunable via `OBSCURA_CDP_COMMAND_TIMEOUT_MS`). `op_dom` is wrapped in `catch_unwind` so a DOM-op panic degrades to a null result instead of aborting the process through V8's FFI frame, and `obscura-dom/tree.rs` rejects cyclic reparenting that would make tree walks loop forever. Scripted `fetch()`/XHR and module loads are timeout-bounded (`OBSCURA_FETCH_TIMEOUT_MS`), and the one-shot `fetch` CLI has a process-level hard deadline as a final backstop.
+One page cannot hang or crash the process. `obscura-js/runtime.rs` provides a V8 termination watchdog (`arm_watchdog`, `run_event_loop_bounded`) that terminates the isolate from a separate thread when synchronous work overruns a budget, because `tokio::time::timeout` cannot preempt synchronous V8. It bounds the post-load settle, the navigation event-loop pumps, and `--eval`. The complete script phase is bounded by `OBSCURA_SCRIPT_DEADLINE_MS`; enhancement modules have a shorter per-module graph-loading/evaluation budget controlled by `OBSCURA_MODULE_BUDGET_MS`, while modules mounting an empty SPA shell receive the full script deadline. `obscura-js/cdp_watchdog.rs` is a single shared watchdog the dispatcher arms around every CDP command, so a runaway page cannot hold the V8 lock and wedge other sessions (tunable via `OBSCURA_CDP_COMMAND_TIMEOUT_MS`). `op_dom` is wrapped in `catch_unwind` so a DOM-op panic degrades to a null result instead of aborting the process through V8's FFI frame, and `obscura-dom/tree.rs` rejects cyclic reparenting that would make tree walks loop forever. Scripted `fetch()`/XHR and module network requests are timeout-bounded (`OBSCURA_FETCH_TIMEOUT_MS`), and the one-shot `fetch` CLI has a process-level hard deadline as a final backstop.
## JS bridge
diff --git a/docs/Environment-variables.md b/docs/Environment-variables.md
index af50c5e9..0a5c75f4 100644
--- a/docs/Environment-variables.md
+++ b/docs/Environment-variables.md
@@ -22,6 +22,24 @@ Hard ceiling on a single navigation. Default 30000 (30 seconds). Applies to `Pag
OBSCURA_NAV_TIMEOUT_MS=60000 obscura serve
```
+### `OBSCURA_SCRIPT_DEADLINE_MS`
+
+Soft deadline for the complete page script-execution phase, including classic scripts and ES modules. Default 30000 (30 seconds). Raise it for a heavy SPA whose initial module is responsible for mounting an otherwise empty document. The engine also uses this value as a hard V8 watchdog budget, with a one-second grace period, so a synchronous script cannot run forever.
+
+```bash
+OBSCURA_SCRIPT_DEADLINE_MS=60000 obscura serve
+```
+
+### `OBSCURA_MODULE_BUDGET_MS`
+
+Per-module graph-loading and evaluation budget for modules that enhance an already-rendered page. Default 3000 (3 seconds). Raise it when a module such as the Vite HMR client legitimately needs longer to evaluate:
+
+```bash
+OBSCURA_MODULE_BUDGET_MS=10000 obscura serve
+```
+
+This shorter budget applies when the document body already contains more than 50 descendant nodes, where modules are normally progressive enhancement and should not delay navigation indefinitely. For an unmounted SPA shell, Obscura instead gives each module the full `OBSCURA_SCRIPT_DEADLINE_MS` budget so the app has time to mount. Module network requests remain independently bounded by `OBSCURA_FETCH_TIMEOUT_MS`.
+
### `OBSCURA_CDP_COMMAND_TIMEOUT_MS`
Per-command deadline for the CDP server. A hung page (a runaway `Runtime.evaluate`, a synchronous DOM op) is terminated after this budget so one bad session cannot hold the shared V8 lock and stall the others. Default 60000 (60 seconds); `0` disables it. Navigation self-bounds via `OBSCURA_NAV_TIMEOUT_MS` well under this.
diff --git a/docs/Run-in-production-at-scale.md b/docs/Run-in-production-at-scale.md
index 6eaafdf4..3ed5f3bd 100644
--- a/docs/Run-in-production-at-scale.md
+++ b/docs/Run-in-production-at-scale.md
@@ -148,9 +148,11 @@ Tune the bounds with environment variables (see [Environment variables](Environm
```bash
OBSCURA_NAV_TIMEOUT_MS=60000 \
-OBSCURA_CDP_COMMAND_TIMEOUT_MS=30000 \
+OBSCURA_SCRIPT_DEADLINE_MS=45000 \
+OBSCURA_MODULE_BUDGET_MS=10000 \
+OBSCURA_CDP_COMMAND_TIMEOUT_MS=70000 \
OBSCURA_FETCH_TIMEOUT_MS=20000 \
obscura serve
```
-`OBSCURA_NAV_TIMEOUT_MS` is the per-navigation ceiling (default 30000). `OBSCURA_CDP_COMMAND_TIMEOUT_MS` is the per-CDP-command V8 deadline (default 60000, `0` disables). `OBSCURA_FETCH_TIMEOUT_MS` bounds scripted fetch/XHR and module loads (default 30000).
+`OBSCURA_NAV_TIMEOUT_MS` is the per-navigation ceiling (default 30000). `OBSCURA_SCRIPT_DEADLINE_MS` bounds the complete script phase (default 30000), while `OBSCURA_MODULE_BUDGET_MS` bounds each enhancement module's graph loading and evaluation (default 3000; unmounted SPA shells use the full script deadline). `OBSCURA_CDP_COMMAND_TIMEOUT_MS` is the outer per-CDP-command V8 deadline (default 60000, `0` disables), so keep it above the navigation ceiling. `OBSCURA_FETCH_TIMEOUT_MS` bounds scripted fetch/XHR and module network requests (default 30000).