fix(browser): default non-finite DOM text budgets · openclaw/openclaw@c7144a8
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 |
|---|
@@ -885,6 +885,30 @@ describe("cdp internal", () => {
|
885 | 885 | const obj = await getDomText({ wsUrl: server.wsUrl, format: "text" }); |
886 | 886 | expect(obj.text).toBe(""); |
887 | 887 | }); |
| 888 | + |
| 889 | +it("uses the default text budget for non-finite maxChars", async () => { |
| 890 | +const server = await startMockWsServer((msg, socket) => { |
| 891 | +if (msg.method === "Runtime.enable") { |
| 892 | +socket.send(JSON.stringify({ id: msg.id, result: {} })); |
| 893 | +return; |
| 894 | +} |
| 895 | +if (msg.method === "Runtime.evaluate") { |
| 896 | +const expression = |
| 897 | +typeof msg.params?.expression === "string" ? msg.params.expression : ""; |
| 898 | +expect(expression).toContain("const max = 200000;"); |
| 899 | +socket.send(JSON.stringify({ id: msg.id, result: { result: { value: "ok" } } })); |
| 900 | +} |
| 901 | +}); |
| 902 | +wss = server.wss; |
| 903 | + |
| 904 | +const res = await getDomText({ |
| 905 | +wsUrl: server.wsUrl, |
| 906 | +format: "text", |
| 907 | +maxChars: Number.NaN, |
| 908 | +}); |
| 909 | + |
| 910 | +expect(res.text).toBe("ok"); |
| 911 | +}); |
888 | 912 | }); |
889 | 913 | |
890 | 914 | describe("querySelector", () => { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -1049,7 +1049,7 @@ export async function getDomText(opts: {
|
1049 | 1049 | maxChars?: number; |
1050 | 1050 | selector?: string; |
1051 | 1051 | }): Promise<{ text: string }> { |
1052 | | -const maxChars = Math.max(0, Math.min(5_000_000, Math.floor(opts.maxChars ?? 200_000))); |
| 1052 | +const maxChars = resolveIntegerOption(opts.maxChars, 200_000, { min: 0, max: 5_000_000 }); |
1053 | 1053 | const selectorExpr = opts.selector ? JSON.stringify(opts.selector) : "null"; |
1054 | 1054 | const expression = `(() => { |
1055 | 1055 | const fmt = ${JSON.stringify(opts.format)}; |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。