cdp-toolkit 1.9.5 → 1.10.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 +54 -0
- package/dist/cli.js +287 -269
- package/dist/index.js +21 -19
- package/dist/mcp.js +297 -271
- package/package.json +1 -1
- package/src/bidi/client.ts +11 -0
- package/src/bidi/driver.ts +7 -1
- package/src/bidi/launch.ts +9 -2
- package/src/manifest.ts +253 -246
- package/src/mcp.ts +16 -2
- package/src/tools/recorder.ts +8 -5
package/dist/index.js
CHANGED
|
@@ -3700,12 +3700,14 @@ import { readFile as readFile4 } from "node:fs/promises";
|
|
|
3700
3700
|
|
|
3701
3701
|
// src/tools/recorder.ts
|
|
3702
3702
|
import { mkdir as mkdir6, appendFile, writeFile as writeFile5, copyFile } from "node:fs/promises";
|
|
3703
|
-
|
|
3703
|
+
function artifactDir() {
|
|
3704
|
+
return process.env.CDP_ARTIFACT_DIR ?? "/tmp/cdp-toolkit";
|
|
3705
|
+
}
|
|
3704
3706
|
function recFile(targetId) {
|
|
3705
|
-
return `${
|
|
3707
|
+
return `${artifactDir()}/rec-${targetId}.jsonl`;
|
|
3706
3708
|
}
|
|
3707
3709
|
function captureFile(targetId, captureId) {
|
|
3708
|
-
return `${
|
|
3710
|
+
return `${artifactDir()}/rec-${targetId}-${captureId}.jsonl`;
|
|
3709
3711
|
}
|
|
3710
3712
|
function delay2(ms) {
|
|
3711
3713
|
return new Promise((r) => setTimeout(r, ms));
|
|
@@ -3745,7 +3747,7 @@ var CONSOLE_EVENTS = ["Runtime.consoleAPICalled", "Runtime.exceptionThrown", "Lo
|
|
|
3745
3747
|
async function startRecorder(target, opts = {}) {
|
|
3746
3748
|
const network = opts.network ?? true;
|
|
3747
3749
|
const consoleCap = opts.console ?? true;
|
|
3748
|
-
await mkdir6(
|
|
3750
|
+
await mkdir6(artifactDir(), { recursive: true });
|
|
3749
3751
|
const { conn, target: resolved } = await openPage(target, { timeoutMs: opts.timeoutMs });
|
|
3750
3752
|
const file = opts.file ?? recFile(resolved.id);
|
|
3751
3753
|
if (opts.truncate) {
|
|
@@ -4105,7 +4107,7 @@ async function getNetworkRequest(args = {}) {
|
|
|
4105
4107
|
// src/tools/performance.ts
|
|
4106
4108
|
import { mkdir as mkdir7, readFile as readFile6, writeFile as writeFile6, stat, unlink as unlink4 } from "node:fs/promises";
|
|
4107
4109
|
import { join as join5 } from "node:path";
|
|
4108
|
-
var
|
|
4110
|
+
var ARTIFACT_DIR2 = process.env.CDP_ARTIFACT_DIR ?? "/tmp/cdp-toolkit";
|
|
4109
4111
|
var STATE_DIR2 = process.env.CDP_STATE_DIR ?? "/tmp/cdp-toolkit";
|
|
4110
4112
|
var DEFAULT_CATEGORIES = [
|
|
4111
4113
|
"devtools.timeline",
|
|
@@ -4144,8 +4146,8 @@ async function endTrace(conn, sink, timeoutMs = 30000) {
|
|
|
4144
4146
|
return sink;
|
|
4145
4147
|
}
|
|
4146
4148
|
async function writeTrace(events, targetId) {
|
|
4147
|
-
await mkdir7(
|
|
4148
|
-
const path = join5(
|
|
4149
|
+
await mkdir7(ARTIFACT_DIR2, { recursive: true });
|
|
4150
|
+
const path = join5(ARTIFACT_DIR2, `trace-${shortId(targetId)}-${stamp2()}.json`);
|
|
4149
4151
|
const body = JSON.stringify({ traceEvents: events, metadata: { source: "cdp-toolkit" } });
|
|
4150
4152
|
await writeFile6(path, body, "utf8");
|
|
4151
4153
|
const { size } = await stat(path);
|
|
@@ -4338,7 +4340,7 @@ async function performanceAnalyzeInsight(args = {}) {
|
|
|
4338
4340
|
import { spawn } from "node:child_process";
|
|
4339
4341
|
import { mkdir as mkdir8, rm as rm2, stat as stat2, writeFile as writeFile7 } from "node:fs/promises";
|
|
4340
4342
|
import { join as join6 } from "node:path";
|
|
4341
|
-
var
|
|
4343
|
+
var ARTIFACT_DIR3 = process.env.CDP_ARTIFACT_DIR ?? "/tmp/cdp-toolkit";
|
|
4342
4344
|
var FFMPEG_BIN = process.env.CDP_FFMPEG ?? "ffmpeg";
|
|
4343
4345
|
function frameDurationsMs(ledger, stopWallclockMs) {
|
|
4344
4346
|
return ledger.map((entry, i) => {
|
|
@@ -4558,7 +4560,7 @@ async function startScreenRecording(args = {}) {
|
|
|
4558
4560
|
conn.close();
|
|
4559
4561
|
throw err;
|
|
4560
4562
|
}
|
|
4561
|
-
const spoolDir = join6(
|
|
4563
|
+
const spoolDir = join6(ARTIFACT_DIR3, `screencast-${shortId2(target.id)}-${stamp3()}`);
|
|
4562
4564
|
try {
|
|
4563
4565
|
await mkdir8(spoolDir, { recursive: true });
|
|
4564
4566
|
} catch (err) {
|
|
@@ -4664,8 +4666,8 @@ async function stopScreenRecording(args = {}) {
|
|
|
4664
4666
|
await rm2(rec.spoolDir, { recursive: true, force: true }).catch(() => {});
|
|
4665
4667
|
throw new CdpError(`screen recording captured 0 frames for target ${shortId2(rec.target.id)}. Chrome emits a screencast frame only on repaint: a fully backgrounded or occluded tab may never paint. Retry with bringToFront:true, or drive the page while recording.`);
|
|
4666
4668
|
}
|
|
4667
|
-
await mkdir8(
|
|
4668
|
-
const outPath = args.savePath ?? join6(
|
|
4669
|
+
await mkdir8(ARTIFACT_DIR3, { recursive: true });
|
|
4670
|
+
const outPath = args.savePath ?? join6(ARTIFACT_DIR3, `screen-recording-${shortId2(rec.target.id)}-${stamp3()}.mp4`);
|
|
4669
4671
|
const frames = coalesceToConcatGrid(ledger, stoppedAt);
|
|
4670
4672
|
const manifestPath = join6(rec.spoolDir, "frames.ffconcat");
|
|
4671
4673
|
await writeFile7(manifestPath, buildConcatManifest(frames), "utf8");
|
|
@@ -4701,7 +4703,7 @@ ffmpeg said: ${res.stderr.trim().slice(0, 800)}`);
|
|
|
4701
4703
|
// src/tools/heap.ts
|
|
4702
4704
|
import { mkdir as mkdir9, writeFile as writeFile8 } from "node:fs/promises";
|
|
4703
4705
|
import { join as join7 } from "node:path";
|
|
4704
|
-
var
|
|
4706
|
+
var ARTIFACT_DIR4 = process.env.CDP_ARTIFACT_DIR ?? "/tmp/cdp-toolkit";
|
|
4705
4707
|
function stamp4(targetId) {
|
|
4706
4708
|
const short = targetId.slice(0, 8);
|
|
4707
4709
|
const iso = new Date().toISOString().replace(/[:.]/g, "-");
|
|
@@ -4725,8 +4727,8 @@ async function takeHeapsnapshot(args = {}) {
|
|
|
4725
4727
|
if (snapshot.length === 0) {
|
|
4726
4728
|
throw new Error("HeapProfiler.takeHeapSnapshot produced no chunks");
|
|
4727
4729
|
}
|
|
4728
|
-
await mkdir9(
|
|
4729
|
-
const path = args.savePath ? args.savePath.startsWith("/") ? args.savePath : join7(
|
|
4730
|
+
await mkdir9(ARTIFACT_DIR4, { recursive: true });
|
|
4731
|
+
const path = args.savePath ? args.savePath.startsWith("/") ? args.savePath : join7(ARTIFACT_DIR4, args.savePath) : join7(ARTIFACT_DIR4, `take_heapsnapshot-${stamp4(target.id)}.heapsnapshot`);
|
|
4730
4732
|
await writeFile8(path, snapshot, "utf8");
|
|
4731
4733
|
const bytes = Buffer.byteLength(snapshot, "utf8");
|
|
4732
4734
|
return {
|
|
@@ -4741,7 +4743,7 @@ async function takeHeapsnapshot(args = {}) {
|
|
|
4741
4743
|
// src/tools/lighthouse.ts
|
|
4742
4744
|
import { spawn as spawn2 } from "node:child_process";
|
|
4743
4745
|
import { mkdir as mkdir10, readFile as readFile7, stat as stat3 } from "node:fs/promises";
|
|
4744
|
-
var
|
|
4746
|
+
var ARTIFACT_DIR5 = process.env.CDP_ARTIFACT_DIR ?? "/tmp/cdp-toolkit";
|
|
4745
4747
|
function cdpPort() {
|
|
4746
4748
|
const base = process.env.CDP_BASE ?? "http://127.0.0.1:9222";
|
|
4747
4749
|
const m = base.match(/:(\d+)/);
|
|
@@ -4801,8 +4803,8 @@ async function lighthouseAudit(args) {
|
|
|
4801
4803
|
const url = args.url.trim();
|
|
4802
4804
|
const timeoutMs = args.timeoutMs ?? 120000;
|
|
4803
4805
|
const port = cdpPort();
|
|
4804
|
-
await mkdir10(
|
|
4805
|
-
const outPath = args.savePath ?? `${
|
|
4806
|
+
await mkdir10(ARTIFACT_DIR5, { recursive: true });
|
|
4807
|
+
const outPath = args.savePath ?? `${ARTIFACT_DIR5}/lighthouse-${shortHost(url)}-${stamp5()}.json`;
|
|
4806
4808
|
const formFactor = args.formFactor ?? "desktop";
|
|
4807
4809
|
const lhArgs = [
|
|
4808
4810
|
"--yes",
|
|
@@ -4923,8 +4925,8 @@ import { basename, extname, join as join9 } from "node:path";
|
|
|
4923
4925
|
// src/tools/browser-session.ts
|
|
4924
4926
|
import { mkdir as mkdir11 } from "node:fs/promises";
|
|
4925
4927
|
import { join as join8 } from "node:path";
|
|
4926
|
-
var
|
|
4927
|
-
var DOWNLOADS_DIR = join8(
|
|
4928
|
+
var ARTIFACT_DIR6 = process.env.CDP_ARTIFACT_DIR ?? "/tmp/cdp-toolkit";
|
|
4929
|
+
var DOWNLOADS_DIR = join8(ARTIFACT_DIR6, "downloads");
|
|
4928
4930
|
var DOWNLOAD_BUFFER_LIMIT = 50;
|
|
4929
4931
|
var session;
|
|
4930
4932
|
function isDisconnect(e) {
|