惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

U
Unit 42
Vercel News
Vercel News
博客园 - 叶小钗
大猫的无限游戏
大猫的无限游戏
MyScale Blog
MyScale Blog
P
Proofpoint News Feed
量子位
Engineering at Meta
Engineering at Meta
B
Blog RSS Feed
博客园 - 【当耐特】
Recent Announcements
Recent Announcements
Google DeepMind News
Google DeepMind News
D
DataBreaches.Net
Stack Overflow Blog
Stack Overflow Blog
博客园 - 聂微东
小众软件
小众软件
Hugging Face - Blog
Hugging Face - Blog
人人都是产品经理
人人都是产品经理
IT之家
IT之家
T
The Blog of Author Tim Ferriss
Last Week in AI
Last Week in AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Jina AI
Jina AI
博客园 - 三生石上(FineUI控件)

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
refactor(browser): remove unused CDP DOM helpers · opencl...
vincentkoc · 2026-06-19 · via Recent Commits to openclaw:main

@@ -6,18 +6,12 @@ import "../test-support/browser-security.mock.js";

66

import {

77

type AriaSnapshotNode,

88

captureScreenshot,

9-

captureScreenshotPng,

109

createTargetViaCdp,

11-

type DomSnapshotNode,

1210

evaluateJavaScript,

1311

formatAriaSnapshot,

14-

getDomText,

1512

normalizeCdpWsUrl,

16-

type QueryMatch,

17-

querySelector,

1813

type RawAXNode,

1914

snapshotAria,

20-

snapshotDom,

2115

snapshotRoleViaCdp,

2216

} from "./cdp.js";

2317

@@ -164,27 +158,6 @@ describe("cdp internal", () => {

164158

expect(buf.toString("utf8")).toBe("PNGDATA");

165159

});

166160167-

it("captureScreenshotPng forwards to the png captureScreenshot flow", async () => {

168-

const server = await startMockWsServer((msg, socket) => {

169-

if (msg.method === "Page.enable") {

170-

socket.send(JSON.stringify({ id: msg.id, result: {} }));

171-

return;

172-

}

173-

if (msg.method === "Page.captureScreenshot") {

174-

expect(msg.params?.format).toBe("png");

175-

socket.send(

176-

JSON.stringify({

177-

id: msg.id,

178-

result: { data: Buffer.from("WRAPPED").toString("base64") },

179-

}),

180-

);

181-

}

182-

});

183-

wss = server.wss;

184-

const buf = await captureScreenshotPng({ wsUrl: server.wsUrl });

185-

expect(buf.toString("utf8")).toBe("WRAPPED");

186-

});

187-188161

it("clamps out-of-range JPEG quality values into [0, 100]", async () => {

189162

const { observed } = await captureScreenshotAndObserveParams({

190163

format: "jpeg",

@@ -730,257 +703,6 @@ describe("cdp internal", () => {

730703

});

731704

});

732705733-

describe("snapshotDom", () => {

734-

it("returns the nodes array from the evaluated expression", async () => {

735-

const server = await startMockWsServer((msg, socket) => {

736-

if (msg.method === "Runtime.enable") {

737-

socket.send(JSON.stringify({ id: msg.id, result: {} }));

738-

return;

739-

}

740-

if (msg.method === "Runtime.evaluate") {

741-

const fake: DomSnapshotNode[] = [{ ref: "n1", parentRef: null, depth: 0, tag: "html" }];

742-

socket.send(

743-

JSON.stringify({

744-

id: msg.id,

745-

result: { result: { value: { nodes: fake } } },

746-

}),

747-

);

748-

}

749-

});

750-

wss = server.wss;

751-

const snap = await snapshotDom({ wsUrl: server.wsUrl, limit: 10, maxTextChars: 200 });

752-

expect(snap.nodes[0]?.tag).toBe("html");

753-

});

754-755-

it("returns an empty nodes array when the value is not an object", async () => {

756-

const server = await startMockWsServer((msg, socket) => {

757-

if (msg.method === "Runtime.enable") {

758-

socket.send(JSON.stringify({ id: msg.id, result: {} }));

759-

return;

760-

}

761-

if (msg.method === "Runtime.evaluate") {

762-

socket.send(

763-

JSON.stringify({

764-

id: msg.id,

765-

result: { result: { value: null } },

766-

}),

767-

);

768-

}

769-

});

770-

wss = server.wss;

771-

const snap = await snapshotDom({ wsUrl: server.wsUrl });

772-

expect(snap.nodes).toStrictEqual([]);

773-

});

774-775-

it("returns an empty nodes array when nodes is not an array", async () => {

776-

const server = await startMockWsServer((msg, socket) => {

777-

if (msg.method === "Runtime.enable") {

778-

socket.send(JSON.stringify({ id: msg.id, result: {} }));

779-

return;

780-

}

781-

if (msg.method === "Runtime.evaluate") {

782-

socket.send(

783-

JSON.stringify({

784-

id: msg.id,

785-

result: { result: { value: { nodes: "not-an-array" } } },

786-

}),

787-

);

788-

}

789-

});

790-

wss = server.wss;

791-

const snap = await snapshotDom({ wsUrl: server.wsUrl });

792-

expect(snap.nodes).toStrictEqual([]);

793-

});

794-795-

it("uses default DOM snapshot budgets for non-finite options", async () => {

796-

const server = await startMockWsServer((msg, socket) => {

797-

if (msg.method === "Runtime.enable") {

798-

socket.send(JSON.stringify({ id: msg.id, result: {} }));

799-

return;

800-

}

801-

if (msg.method === "Runtime.evaluate") {

802-

const expression =

803-

typeof msg.params?.expression === "string" ? msg.params.expression : "";

804-

expect(expression).toContain("const maxNodes = 800;");

805-

expect(expression).toContain("const maxText = 220;");

806-

socket.send(JSON.stringify({ id: msg.id, result: { result: { value: { nodes: [] } } } }));

807-

}

808-

});

809-

wss = server.wss;

810-811-

const snap = await snapshotDom({

812-

wsUrl: server.wsUrl,

813-

limit: Number.NaN,

814-

maxTextChars: Number.NaN,

815-

});

816-817-

expect(snap.nodes).toStrictEqual([]);

818-

});

819-

});

820-821-

describe("getDomText", () => {

822-

it("returns the evaluated string for text format", async () => {

823-

const server = await startMockWsServer((msg, socket) => {

824-

if (msg.method === "Runtime.enable") {

825-

socket.send(JSON.stringify({ id: msg.id, result: {} }));

826-

return;

827-

}

828-

if (msg.method === "Runtime.evaluate") {

829-

socket.send(

830-

JSON.stringify({

831-

id: msg.id,

832-

result: { result: { value: "plain body text" } },

833-

}),

834-

);

835-

}

836-

});

837-

wss = server.wss;

838-

const res = await getDomText({ wsUrl: server.wsUrl, format: "text", maxChars: 100 });

839-

expect(res.text).toBe("plain body text");

840-

});

841-842-

it("returns the html outerHTML for html format with a selector", async () => {

843-

const server = await startMockWsServer((msg, socket) => {

844-

if (msg.method === "Runtime.enable") {

845-

socket.send(JSON.stringify({ id: msg.id, result: {} }));

846-

return;

847-

}

848-

if (msg.method === "Runtime.evaluate") {

849-

socket.send(

850-

JSON.stringify({

851-

id: msg.id,

852-

result: { result: { value: "<div>html</div>" } },

853-

}),

854-

);

855-

}

856-

});

857-

wss = server.wss;

858-

const res = await getDomText({

859-

wsUrl: server.wsUrl,

860-

format: "html",

861-

selector: "#foo",

862-

});

863-

expect(res.text).toBe("<div>html</div>");

864-

});

865-866-

it("coerces numeric/boolean values to strings and falls back to empty for objects", async () => {

867-

const responses: unknown[] = [42, true, { shape: "object" }];

868-

let i = 0;

869-

const server = await startMockWsServer((msg, socket) => {

870-

if (msg.method === "Runtime.enable") {

871-

socket.send(JSON.stringify({ id: msg.id, result: {} }));

872-

return;

873-

}

874-

if (msg.method === "Runtime.evaluate") {

875-

socket.send(

876-

JSON.stringify({

877-

id: msg.id,

878-

result: { result: { value: responses[i++] } },

879-

}),

880-

);

881-

}

882-

});

883-

wss = server.wss;

884-

const num = await getDomText({ wsUrl: server.wsUrl, format: "text" });

885-

expect(num.text).toBe("42");

886-

const bool = await getDomText({ wsUrl: server.wsUrl, format: "text" });

887-

expect(bool.text).toBe("true");

888-

const obj = await getDomText({ wsUrl: server.wsUrl, format: "text" });

889-

expect(obj.text).toBe("");

890-

});

891-892-

it("uses the default text budget for non-finite maxChars", async () => {

893-

const server = await startMockWsServer((msg, socket) => {

894-

if (msg.method === "Runtime.enable") {

895-

socket.send(JSON.stringify({ id: msg.id, result: {} }));

896-

return;

897-

}

898-

if (msg.method === "Runtime.evaluate") {

899-

const expression =

900-

typeof msg.params?.expression === "string" ? msg.params.expression : "";

901-

expect(expression).toContain("const max = 200000;");

902-

socket.send(JSON.stringify({ id: msg.id, result: { result: { value: "ok" } } }));

903-

}

904-

});

905-

wss = server.wss;

906-907-

const res = await getDomText({

908-

wsUrl: server.wsUrl,

909-

format: "text",

910-

maxChars: Number.NaN,

911-

});

912-913-

expect(res.text).toBe("ok");

914-

});

915-

});

916-917-

describe("querySelector", () => {

918-

it("returns the matches array from the evaluated expression", async () => {

919-

const server = await startMockWsServer((msg, socket) => {

920-

if (msg.method === "Runtime.enable") {

921-

socket.send(JSON.stringify({ id: msg.id, result: {} }));

922-

return;

923-

}

924-

if (msg.method === "Runtime.evaluate") {

925-

const matches: QueryMatch[] = [{ index: 1, tag: "button", text: "OK" }];

926-

socket.send(JSON.stringify({ id: msg.id, result: { result: { value: matches } } }));

927-

}

928-

});

929-

wss = server.wss;

930-

const out = await querySelector({

931-

wsUrl: server.wsUrl,

932-

selector: "button",

933-

limit: 5,

934-

maxTextChars: 100,

935-

maxHtmlChars: 500,

936-

});

937-

expect(out.matches[0]?.tag).toBe("button");

938-

});

939-940-

it("returns an empty array when the value is not an array", async () => {

941-

const server = await startMockWsServer((msg, socket) => {

942-

if (msg.method === "Runtime.enable") {

943-

socket.send(JSON.stringify({ id: msg.id, result: {} }));

944-

return;

945-

}

946-

if (msg.method === "Runtime.evaluate") {

947-

socket.send(JSON.stringify({ id: msg.id, result: { result: { value: "not-array" } } }));

948-

}

949-

});

950-

wss = server.wss;

951-

const out = await querySelector({ wsUrl: server.wsUrl, selector: "button" });

952-

expect(out.matches).toStrictEqual([]);

953-

});

954-955-

it("uses default query budgets for non-finite options", async () => {

956-

const server = await startMockWsServer((msg, socket) => {

957-

if (msg.method === "Runtime.enable") {

958-

socket.send(JSON.stringify({ id: msg.id, result: {} }));

959-

return;

960-

}

961-

if (msg.method === "Runtime.evaluate") {

962-

const expression =

963-

typeof msg.params?.expression === "string" ? msg.params.expression : "";

964-

expect(expression).toContain("const lim = 20;");

965-

expect(expression).toContain("const maxText = 500;");

966-

expect(expression).toContain("const maxHtml = 1500;");

967-

socket.send(JSON.stringify({ id: msg.id, result: { result: { value: [] } } }));

968-

}

969-

});

970-

wss = server.wss;

971-972-

const out = await querySelector({

973-

wsUrl: server.wsUrl,

974-

selector: "button",

975-

limit: Number.NaN,

976-

maxTextChars: Number.NaN,

977-

maxHtmlChars: Number.NaN,

978-

});

979-980-

expect(out.matches).toStrictEqual([]);

981-

});

982-

});

983-984706

describe("normalizeCdpWsUrl fill-in", () => {

985707

it("respects an already-non-loopback ws hostname (no-rewrite branch)", () => {

986708

// Covers the else side of the loopback/wildcard-guard in normalizeCdpWsUrl.

@@ -1287,21 +1009,4 @@ describe("cdp internal", () => {

12871009

});

12881010

});

128910111290-

describe("getDomText branch coverage", () => {

1291-

it("coerces a missing evaluated value to an empty string", async () => {

1292-

// Covers the right-hand side of `evaluated.result?.value ?? ""`.

1293-

const server = await startMockWsServer((msg, socket) => {

1294-

if (msg.method === "Runtime.enable") {

1295-

socket.send(JSON.stringify({ id: msg.id, result: {} }));

1296-

return;

1297-

}

1298-

if (msg.method === "Runtime.evaluate") {

1299-

socket.send(JSON.stringify({ id: msg.id, result: { result: {} } }));

1300-

}

1301-

});

1302-

wss = server.wss;

1303-

const res = await getDomText({ wsUrl: server.wsUrl, format: "text" });

1304-

expect(res.text).toBe("");

1305-

});

1306-

});

13071012

});