fix(browser): default non-finite keypress delays · openclaw/openclaw@4638f58
steipete
·
2026-05-29
·
via Recent Commits to openclaw:main
File tree
extensions/browser/src/browser
| Original file line number | Diff line number | Diff line change |
|---|
@@ -972,6 +972,35 @@ describe("pw-tools-core interaction navigation guard", () => {
|
972 | 972 | } |
973 | 973 | }); |
974 | 974 | |
| 975 | +it("defaults non-finite keypress delays before calling Playwright", async () => { |
| 976 | +vi.useFakeTimers(); |
| 977 | +try { |
| 978 | +const press = vi.fn(async () => {}); |
| 979 | +const page = { |
| 980 | +keyboard: { press }, |
| 981 | +on: vi.fn(), |
| 982 | +off: vi.fn(), |
| 983 | +url: vi.fn(() => "http://127.0.0.1:9222/json/version"), |
| 984 | +}; |
| 985 | +setPwToolsCoreCurrentPage(page); |
| 986 | + |
| 987 | +const task = mod.pressKeyViaPlaywright({ |
| 988 | +cdpUrl: "http://127.0.0.1:18792", |
| 989 | +targetId: "T1", |
| 990 | +key: "Enter", |
| 991 | +delayMs: Number.NaN, |
| 992 | +ssrfPolicy: { allowPrivateNetwork: false }, |
| 993 | +}); |
| 994 | + |
| 995 | +await vi.advanceTimersByTimeAsync(250); |
| 996 | +await task; |
| 997 | + |
| 998 | +expect(press).toHaveBeenCalledWith("Enter", { delay: 0 }); |
| 999 | +} finally { |
| 1000 | +vi.useRealTimers(); |
| 1001 | +} |
| 1002 | +}); |
| 1003 | + |
975 | 1004 | it("propagates blocked delayed submit navigation instead of reporting type success", async () => { |
976 | 1005 | vi.useFakeTimers(); |
977 | 1006 | try { |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +import { resolveNonNegativeIntegerOption } from "openclaw/plugin-sdk/number-runtime"; |
1 | 2 | import { normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime"; |
2 | 3 | import type { Frame, Page } from "playwright-core"; |
3 | 4 | import { formatErrorMessage } from "../infra/errors.js"; |
@@ -792,7 +793,7 @@ export async function pressKeyViaPlaywright(opts: {
|
792 | 793 | action: async () => { |
793 | 794 | await awaitActionWithAbort( |
794 | 795 | page.keyboard.press(key, { |
795 | | -delay: Math.max(0, Math.floor(opts.delayMs ?? 0)), |
| 796 | +delay: resolveNonNegativeIntegerOption(opts.delayMs, 0), |
796 | 797 | }), |
797 | 798 | abortPromise, |
798 | 799 | reconcileRemoteDialog, |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。