@skrillex1224/playwright-toolkit 2.1.167 → 2.1.168
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/index.cjs +68 -3
- package/dist/index.cjs.map +2 -2
- package/dist/index.js +68 -3
- package/dist/index.js.map +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -558,6 +558,7 @@ var FLUSH_INTERVAL_MS = 2e3;
|
|
|
558
558
|
var DEFAULT_DEBUG_MAX_EVENTS = 400;
|
|
559
559
|
var runtime = null;
|
|
560
560
|
var cleanupInstalled = false;
|
|
561
|
+
var observedDomainResourceTypes = /* @__PURE__ */ new Map();
|
|
561
562
|
var toSafeInt = (value) => {
|
|
562
563
|
const num = Number(value);
|
|
563
564
|
if (!Number.isFinite(num) || num <= 0) return 0;
|
|
@@ -568,6 +569,50 @@ var toSafeFloat = (value) => {
|
|
|
568
569
|
if (!Number.isFinite(num)) return 0;
|
|
569
570
|
return num;
|
|
570
571
|
};
|
|
572
|
+
var normalizeResourceType = (value) => {
|
|
573
|
+
const type = String(value || "").trim().toLowerCase();
|
|
574
|
+
if (!type) return "other";
|
|
575
|
+
return type;
|
|
576
|
+
};
|
|
577
|
+
var resolveHostname = (requestUrl) => {
|
|
578
|
+
const raw = String(requestUrl || "").trim();
|
|
579
|
+
if (!raw) return "";
|
|
580
|
+
try {
|
|
581
|
+
return String(new URL(raw).hostname || "").trim().toLowerCase();
|
|
582
|
+
} catch {
|
|
583
|
+
return "";
|
|
584
|
+
}
|
|
585
|
+
};
|
|
586
|
+
var recordDomainResourceType = (domain, resourceType) => {
|
|
587
|
+
const host = String(domain || "").trim().toLowerCase();
|
|
588
|
+
if (!host) return;
|
|
589
|
+
const type = normalizeResourceType(resourceType);
|
|
590
|
+
let byType = observedDomainResourceTypes.get(host);
|
|
591
|
+
if (!byType) {
|
|
592
|
+
byType = /* @__PURE__ */ new Map();
|
|
593
|
+
observedDomainResourceTypes.set(host, byType);
|
|
594
|
+
}
|
|
595
|
+
byType.set(type, (byType.get(type) || 0) + 1);
|
|
596
|
+
};
|
|
597
|
+
var resolveResourceTypeMeta = (domain) => {
|
|
598
|
+
const host = String(domain || "").trim().toLowerCase();
|
|
599
|
+
if (!host) return { resourceType: "", resourceTypeCounts: void 0 };
|
|
600
|
+
const byType = observedDomainResourceTypes.get(host);
|
|
601
|
+
if (!byType || byType.size === 0) {
|
|
602
|
+
return { resourceType: "", resourceTypeCounts: void 0 };
|
|
603
|
+
}
|
|
604
|
+
const entries = Array.from(byType.entries()).filter(([type, count]) => type && Number(count) > 0).sort((a, b) => {
|
|
605
|
+
if (Number(b[1]) !== Number(a[1])) return Number(b[1]) - Number(a[1]);
|
|
606
|
+
return String(a[0]).localeCompare(String(b[0]));
|
|
607
|
+
});
|
|
608
|
+
if (entries.length === 0) {
|
|
609
|
+
return { resourceType: "", resourceTypeCounts: void 0 };
|
|
610
|
+
}
|
|
611
|
+
return {
|
|
612
|
+
resourceType: entries[0][0],
|
|
613
|
+
resourceTypeCounts: Object.fromEntries(entries.map(([type, count]) => [type, toSafeInt(count)]))
|
|
614
|
+
};
|
|
615
|
+
};
|
|
571
616
|
var resolveScriptPath = () => {
|
|
572
617
|
const baseDir = typeof __dirname !== "undefined" ? __dirname : path.dirname(fileURLToPath(import.meta.url));
|
|
573
618
|
return path.join(baseDir, "proxy-meter.js");
|
|
@@ -632,13 +677,16 @@ var normalizeDomainRows = (hosts) => {
|
|
|
632
677
|
requestCount += requests;
|
|
633
678
|
connectCount += connections;
|
|
634
679
|
if (totalBytes <= 0 && requests <= 0 && connections <= 0) continue;
|
|
680
|
+
const resourceTypeMeta = resolveResourceTypeMeta(domain);
|
|
635
681
|
rows.push({
|
|
636
682
|
domain,
|
|
637
683
|
inBytes,
|
|
638
684
|
outBytes,
|
|
639
685
|
totalBytes,
|
|
640
686
|
requests,
|
|
641
|
-
connections
|
|
687
|
+
connections,
|
|
688
|
+
resourceType: resourceTypeMeta.resourceType || void 0,
|
|
689
|
+
resourceTypeCounts: resourceTypeMeta.resourceTypeCounts || void 0
|
|
642
690
|
});
|
|
643
691
|
}
|
|
644
692
|
rows.sort((a, b) => {
|
|
@@ -769,6 +817,7 @@ var startProxyMeter = (options = {}) => {
|
|
|
769
817
|
}
|
|
770
818
|
runtime = null;
|
|
771
819
|
}
|
|
820
|
+
observedDomainResourceTypes = /* @__PURE__ */ new Map();
|
|
772
821
|
const port = pickFreePort();
|
|
773
822
|
const logPath = ensureLogPath();
|
|
774
823
|
const scriptPath = resolveScriptPath();
|
|
@@ -801,6 +850,12 @@ var startProxyMeter = (options = {}) => {
|
|
|
801
850
|
registerCleanup();
|
|
802
851
|
return { server: `http://127.0.0.1:${port}` };
|
|
803
852
|
};
|
|
853
|
+
var recordProxyMeterResourceType = (requestUrl, resourceType) => {
|
|
854
|
+
if (!runtime) return;
|
|
855
|
+
const host = resolveHostname(requestUrl);
|
|
856
|
+
if (!host) return;
|
|
857
|
+
recordDomainResourceType(host, resourceType);
|
|
858
|
+
};
|
|
804
859
|
var stopProxyMeter = async () => {
|
|
805
860
|
if (!runtime) return null;
|
|
806
861
|
const { proc, logPath } = runtime;
|
|
@@ -1655,6 +1710,7 @@ var findMatchedByPassRule = (rules = [], requestUrl = "") => {
|
|
|
1655
1710
|
|
|
1656
1711
|
// src/launch.js
|
|
1657
1712
|
var logger7 = createInternalLogger("Launch");
|
|
1713
|
+
var REQUEST_HOOK_FLAG = Symbol("playwright-toolkit-request-hook");
|
|
1658
1714
|
var DEFAULT_CRAWLER_BASE_OPTIONS = Object.freeze({
|
|
1659
1715
|
maxConcurrency: 1,
|
|
1660
1716
|
maxRequestRetries: 0,
|
|
@@ -1731,14 +1787,23 @@ var Launch = {
|
|
|
1731
1787
|
const recommendedGotoOptions = {
|
|
1732
1788
|
waitUntil: "commit"
|
|
1733
1789
|
};
|
|
1734
|
-
if (!
|
|
1790
|
+
if (!page || typeof page.on !== "function") {
|
|
1791
|
+
return recommendedGotoOptions;
|
|
1792
|
+
}
|
|
1793
|
+
if (page[REQUEST_HOOK_FLAG]) {
|
|
1735
1794
|
return recommendedGotoOptions;
|
|
1736
1795
|
}
|
|
1796
|
+
page[REQUEST_HOOK_FLAG] = true;
|
|
1737
1797
|
const requestHandler = (req) => {
|
|
1738
1798
|
const requestUrl = req.url();
|
|
1799
|
+
const resourceType = req.resourceType();
|
|
1800
|
+
if (launchProxy) {
|
|
1801
|
+
recordProxyMeterResourceType(requestUrl, resourceType);
|
|
1802
|
+
}
|
|
1803
|
+
if (!enableByPassLogger || byPassDomains.length === 0) return;
|
|
1739
1804
|
const matched = findMatchedByPassRule(byPassRules, requestUrl);
|
|
1740
1805
|
if (!matched || !matched.rule) return;
|
|
1741
|
-
logger7.info(`[\u76F4\u8FDE\u547D\u4E2D] \u89C4\u5219=${matched.rule.pattern} \u57DF\u540D=${matched.hostname} \u8D44\u6E90\u7C7B\u578B=${
|
|
1806
|
+
logger7.info(`[\u76F4\u8FDE\u547D\u4E2D] \u89C4\u5219=${matched.rule.pattern} \u57DF\u540D=${matched.hostname} \u8D44\u6E90\u7C7B\u578B=${resourceType} \u65B9\u6CD5=${req.method()} \u5730\u5740=${requestUrl}`);
|
|
1742
1807
|
};
|
|
1743
1808
|
page.on("request", requestHandler);
|
|
1744
1809
|
return recommendedGotoOptions;
|