@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.cjs
CHANGED
|
@@ -586,6 +586,7 @@ var FLUSH_INTERVAL_MS = 2e3;
|
|
|
586
586
|
var DEFAULT_DEBUG_MAX_EVENTS = 400;
|
|
587
587
|
var runtime = null;
|
|
588
588
|
var cleanupInstalled = false;
|
|
589
|
+
var observedDomainResourceTypes = /* @__PURE__ */ new Map();
|
|
589
590
|
var toSafeInt = (value) => {
|
|
590
591
|
const num = Number(value);
|
|
591
592
|
if (!Number.isFinite(num) || num <= 0) return 0;
|
|
@@ -596,6 +597,50 @@ var toSafeFloat = (value) => {
|
|
|
596
597
|
if (!Number.isFinite(num)) return 0;
|
|
597
598
|
return num;
|
|
598
599
|
};
|
|
600
|
+
var normalizeResourceType = (value) => {
|
|
601
|
+
const type = String(value || "").trim().toLowerCase();
|
|
602
|
+
if (!type) return "other";
|
|
603
|
+
return type;
|
|
604
|
+
};
|
|
605
|
+
var resolveHostname = (requestUrl) => {
|
|
606
|
+
const raw = String(requestUrl || "").trim();
|
|
607
|
+
if (!raw) return "";
|
|
608
|
+
try {
|
|
609
|
+
return String(new URL(raw).hostname || "").trim().toLowerCase();
|
|
610
|
+
} catch {
|
|
611
|
+
return "";
|
|
612
|
+
}
|
|
613
|
+
};
|
|
614
|
+
var recordDomainResourceType = (domain, resourceType) => {
|
|
615
|
+
const host = String(domain || "").trim().toLowerCase();
|
|
616
|
+
if (!host) return;
|
|
617
|
+
const type = normalizeResourceType(resourceType);
|
|
618
|
+
let byType = observedDomainResourceTypes.get(host);
|
|
619
|
+
if (!byType) {
|
|
620
|
+
byType = /* @__PURE__ */ new Map();
|
|
621
|
+
observedDomainResourceTypes.set(host, byType);
|
|
622
|
+
}
|
|
623
|
+
byType.set(type, (byType.get(type) || 0) + 1);
|
|
624
|
+
};
|
|
625
|
+
var resolveResourceTypeMeta = (domain) => {
|
|
626
|
+
const host = String(domain || "").trim().toLowerCase();
|
|
627
|
+
if (!host) return { resourceType: "", resourceTypeCounts: void 0 };
|
|
628
|
+
const byType = observedDomainResourceTypes.get(host);
|
|
629
|
+
if (!byType || byType.size === 0) {
|
|
630
|
+
return { resourceType: "", resourceTypeCounts: void 0 };
|
|
631
|
+
}
|
|
632
|
+
const entries = Array.from(byType.entries()).filter(([type, count]) => type && Number(count) > 0).sort((a, b) => {
|
|
633
|
+
if (Number(b[1]) !== Number(a[1])) return Number(b[1]) - Number(a[1]);
|
|
634
|
+
return String(a[0]).localeCompare(String(b[0]));
|
|
635
|
+
});
|
|
636
|
+
if (entries.length === 0) {
|
|
637
|
+
return { resourceType: "", resourceTypeCounts: void 0 };
|
|
638
|
+
}
|
|
639
|
+
return {
|
|
640
|
+
resourceType: entries[0][0],
|
|
641
|
+
resourceTypeCounts: Object.fromEntries(entries.map(([type, count]) => [type, toSafeInt(count)]))
|
|
642
|
+
};
|
|
643
|
+
};
|
|
599
644
|
var resolveScriptPath = () => {
|
|
600
645
|
const baseDir = typeof __dirname !== "undefined" ? __dirname : import_path.default.dirname((0, import_url.fileURLToPath)(import_meta.url));
|
|
601
646
|
return import_path.default.join(baseDir, "proxy-meter.js");
|
|
@@ -660,13 +705,16 @@ var normalizeDomainRows = (hosts) => {
|
|
|
660
705
|
requestCount += requests;
|
|
661
706
|
connectCount += connections;
|
|
662
707
|
if (totalBytes <= 0 && requests <= 0 && connections <= 0) continue;
|
|
708
|
+
const resourceTypeMeta = resolveResourceTypeMeta(domain);
|
|
663
709
|
rows.push({
|
|
664
710
|
domain,
|
|
665
711
|
inBytes,
|
|
666
712
|
outBytes,
|
|
667
713
|
totalBytes,
|
|
668
714
|
requests,
|
|
669
|
-
connections
|
|
715
|
+
connections,
|
|
716
|
+
resourceType: resourceTypeMeta.resourceType || void 0,
|
|
717
|
+
resourceTypeCounts: resourceTypeMeta.resourceTypeCounts || void 0
|
|
670
718
|
});
|
|
671
719
|
}
|
|
672
720
|
rows.sort((a, b) => {
|
|
@@ -797,6 +845,7 @@ var startProxyMeter = (options = {}) => {
|
|
|
797
845
|
}
|
|
798
846
|
runtime = null;
|
|
799
847
|
}
|
|
848
|
+
observedDomainResourceTypes = /* @__PURE__ */ new Map();
|
|
800
849
|
const port = pickFreePort();
|
|
801
850
|
const logPath = ensureLogPath();
|
|
802
851
|
const scriptPath = resolveScriptPath();
|
|
@@ -829,6 +878,12 @@ var startProxyMeter = (options = {}) => {
|
|
|
829
878
|
registerCleanup();
|
|
830
879
|
return { server: `http://127.0.0.1:${port}` };
|
|
831
880
|
};
|
|
881
|
+
var recordProxyMeterResourceType = (requestUrl, resourceType) => {
|
|
882
|
+
if (!runtime) return;
|
|
883
|
+
const host = resolveHostname(requestUrl);
|
|
884
|
+
if (!host) return;
|
|
885
|
+
recordDomainResourceType(host, resourceType);
|
|
886
|
+
};
|
|
832
887
|
var stopProxyMeter = async () => {
|
|
833
888
|
if (!runtime) return null;
|
|
834
889
|
const { proc, logPath } = runtime;
|
|
@@ -1683,6 +1738,7 @@ var findMatchedByPassRule = (rules = [], requestUrl = "") => {
|
|
|
1683
1738
|
|
|
1684
1739
|
// src/launch.js
|
|
1685
1740
|
var logger7 = createInternalLogger("Launch");
|
|
1741
|
+
var REQUEST_HOOK_FLAG = Symbol("playwright-toolkit-request-hook");
|
|
1686
1742
|
var DEFAULT_CRAWLER_BASE_OPTIONS = Object.freeze({
|
|
1687
1743
|
maxConcurrency: 1,
|
|
1688
1744
|
maxRequestRetries: 0,
|
|
@@ -1759,14 +1815,23 @@ var Launch = {
|
|
|
1759
1815
|
const recommendedGotoOptions = {
|
|
1760
1816
|
waitUntil: "commit"
|
|
1761
1817
|
};
|
|
1762
|
-
if (!
|
|
1818
|
+
if (!page || typeof page.on !== "function") {
|
|
1819
|
+
return recommendedGotoOptions;
|
|
1820
|
+
}
|
|
1821
|
+
if (page[REQUEST_HOOK_FLAG]) {
|
|
1763
1822
|
return recommendedGotoOptions;
|
|
1764
1823
|
}
|
|
1824
|
+
page[REQUEST_HOOK_FLAG] = true;
|
|
1765
1825
|
const requestHandler = (req) => {
|
|
1766
1826
|
const requestUrl = req.url();
|
|
1827
|
+
const resourceType = req.resourceType();
|
|
1828
|
+
if (launchProxy) {
|
|
1829
|
+
recordProxyMeterResourceType(requestUrl, resourceType);
|
|
1830
|
+
}
|
|
1831
|
+
if (!enableByPassLogger || byPassDomains.length === 0) return;
|
|
1767
1832
|
const matched = findMatchedByPassRule(byPassRules, requestUrl);
|
|
1768
1833
|
if (!matched || !matched.rule) return;
|
|
1769
|
-
logger7.info(`[\u76F4\u8FDE\u547D\u4E2D] \u89C4\u5219=${matched.rule.pattern} \u57DF\u540D=${matched.hostname} \u8D44\u6E90\u7C7B\u578B=${
|
|
1834
|
+
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}`);
|
|
1770
1835
|
};
|
|
1771
1836
|
page.on("request", requestHandler);
|
|
1772
1837
|
return recommendedGotoOptions;
|