wb-browser-runtime 0.11.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +101 -2
- package/bin/wb-browser-runtime.js +55 -2
- package/lib/download-capture.js +180 -0
- package/lib/failure.js +99 -0
- package/lib/providers/browser-use.js +9 -2
- package/lib/providers/browserbase.js +12 -2
- package/lib/providers/index.js +6 -2
- package/lib/providers/local.js +120 -0
- package/lib/stub-page.js +16 -0
- package/lib/util.js +58 -0
- package/package.json +1 -1
- package/verbs/click.js +24 -2
- package/verbs/download.js +410 -0
- package/verbs/index.js +4 -0
- package/verbs/wait_for_network_idle.js +51 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// Wait until the page reports "networkidle" — at most one in-flight request
|
|
2
|
+
// for >=500ms. SPA flows that don't have a stable selector to wait on need
|
|
3
|
+
// this; otherwise the next verb fires before async XHRs settle and reads
|
|
4
|
+
// stale DOM.
|
|
5
|
+
|
|
6
|
+
const DEFAULT_TIMEOUT_MS = 30_000;
|
|
7
|
+
|
|
8
|
+
// Parse "30s" / "2m" / "500ms" / 5000 / "5000" into ms. Anything malformed
|
|
9
|
+
// falls back to the default — the sidecar would rather time out at a known
|
|
10
|
+
// bound than throw on a typo.
|
|
11
|
+
function parseTimeoutMs(value) {
|
|
12
|
+
if (value == null) return DEFAULT_TIMEOUT_MS;
|
|
13
|
+
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
14
|
+
if (typeof value !== "string") return DEFAULT_TIMEOUT_MS;
|
|
15
|
+
const trimmed = value.trim();
|
|
16
|
+
if (trimmed === "") return DEFAULT_TIMEOUT_MS;
|
|
17
|
+
const m = trimmed.match(/^(\d+(?:\.\d+)?)\s*(ms|s|m|h)?$/i);
|
|
18
|
+
if (!m) {
|
|
19
|
+
const asNum = Number(trimmed);
|
|
20
|
+
return Number.isFinite(asNum) ? asNum : DEFAULT_TIMEOUT_MS;
|
|
21
|
+
}
|
|
22
|
+
const n = Number(m[1]);
|
|
23
|
+
const unit = (m[2] || "ms").toLowerCase();
|
|
24
|
+
switch (unit) {
|
|
25
|
+
case "ms":
|
|
26
|
+
return n;
|
|
27
|
+
case "s":
|
|
28
|
+
return n * 1000;
|
|
29
|
+
case "m":
|
|
30
|
+
return n * 60_000;
|
|
31
|
+
case "h":
|
|
32
|
+
return n * 3_600_000;
|
|
33
|
+
default:
|
|
34
|
+
return DEFAULT_TIMEOUT_MS;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export default {
|
|
39
|
+
name: "wait_for_network_idle",
|
|
40
|
+
primaryKey: "timeout",
|
|
41
|
+
async execute(page, args) {
|
|
42
|
+
const raw = args.timeout;
|
|
43
|
+
const timeout = parseTimeoutMs(raw);
|
|
44
|
+
await page.waitForLoadState("networkidle", { timeout });
|
|
45
|
+
const summary =
|
|
46
|
+
typeof raw === "string" && raw.trim() !== ""
|
|
47
|
+
? `network idle (timeout=${raw.trim()})`
|
|
48
|
+
: `network idle (timeout=${timeout}ms)`;
|
|
49
|
+
return summary;
|
|
50
|
+
},
|
|
51
|
+
};
|