cdp-toolkit 3.1.0 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/README.md +69 -16
- package/dist/bidi/mux-daemon.js +560 -137
- package/dist/cli.js +1236 -493
- package/dist/index.js +708 -79
- package/dist/mcp.js +1229 -486
- package/package.json +3 -1
- package/src/bidi/driver.ts +346 -54
- package/src/bidi/protocol.ts +27 -9
- package/src/bidi/snapshot.ts +123 -113
- package/src/bidi-browser-tools.ts +366 -0
- package/src/bidi-tools.ts +29 -2
- package/src/cdp/driver.ts +36 -33
- package/src/cdp/endpoint.ts +200 -0
- package/src/cdp/session.ts +246 -0
- package/src/client.ts +118 -10
- package/src/driver.ts +22 -5
- package/src/firefox-tools.ts +6 -3
- package/src/manifest.ts +2 -2
- package/src/policy.ts +2 -2
- package/src/shared-tools.ts +96 -24
- package/src/toolDocs.ts +7 -7
- package/src/tools/dispatch-mouse.ts +6 -1
- package/src/tools/downloads.ts +5 -6
- package/src/tools/evaluate.ts +3 -3
- package/src/tools/navigation.ts +3 -3
- package/src/tools/network_mock.ts +2 -2
- package/src/tools/performance.ts +5 -5
- package/src/tools/permissions.ts +5 -5
- package/src/tools/recorder.ts +3 -3
- package/src/tools/screencast.ts +46 -6
- package/src/tools/snapshot.ts +2 -2
- package/src/version.ts +1 -1
package/src/tools/screencast.ts
CHANGED
|
@@ -54,7 +54,7 @@ import { spawn } from "node:child_process";
|
|
|
54
54
|
import { mkdir, rm, stat, writeFile } from "node:fs/promises";
|
|
55
55
|
import { join } from "node:path";
|
|
56
56
|
import { CdpError, openPage } from "../client.ts";
|
|
57
|
-
import type {
|
|
57
|
+
import type { PageConnection } from "../client.ts";
|
|
58
58
|
import type { Target, TargetSelector } from "../types.ts";
|
|
59
59
|
|
|
60
60
|
const ARTIFACT_DIR = process.env.CDP_ARTIFACT_DIR ?? "/tmp/cdp-toolkit";
|
|
@@ -235,6 +235,8 @@ export interface EncoderChoice {
|
|
|
235
235
|
codec: "hevc" | "h264";
|
|
236
236
|
/** -tag:v value, set on HEVC so QuickTime will play the result. */
|
|
237
237
|
tag?: "hvc1";
|
|
238
|
+
/** Use `-fps_mode vfr` (ffmpeg >=5.1) instead of `-vsync vfr`; set by the probe. */
|
|
239
|
+
fpsMode?: boolean;
|
|
238
240
|
}
|
|
239
241
|
|
|
240
242
|
/** Preference order: hardware HEVC, hardware H.264, software HEVC, software H.264. */
|
|
@@ -278,8 +280,38 @@ export function selectEncoder(encodersOutput: string): EncoderChoice {
|
|
|
278
280
|
}
|
|
279
281
|
|
|
280
282
|
/**
|
|
281
|
-
*
|
|
282
|
-
*
|
|
283
|
+
* Whether this ffmpeg takes `-fps_mode` (added in 5.1). `-vsync` was deprecated
|
|
284
|
+
* then and later removed, so a new ffmpeg fails with "Unrecognized option 'vsync'",
|
|
285
|
+
* while 4.4 (Ubuntu 22.04) only knows `-vsync`. Parses `ffmpeg -version`;
|
|
286
|
+
* a git snapshot ("ffmpeg version N-1234-g...") is treated as new. Returns
|
|
287
|
+
* `undefined` when the banner has no version it can read, so the caller can
|
|
288
|
+
* look further instead of guessing.
|
|
289
|
+
*/
|
|
290
|
+
export function supportsFpsMode(versionOutput: string): boolean | undefined {
|
|
291
|
+
const m = /ffmpeg version n?(\d+)\.(\d+)/.exec(versionOutput);
|
|
292
|
+
if (!m) return /ffmpeg version N-/.test(versionOutput) ? true : undefined;
|
|
293
|
+
const major = Number(m[1]);
|
|
294
|
+
const minor = Number(m[2]);
|
|
295
|
+
return major > 5 || (major === 5 && minor >= 1);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Pick `-fps_mode` vs `-vsync` from what the probe could read. The version
|
|
300
|
+
* banner decides when it parses; otherwise the option list from `-h full`
|
|
301
|
+
* decides (it names `-fps_mode` only on ffmpeg that has it). When neither could
|
|
302
|
+
* be read, choose `-fps_mode`: it is the current option, while `-vsync` is gone
|
|
303
|
+
* from new ffmpeg, so an unreadable probe must not silently pick the removed one.
|
|
304
|
+
*/
|
|
305
|
+
export function chooseFpsMode(versionOutput: string | undefined, helpOutput: string | undefined): boolean {
|
|
306
|
+
const byVersion = versionOutput === undefined ? undefined : supportsFpsMode(versionOutput);
|
|
307
|
+
if (byVersion !== undefined) return byVersion;
|
|
308
|
+
if (helpOutput !== undefined && /-vsync\b|-fps_mode\b/.test(helpOutput)) return /-fps_mode\b/.test(helpOutput);
|
|
309
|
+
return true;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* The exact ffmpeg argv. `-fps_mode vfr` (or `-vsync vfr` on ffmpeg <5.1, see
|
|
314
|
+
* supportsFpsMode) passes the concat demuxer's
|
|
283
315
|
* per-frame timestamps through instead of resampling them to a constant rate.
|
|
284
316
|
* `-t` is deliberately NOT used to pin the duration: it trims at the LAST
|
|
285
317
|
* frame's PTS, which throws away exactly the long final hold the ledger exists
|
|
@@ -293,7 +325,7 @@ export function buildFfmpegArgs(manifestPath: string, outPath: string, choice: E
|
|
|
293
325
|
"-f", "concat",
|
|
294
326
|
"-safe", "0",
|
|
295
327
|
"-i", manifestPath,
|
|
296
|
-
"-vsync", "vfr",
|
|
328
|
+
...(choice.fpsMode ? ["-fps_mode", "vfr"] : ["-vsync", "vfr"]),
|
|
297
329
|
"-vf", "scale=trunc(iw/2)*2:trunc(ih/2)*2",
|
|
298
330
|
"-c:v", choice.encoder,
|
|
299
331
|
...(choice.tag ? ["-tag:v", choice.tag] : []),
|
|
@@ -352,7 +384,15 @@ async function probeEncoder(): Promise<EncoderChoice> {
|
|
|
352
384
|
throw new CdpError(`${FFMPEG_MISSING} (${(err as Error).message})`);
|
|
353
385
|
}
|
|
354
386
|
if (res.code !== 0) throw new CdpError(`${FFMPEG_MISSING} ('-encoders' exited ${res.code}: ${res.stderr.trim().slice(0, 300)})`);
|
|
355
|
-
|
|
387
|
+
const choice = selectEncoder(`${res.stdout}\n${res.stderr}`);
|
|
388
|
+
const output = async (args: string[]): Promise<string | undefined> => {
|
|
389
|
+
const r = await run(FFMPEG_BIN, args).catch(() => undefined);
|
|
390
|
+
return r && r.code === 0 ? `${r.stdout}\n${r.stderr}` : undefined;
|
|
391
|
+
};
|
|
392
|
+
const version = await output(["-version"]);
|
|
393
|
+
const byVersion = version === undefined ? undefined : supportsFpsMode(version);
|
|
394
|
+
const help = byVersion === undefined ? await output(["-hide_banner", "-h", "full"]) : undefined;
|
|
395
|
+
return { ...choice, fpsMode: chooseFpsMode(version, help) };
|
|
356
396
|
})();
|
|
357
397
|
// A failed probe must not poison every later call: forget it so a caller who
|
|
358
398
|
// installs ffmpeg and retries is not told it is still missing.
|
|
@@ -367,7 +407,7 @@ async function probeEncoder(): Promise<EncoderChoice> {
|
|
|
367
407
|
|
|
368
408
|
/** A live screencast held in-process between start and stop, keyed by targetId. */
|
|
369
409
|
interface LiveRecording {
|
|
370
|
-
conn:
|
|
410
|
+
conn: PageConnection;
|
|
371
411
|
target: Target;
|
|
372
412
|
spoolDir: string;
|
|
373
413
|
ledger: FrameLedgerEntry[];
|
package/src/tools/snapshot.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* `DOM.resolveNode({ backendNodeId: uid })`. There is no server-side ref
|
|
9
9
|
* table to drift or expire.
|
|
10
10
|
*/
|
|
11
|
-
import type {
|
|
11
|
+
import type { PageConnection } from "../client.ts";
|
|
12
12
|
import { withPage } from "../client.ts";
|
|
13
13
|
import type { Target, TargetSelector, Uid } from "../types.ts";
|
|
14
14
|
|
|
@@ -175,7 +175,7 @@ export async function takeSnapshot(args: TakeSnapshotArgs = {}): Promise<TakeSna
|
|
|
175
175
|
* Resolve a Uid (backendDOMNodeId) to a live JS object handle. Shared by every
|
|
176
176
|
* interaction tool in input.ts. Throws if the node no longer exists.
|
|
177
177
|
*/
|
|
178
|
-
export async function resolveUid(conn:
|
|
178
|
+
export async function resolveUid(conn: PageConnection, uid: Uid): Promise<{ objectId: string }> {
|
|
179
179
|
const { object } = await conn.send<{ object: { objectId?: string } }>("DOM.resolveNode", {
|
|
180
180
|
backendNodeId: uid,
|
|
181
181
|
});
|
package/src/version.ts
CHANGED