@saptools/cf-inspector 0.3.15 → 0.3.16
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/dist/cli.js +119 -116
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +7 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -258,7 +258,6 @@ function writeLogEvent(event, json) {
|
|
|
258
258
|
}
|
|
259
259
|
|
|
260
260
|
// src/inspector.ts
|
|
261
|
-
import { request } from "http";
|
|
262
261
|
import { performance } from "perf_hooks";
|
|
263
262
|
|
|
264
263
|
// src/cdp.ts
|
|
@@ -471,6 +470,125 @@ var CdpClient = class _CdpClient {
|
|
|
471
470
|
}
|
|
472
471
|
};
|
|
473
472
|
|
|
473
|
+
// src/inspectorDiscovery.ts
|
|
474
|
+
init_types();
|
|
475
|
+
import { request } from "http";
|
|
476
|
+
async function fetchJson(url, timeoutMs) {
|
|
477
|
+
return await new Promise((resolve, reject) => {
|
|
478
|
+
const req = request(url, { method: "GET" }, (res) => {
|
|
479
|
+
const chunks = [];
|
|
480
|
+
res.on("data", (chunk) => {
|
|
481
|
+
chunks.push(chunk);
|
|
482
|
+
});
|
|
483
|
+
res.on("end", () => {
|
|
484
|
+
try {
|
|
485
|
+
const text = Buffer.concat(chunks).toString("utf8");
|
|
486
|
+
resolve(JSON.parse(text));
|
|
487
|
+
} catch (err) {
|
|
488
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
489
|
+
reject(
|
|
490
|
+
new CfInspectorError(
|
|
491
|
+
"INSPECTOR_DISCOVERY_FAILED",
|
|
492
|
+
`Failed to parse inspector discovery response from ${url}: ${message}`
|
|
493
|
+
)
|
|
494
|
+
);
|
|
495
|
+
}
|
|
496
|
+
});
|
|
497
|
+
res.on("error", (err) => {
|
|
498
|
+
reject(
|
|
499
|
+
new CfInspectorError(
|
|
500
|
+
"INSPECTOR_DISCOVERY_FAILED",
|
|
501
|
+
`Inspector discovery response error: ${err.message}`
|
|
502
|
+
)
|
|
503
|
+
);
|
|
504
|
+
});
|
|
505
|
+
});
|
|
506
|
+
req.setTimeout(timeoutMs, () => {
|
|
507
|
+
req.destroy(
|
|
508
|
+
new CfInspectorError(
|
|
509
|
+
"INSPECTOR_DISCOVERY_FAILED",
|
|
510
|
+
`Inspector discovery at ${url} timed out after ${timeoutMs.toString()}ms`
|
|
511
|
+
)
|
|
512
|
+
);
|
|
513
|
+
});
|
|
514
|
+
req.on("error", (err) => {
|
|
515
|
+
reject(
|
|
516
|
+
err instanceof CfInspectorError ? err : new CfInspectorError(
|
|
517
|
+
"INSPECTOR_DISCOVERY_FAILED",
|
|
518
|
+
`Inspector discovery at ${url} failed: ${err.message}`
|
|
519
|
+
)
|
|
520
|
+
);
|
|
521
|
+
});
|
|
522
|
+
req.end();
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
function toInspectorTarget(value, source) {
|
|
526
|
+
if (typeof value !== "object" || value === null) {
|
|
527
|
+
throw new CfInspectorError(
|
|
528
|
+
"INSPECTOR_DISCOVERY_FAILED",
|
|
529
|
+
`Inspector target is not an object in ${source}`
|
|
530
|
+
);
|
|
531
|
+
}
|
|
532
|
+
const candidate = value;
|
|
533
|
+
const webSocketDebuggerUrl = candidate["webSocketDebuggerUrl"];
|
|
534
|
+
if (typeof webSocketDebuggerUrl !== "string" || webSocketDebuggerUrl.length === 0) {
|
|
535
|
+
throw new CfInspectorError(
|
|
536
|
+
"INSPECTOR_DISCOVERY_FAILED",
|
|
537
|
+
`Inspector target is missing webSocketDebuggerUrl in ${source}`
|
|
538
|
+
);
|
|
539
|
+
}
|
|
540
|
+
return {
|
|
541
|
+
description: typeof candidate["description"] === "string" ? candidate["description"] : "",
|
|
542
|
+
id: typeof candidate["id"] === "string" ? candidate["id"] : "",
|
|
543
|
+
title: typeof candidate["title"] === "string" ? candidate["title"] : "",
|
|
544
|
+
type: typeof candidate["type"] === "string" ? candidate["type"] : "",
|
|
545
|
+
url: typeof candidate["url"] === "string" ? candidate["url"] : "",
|
|
546
|
+
webSocketDebuggerUrl,
|
|
547
|
+
...typeof candidate["devtoolsFrontendUrl"] === "string" ? { devtoolsFrontendUrl: candidate["devtoolsFrontendUrl"] } : {},
|
|
548
|
+
...typeof candidate["faviconUrl"] === "string" ? { faviconUrl: candidate["faviconUrl"] } : {}
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
async function discoverInspectorTargets(host, port, timeoutMs) {
|
|
552
|
+
const url = `http://${host}:${port.toString()}/json/list`;
|
|
553
|
+
const raw = await fetchJson(url, timeoutMs);
|
|
554
|
+
if (!Array.isArray(raw) || raw.length === 0) {
|
|
555
|
+
throw new CfInspectorError(
|
|
556
|
+
"INSPECTOR_DISCOVERY_FAILED",
|
|
557
|
+
`No inspector targets returned from ${url}`
|
|
558
|
+
);
|
|
559
|
+
}
|
|
560
|
+
return raw.map((entry, idx) => toInspectorTarget(entry, `${url}[${idx.toString()}]`));
|
|
561
|
+
}
|
|
562
|
+
function readVersionField(value, ...keys) {
|
|
563
|
+
for (const key of keys) {
|
|
564
|
+
const entry = value[key];
|
|
565
|
+
if (typeof entry === "string" && entry.length > 0) {
|
|
566
|
+
return entry;
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
return void 0;
|
|
570
|
+
}
|
|
571
|
+
async function fetchInspectorVersion(host, port, timeoutMs) {
|
|
572
|
+
const url = `http://${host}:${port.toString()}/json/version`;
|
|
573
|
+
const raw = await fetchJson(url, timeoutMs);
|
|
574
|
+
if (typeof raw !== "object" || raw === null) {
|
|
575
|
+
throw new CfInspectorError(
|
|
576
|
+
"INSPECTOR_DISCOVERY_FAILED",
|
|
577
|
+
`Unexpected /json/version response from ${url}`
|
|
578
|
+
);
|
|
579
|
+
}
|
|
580
|
+
const value = raw;
|
|
581
|
+
const browser = readVersionField(value, "Browser", "browser");
|
|
582
|
+
const protocolVersion = readVersionField(value, "Protocol-Version", "protocolVersion");
|
|
583
|
+
if (browser === void 0 || protocolVersion === void 0) {
|
|
584
|
+
throw new CfInspectorError(
|
|
585
|
+
"INSPECTOR_DISCOVERY_FAILED",
|
|
586
|
+
`Unexpected /json/version response from ${url}`
|
|
587
|
+
);
|
|
588
|
+
}
|
|
589
|
+
return { browser, protocolVersion };
|
|
590
|
+
}
|
|
591
|
+
|
|
474
592
|
// src/pathMapper.ts
|
|
475
593
|
init_types();
|
|
476
594
|
var REGEX_PREFIX = "regex:";
|
|
@@ -614,121 +732,6 @@ function buildBreakpointUrlRegex(input) {
|
|
|
614
732
|
init_types();
|
|
615
733
|
var DEFAULT_CONNECT_TIMEOUT_MS = 5e3;
|
|
616
734
|
var DEFAULT_HOST = "127.0.0.1";
|
|
617
|
-
async function fetchJson(url, timeoutMs) {
|
|
618
|
-
return await new Promise((resolve, reject) => {
|
|
619
|
-
const req = request(url, { method: "GET" }, (res) => {
|
|
620
|
-
const chunks = [];
|
|
621
|
-
res.on("data", (chunk) => {
|
|
622
|
-
chunks.push(chunk);
|
|
623
|
-
});
|
|
624
|
-
res.on("end", () => {
|
|
625
|
-
try {
|
|
626
|
-
const text = Buffer.concat(chunks).toString("utf8");
|
|
627
|
-
resolve(JSON.parse(text));
|
|
628
|
-
} catch (err) {
|
|
629
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
630
|
-
reject(
|
|
631
|
-
new CfInspectorError(
|
|
632
|
-
"INSPECTOR_DISCOVERY_FAILED",
|
|
633
|
-
`Failed to parse inspector discovery response from ${url}: ${message}`
|
|
634
|
-
)
|
|
635
|
-
);
|
|
636
|
-
}
|
|
637
|
-
});
|
|
638
|
-
res.on("error", (err) => {
|
|
639
|
-
reject(
|
|
640
|
-
new CfInspectorError(
|
|
641
|
-
"INSPECTOR_DISCOVERY_FAILED",
|
|
642
|
-
`Inspector discovery response error: ${err.message}`
|
|
643
|
-
)
|
|
644
|
-
);
|
|
645
|
-
});
|
|
646
|
-
});
|
|
647
|
-
req.setTimeout(timeoutMs, () => {
|
|
648
|
-
req.destroy(
|
|
649
|
-
new CfInspectorError(
|
|
650
|
-
"INSPECTOR_DISCOVERY_FAILED",
|
|
651
|
-
`Inspector discovery at ${url} timed out after ${timeoutMs.toString()}ms`
|
|
652
|
-
)
|
|
653
|
-
);
|
|
654
|
-
});
|
|
655
|
-
req.on("error", (err) => {
|
|
656
|
-
reject(
|
|
657
|
-
err instanceof CfInspectorError ? err : new CfInspectorError(
|
|
658
|
-
"INSPECTOR_DISCOVERY_FAILED",
|
|
659
|
-
`Inspector discovery at ${url} failed: ${err.message}`
|
|
660
|
-
)
|
|
661
|
-
);
|
|
662
|
-
});
|
|
663
|
-
req.end();
|
|
664
|
-
});
|
|
665
|
-
}
|
|
666
|
-
function toInspectorTarget(value, source) {
|
|
667
|
-
if (typeof value !== "object" || value === null) {
|
|
668
|
-
throw new CfInspectorError(
|
|
669
|
-
"INSPECTOR_DISCOVERY_FAILED",
|
|
670
|
-
`Inspector target is not an object in ${source}`
|
|
671
|
-
);
|
|
672
|
-
}
|
|
673
|
-
const candidate = value;
|
|
674
|
-
const webSocketDebuggerUrl = candidate["webSocketDebuggerUrl"];
|
|
675
|
-
if (typeof webSocketDebuggerUrl !== "string" || webSocketDebuggerUrl.length === 0) {
|
|
676
|
-
throw new CfInspectorError(
|
|
677
|
-
"INSPECTOR_DISCOVERY_FAILED",
|
|
678
|
-
`Inspector target is missing webSocketDebuggerUrl in ${source}`
|
|
679
|
-
);
|
|
680
|
-
}
|
|
681
|
-
return {
|
|
682
|
-
description: typeof candidate["description"] === "string" ? candidate["description"] : "",
|
|
683
|
-
id: typeof candidate["id"] === "string" ? candidate["id"] : "",
|
|
684
|
-
title: typeof candidate["title"] === "string" ? candidate["title"] : "",
|
|
685
|
-
type: typeof candidate["type"] === "string" ? candidate["type"] : "",
|
|
686
|
-
url: typeof candidate["url"] === "string" ? candidate["url"] : "",
|
|
687
|
-
webSocketDebuggerUrl,
|
|
688
|
-
...typeof candidate["devtoolsFrontendUrl"] === "string" ? { devtoolsFrontendUrl: candidate["devtoolsFrontendUrl"] } : {},
|
|
689
|
-
...typeof candidate["faviconUrl"] === "string" ? { faviconUrl: candidate["faviconUrl"] } : {}
|
|
690
|
-
};
|
|
691
|
-
}
|
|
692
|
-
async function discoverInspectorTargets(host, port, timeoutMs) {
|
|
693
|
-
const url = `http://${host}:${port.toString()}/json/list`;
|
|
694
|
-
const raw = await fetchJson(url, timeoutMs);
|
|
695
|
-
if (!Array.isArray(raw) || raw.length === 0) {
|
|
696
|
-
throw new CfInspectorError(
|
|
697
|
-
"INSPECTOR_DISCOVERY_FAILED",
|
|
698
|
-
`No inspector targets returned from ${url}`
|
|
699
|
-
);
|
|
700
|
-
}
|
|
701
|
-
return raw.map((entry, idx) => toInspectorTarget(entry, `${url}[${idx.toString()}]`));
|
|
702
|
-
}
|
|
703
|
-
function readVersionField(value, ...keys) {
|
|
704
|
-
for (const key of keys) {
|
|
705
|
-
const entry = value[key];
|
|
706
|
-
if (typeof entry === "string" && entry.length > 0) {
|
|
707
|
-
return entry;
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
return void 0;
|
|
711
|
-
}
|
|
712
|
-
async function fetchInspectorVersion(host, port, timeoutMs) {
|
|
713
|
-
const url = `http://${host}:${port.toString()}/json/version`;
|
|
714
|
-
const raw = await fetchJson(url, timeoutMs);
|
|
715
|
-
if (typeof raw !== "object" || raw === null) {
|
|
716
|
-
throw new CfInspectorError(
|
|
717
|
-
"INSPECTOR_DISCOVERY_FAILED",
|
|
718
|
-
`Unexpected /json/version response from ${url}`
|
|
719
|
-
);
|
|
720
|
-
}
|
|
721
|
-
const value = raw;
|
|
722
|
-
const browser = readVersionField(value, "Browser", "browser");
|
|
723
|
-
const protocolVersion = readVersionField(value, "Protocol-Version", "protocolVersion");
|
|
724
|
-
if (browser === void 0 || protocolVersion === void 0) {
|
|
725
|
-
throw new CfInspectorError(
|
|
726
|
-
"INSPECTOR_DISCOVERY_FAILED",
|
|
727
|
-
`Unexpected /json/version response from ${url}`
|
|
728
|
-
);
|
|
729
|
-
}
|
|
730
|
-
return { browser, protocolVersion };
|
|
731
|
-
}
|
|
732
735
|
async function connectInspector(options) {
|
|
733
736
|
const host = options.host ?? DEFAULT_HOST;
|
|
734
737
|
const connectTimeoutMs = options.connectTimeoutMs ?? DEFAULT_CONNECT_TIMEOUT_MS;
|