fix(browser): reject invalid wait load states · openclaw/openclaw@13c6a33
steipete
·
2026-05-26
·
via Recent Commits to openclaw:main
File tree
extensions/browser/src/cli/browser-cli-actions-input
| Original file line number | Diff line number | Diff line change |
|---|
@@ -64,6 +64,18 @@ describe("browser action input wait command", () => {
|
64 | 64 | | undefined; |
65 | 65 | expect(options?.timeoutMs).toBeGreaterThan(21000); |
66 | 66 | }); |
| 67 | + |
| 68 | +it("rejects unsupported load states before sending the wait request", async () => { |
| 69 | +const program = createActionInputProgram(); |
| 70 | + |
| 71 | +await expect( |
| 72 | +program.parseAsync(["browser", "wait", "--load", "complete"], { from: "user" }), |
| 73 | +).rejects.toThrow("__exit__:1"); |
| 74 | + |
| 75 | +const capture = getBrowserCliRuntimeCapture(); |
| 76 | +expect(capture.runtimeErrors.join("\n")).toContain("Invalid --load value: complete"); |
| 77 | +expect(mocks.callBrowserRequest).not.toHaveBeenCalled(); |
| 78 | +}); |
67 | 79 | }); |
68 | 80 | |
69 | 81 | describe("browser action input evaluate command", () => { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -10,6 +10,21 @@ import {
|
10 | 10 | } from "./shared.js"; |
11 | 11 | |
12 | 12 | const DEFAULT_WAIT_CONDITION_TIMEOUT_MS = 20000; |
| 13 | +type BrowserWaitLoadState = "load" | "domcontentloaded" | "networkidle"; |
| 14 | + |
| 15 | +function parseBrowserWaitLoadState(value: unknown): BrowserWaitLoadState | undefined { |
| 16 | +const load = normalizeOptionalString(value); |
| 17 | +switch (load) { |
| 18 | +case undefined: |
| 19 | +return undefined; |
| 20 | +case "load": |
| 21 | +case "domcontentloaded": |
| 22 | +case "networkidle": |
| 23 | +return load; |
| 24 | +default: |
| 25 | +throw new Error(`Invalid --load value: ${load}`); |
| 26 | +} |
| 27 | +} |
13 | 28 | |
14 | 29 | export function registerBrowserFormWaitEvalCommands( |
15 | 30 | browser: Command, |
@@ -64,10 +79,7 @@ export function registerBrowserFormWaitEvalCommands(
|
64 | 79 | const { parent, profile } = resolveBrowserActionContext(cmd, parentOpts); |
65 | 80 | try { |
66 | 81 | const sel = normalizeOptionalString(selector); |
67 | | -const load = |
68 | | -opts.load === "load" || opts.load === "domcontentloaded" || opts.load === "networkidle" |
69 | | - ? (opts.load as "load" | "domcontentloaded" | "networkidle") |
70 | | - : undefined; |
| 82 | +const load = parseBrowserWaitLoadState(opts.load); |
71 | 83 | const timeoutMs = Number.isFinite(opts.timeoutMs) ? opts.timeoutMs : undefined; |
72 | 84 | const timeMs = Number.isFinite(opts.time) ? opts.time : undefined; |
73 | 85 | const text = normalizeOptionalString(opts.text); |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。