fix(web-probe): 适配持续连接页面截图

This commit is contained in:
pikastech
2026-07-21 10:44:19 +02:00
parent e5d3749079
commit 8e9bca49fc
6 changed files with 23 additions and 2 deletions
+2
View File
@@ -182,12 +182,14 @@ export function hwlabNodeWebProbeScreenshotHelp(): Record<string, unknown> {
"--path": "附加到 semantic origin 的绝对路径;与 --url 互斥。",
"--url": "custom/local 一次性 URL,必须包含完整路径;与 --origin、--path 互斥。",
"--viewport": "截图视口,默认 1440x900。",
"--wait-until": "导航完成条件,默认 domcontentloaded;静态页面可显式选择 networkidle。",
"--selector": "等待指定 selector 后再截图。",
"--full-page|--no-full-page": "选择整页或当前视口截图。",
},
notes: [
"使用 --url 时不要再传 --pathcustom/local URL 已包含完整路径。",
"internal/public/native 运行面必须通过 owning YAML 的 --origin 选择,禁止用手写 URL 或 IP 替代。",
"持续 SSE、WebSocket 或长轮询页面使用默认 domcontentloadednetworkidle 只用于能够稳定进入网络静默的页面。",
"该命令只采集证据,不修改浏览器能力、资源门禁或运行面。",
],
mutation: false,
@@ -2,6 +2,7 @@ import assert from "node:assert/strict";
import { test } from "bun:test";
import { hwlabNodeWebProbeHelp, hwlabNodeWebProbeScreenshotHelp } from "../hwlab-node-help";
import { parseNodeWebProbeOptions } from "./web-probe";
test("web-probe help promotes reusable Workbench debug and product Trace commands", () => {
const help = hwlabNodeWebProbeHelp();
@@ -21,5 +22,18 @@ test("web-probe screenshot scoped help explains semantic, custom and local URL u
assert.match(usage, /--url 'https:\/\/custom\.example\/workbench'/u);
assert.match(usage, /--url 'http:\/\/127\.0\.0\.1:4173\/workbench'/u);
assert.match(notes, /--url.* --path/u);
assert.match(notes, / SSE.*domcontentloaded/u);
assert.equal(help.mutation, false);
});
test("web-probe screenshot defaults to DOM readiness and keeps network idle explicit", () => {
const defaults = parseNodeWebProbeOptions(["screenshot", "--node", "NC01", "--lane", "v03", "--origin", "native"]);
assert.equal(defaults.action, "screenshot");
if (defaults.action !== "screenshot") throw new Error("expected screenshot options");
assert.equal(defaults.waitUntil, "domcontentloaded");
const explicit = parseNodeWebProbeOptions(["screenshot", "--node", "NC01", "--lane", "v03", "--origin", "native", "--wait-until", "networkidle"]);
assert.equal(explicit.action, "screenshot");
if (explicit.action !== "screenshot") throw new Error("expected screenshot options");
assert.equal(explicit.waitUntil, "networkidle");
});
+1 -1
View File
@@ -1105,7 +1105,7 @@ const screenshotPath = process.env.UNIDESK_WEB_PROBE_SCREENSHOT_PATH;
const width = Number(process.env.UNIDESK_WEB_PROBE_SCREENSHOT_WIDTH || 1440);
const height = Number(process.env.UNIDESK_WEB_PROBE_SCREENSHOT_HEIGHT || 900);
const timeout = Number(process.env.UNIDESK_WEB_PROBE_SCREENSHOT_TIMEOUT_MS || 30000);
const waitUntil = process.env.UNIDESK_WEB_PROBE_SCREENSHOT_WAIT_UNTIL || "networkidle";
const waitUntil = process.env.UNIDESK_WEB_PROBE_SCREENSHOT_WAIT_UNTIL || "domcontentloaded";
const fullPage = process.env.UNIDESK_WEB_PROBE_SCREENSHOT_FULL_PAGE === "1";
const selector = process.env.UNIDESK_WEB_PROBE_SCREENSHOT_SELECTOR || "";
const executablePath = process.env.UNIDESK_WEB_PROBE_SCREENSHOT_EXECUTABLE_PATH || "";
+1 -1
View File
@@ -2296,7 +2296,7 @@ export function parseNodeWebProbeOptions(args: string[]): NodeWebProbeOptions {
localDir: optionValue(args, "--local-dir") ?? "/tmp",
name: parseWebProbeScreenshotName(optionValue(args, "--name") ?? `web-probe-${node.toLowerCase()}-${lane}.png`),
timeoutMs,
waitUntil: parseWebProbeScreenshotWaitUntil(optionValue(args, "--wait-until") ?? "networkidle"),
waitUntil: parseWebProbeScreenshotWaitUntil(optionValue(args, "--wait-until") ?? "domcontentloaded"),
fullPage: args.includes("--full-page") && !args.includes("--no-full-page"),
selector: optionValue(args, "--selector") ?? null,
keepRemote: args.includes("--keep-remote"),