@skrillex1224/playwright-toolkit 2.1.285 → 3.0.1
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/browser.js +3 -3
- package/dist/browser.js.map +2 -2
- package/dist/index.cjs +132 -245
- package/dist/index.cjs.map +4 -4
- package/dist/index.js +132 -245
- package/dist/index.js.map +4 -4
- package/index.d.ts +15 -37
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -66,7 +66,7 @@ var Device = Object.freeze({
|
|
|
66
66
|
});
|
|
67
67
|
var Mode = Object.freeze({
|
|
68
68
|
Default: "default",
|
|
69
|
-
|
|
69
|
+
Cloak: "cloak"
|
|
70
70
|
});
|
|
71
71
|
var normalizeDevice = (value, fallback = Device.Desktop) => {
|
|
72
72
|
const normalizedFallback = String(fallback || "").trim().toLowerCase() === Device.Mobile ? Device.Mobile : Device.Desktop;
|
|
@@ -76,9 +76,9 @@ var normalizeDevice = (value, fallback = Device.Desktop) => {
|
|
|
76
76
|
return normalizedFallback;
|
|
77
77
|
};
|
|
78
78
|
var normalizeMode = (value, fallback = Mode.Default) => {
|
|
79
|
-
const normalizedFallback = String(fallback || "").trim().toLowerCase() === Mode.
|
|
79
|
+
const normalizedFallback = String(fallback || "").trim().toLowerCase() === Mode.Cloak ? Mode.Cloak : Mode.Default;
|
|
80
80
|
const raw = String(value || "").trim().toLowerCase();
|
|
81
|
-
if (raw === Mode.
|
|
81
|
+
if (raw === Mode.Cloak) return Mode.Cloak;
|
|
82
82
|
if (raw === Mode.Default) return Mode.Default;
|
|
83
83
|
return normalizedFallback;
|
|
84
84
|
};
|
|
@@ -2509,35 +2509,59 @@ var setToolkitMode = (mode = Mode.Default) => ToolkitContext.setMode(mode);
|
|
|
2509
2509
|
var resolveModeStrategy = (strategies = {}, mode = getToolkitMode(), fallbackMode = Mode.Default) => {
|
|
2510
2510
|
const normalizedStrategies = normalizeStrategies(strategies);
|
|
2511
2511
|
const normalizedMode = normalizeMode(mode, fallbackMode);
|
|
2512
|
-
const
|
|
2512
|
+
const strategy = normalizedStrategies[normalizedMode] ?? normalizedStrategies[fallbackMode] ?? Object.values(normalizedStrategies).find(Boolean) ?? null;
|
|
2513
2513
|
return {
|
|
2514
2514
|
mode: normalizedMode,
|
|
2515
|
-
|
|
2515
|
+
strategy
|
|
2516
2516
|
};
|
|
2517
2517
|
};
|
|
2518
2518
|
|
|
2519
|
-
// src/internals/
|
|
2520
|
-
var
|
|
2521
|
-
|
|
2522
|
-
|
|
2519
|
+
// src/internals/reflect.js
|
|
2520
|
+
var normalizeStrategies2 = (strategies) => strategies && typeof strategies === "object" ? strategies : {};
|
|
2521
|
+
var collectFunctionNames = (strategies = []) => {
|
|
2522
|
+
const names = /* @__PURE__ */ new Set();
|
|
2523
|
+
for (const strategy of strategies) {
|
|
2524
|
+
if (!strategy || typeof strategy !== "object") continue;
|
|
2525
|
+
for (const name of Reflect.ownKeys(strategy)) {
|
|
2526
|
+
if (typeof name === "string" && typeof strategy[name] === "function") {
|
|
2527
|
+
names.add(name);
|
|
2528
|
+
}
|
|
2529
|
+
}
|
|
2530
|
+
}
|
|
2531
|
+
return names;
|
|
2523
2532
|
};
|
|
2524
|
-
var
|
|
2525
|
-
enumerable,
|
|
2533
|
+
var methodDescriptor = (namespace, name, resolveTarget) => ({
|
|
2534
|
+
enumerable: true,
|
|
2535
|
+
configurable: true,
|
|
2536
|
+
writable: true,
|
|
2526
2537
|
value: (...args) => {
|
|
2527
|
-
const { mode,
|
|
2528
|
-
|
|
2529
|
-
|
|
2538
|
+
const { mode, strategy } = resolveTarget(args);
|
|
2539
|
+
const method = strategy?.[name];
|
|
2540
|
+
if (typeof method !== "function") {
|
|
2541
|
+
throw new Error(`${namespace}.${name} is not available in ${mode} mode`);
|
|
2530
2542
|
}
|
|
2531
|
-
return
|
|
2543
|
+
return method.apply(strategy, args);
|
|
2532
2544
|
}
|
|
2533
2545
|
});
|
|
2534
|
-
var
|
|
2535
|
-
const
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2546
|
+
var withModeReflect = (namespace, strategies = {}) => {
|
|
2547
|
+
const normalizedStrategies = normalizeStrategies2(strategies);
|
|
2548
|
+
const baseStrategy = normalizedStrategies.default ?? Object.values(normalizedStrategies).find(Boolean);
|
|
2549
|
+
const names = collectFunctionNames([baseStrategy]);
|
|
2550
|
+
const descriptors = {};
|
|
2551
|
+
for (const name of names) {
|
|
2552
|
+
descriptors[name] = methodDescriptor(namespace, name, () => resolveModeStrategy(normalizedStrategies));
|
|
2553
|
+
}
|
|
2554
|
+
return Object.defineProperties({}, descriptors);
|
|
2555
|
+
};
|
|
2556
|
+
var withPageReflect = (namespace, resolveStrategy, strategies = []) => {
|
|
2557
|
+
const names = collectFunctionNames(strategies);
|
|
2558
|
+
const descriptors = {};
|
|
2559
|
+
for (const name of names) {
|
|
2560
|
+
descriptors[name] = methodDescriptor(namespace, name, ([page]) => ({
|
|
2561
|
+
mode: "page",
|
|
2562
|
+
strategy: resolveStrategy(page)
|
|
2563
|
+
}));
|
|
2564
|
+
}
|
|
2541
2565
|
return Object.defineProperties({}, descriptors);
|
|
2542
2566
|
};
|
|
2543
2567
|
|
|
@@ -2613,8 +2637,8 @@ var DefaultAntiCheat = {
|
|
|
2613
2637
|
}
|
|
2614
2638
|
};
|
|
2615
2639
|
|
|
2616
|
-
// src/internals/anti-cheat/
|
|
2617
|
-
var
|
|
2640
|
+
// src/internals/anti-cheat/cloak.js
|
|
2641
|
+
var CLOAK_BASE_CONFIG = Object.freeze({
|
|
2618
2642
|
locale: "",
|
|
2619
2643
|
acceptLanguage: "",
|
|
2620
2644
|
timezoneId: "",
|
|
@@ -2622,12 +2646,12 @@ var CLOAK_BROWSER_BASE_CONFIG = Object.freeze({
|
|
|
2622
2646
|
geolocation: null
|
|
2623
2647
|
});
|
|
2624
2648
|
var normalizeHeaders = (headers) => headers && typeof headers === "object" ? headers : {};
|
|
2625
|
-
var
|
|
2649
|
+
var CloakAntiCheat = {
|
|
2626
2650
|
/**
|
|
2627
|
-
*
|
|
2651
|
+
* Cloak 自身会负责浏览器指纹,toolkit 在该模式下尽量不再注入额外反检测配置。
|
|
2628
2652
|
*/
|
|
2629
2653
|
getBaseConfig() {
|
|
2630
|
-
return { ...
|
|
2654
|
+
return { ...CLOAK_BASE_CONFIG };
|
|
2631
2655
|
},
|
|
2632
2656
|
getFingerprintGeneratorOptions() {
|
|
2633
2657
|
return {};
|
|
@@ -2650,15 +2674,9 @@ var CloakBrowserAntiCheat = {
|
|
|
2650
2674
|
// src/anti-cheat.js
|
|
2651
2675
|
var antiCheatStrategies = {
|
|
2652
2676
|
[Mode.Default]: DefaultAntiCheat,
|
|
2653
|
-
[Mode.
|
|
2654
|
-
};
|
|
2655
|
-
var AntiCheat =
|
|
2656
|
-
"getBaseConfig",
|
|
2657
|
-
"getFingerprintGeneratorOptions",
|
|
2658
|
-
"getLaunchArgs",
|
|
2659
|
-
"getTlsFingerprintOptions",
|
|
2660
|
-
"applyLocaleHeaders"
|
|
2661
|
-
]);
|
|
2677
|
+
[Mode.Cloak]: CloakAntiCheat
|
|
2678
|
+
};
|
|
2679
|
+
var AntiCheat = withModeReflect("AntiCheat", antiCheatStrategies);
|
|
2662
2680
|
|
|
2663
2681
|
// src/device-input.js
|
|
2664
2682
|
var resolveDeviceFromPage = (page) => normalizeDevice(page?.[PageRuntimeStateKey]?.device);
|
|
@@ -3210,6 +3228,9 @@ var DeviceView = {
|
|
|
3210
3228
|
}
|
|
3211
3229
|
};
|
|
3212
3230
|
|
|
3231
|
+
// src/internals/humanize/index.js
|
|
3232
|
+
var import_delay4 = __toESM(require("delay"), 1);
|
|
3233
|
+
|
|
3213
3234
|
// src/internals/humanize/desktop.js
|
|
3214
3235
|
var import_delay2 = __toESM(require("delay"), 1);
|
|
3215
3236
|
var import_ghost_cursor_playwright = require("ghost-cursor-playwright");
|
|
@@ -4679,217 +4700,85 @@ var resolveDeviceFromPage2 = (page) => normalizeDevice(page?.[PageRuntimeStateKe
|
|
|
4679
4700
|
var resolveDelegate = (page) => {
|
|
4680
4701
|
return resolveDeviceFromPage2(page) === Device.Mobile ? MobileHumanize : Humanize;
|
|
4681
4702
|
};
|
|
4682
|
-
var
|
|
4683
|
-
|
|
4684
|
-
|
|
4685
|
-
|
|
4686
|
-
|
|
4687
|
-
jitterMs(base, jitterPercent = 0.3) {
|
|
4688
|
-
return Humanize.jitterMs(base, jitterPercent);
|
|
4689
|
-
},
|
|
4690
|
-
initializeCursor(page) {
|
|
4691
|
-
return callDelegate("initializeCursor", page, []);
|
|
4692
|
-
},
|
|
4693
|
-
humanMove(page, target) {
|
|
4694
|
-
return callDelegate("humanMove", page, [target]);
|
|
4695
|
-
},
|
|
4696
|
-
humanScroll(page, target, options = {}) {
|
|
4697
|
-
return callDelegate("humanScroll", page, [target, options]);
|
|
4698
|
-
},
|
|
4699
|
-
humanClick(page, target, options = {}) {
|
|
4700
|
-
return callDelegate("humanClick", page, [target, options]);
|
|
4701
|
-
},
|
|
4702
|
-
randomSleep(pageOrBaseMs, maybeBaseMs, maybeJitterPercent) {
|
|
4703
|
-
if (pageOrBaseMs && typeof pageOrBaseMs === "object" && typeof pageOrBaseMs.evaluate === "function") {
|
|
4704
|
-
const delegate = resolveDelegate(pageOrBaseMs);
|
|
4705
|
-
return delegate.randomSleep(maybeBaseMs, maybeJitterPercent);
|
|
4706
|
-
}
|
|
4707
|
-
return Humanize.randomSleep(pageOrBaseMs, maybeBaseMs);
|
|
4708
|
-
},
|
|
4709
|
-
simulateGaze(page, baseDurationMs = 2500) {
|
|
4710
|
-
return callDelegate("simulateGaze", page, [baseDurationMs]);
|
|
4711
|
-
},
|
|
4712
|
-
humanType(page, selector, text, options = {}) {
|
|
4713
|
-
return callDelegate("humanType", page, [selector, text, options]);
|
|
4714
|
-
},
|
|
4715
|
-
humanPress(page, targetOrKey, maybeKey, options = {}) {
|
|
4716
|
-
if (typeof maybeKey === "string") {
|
|
4717
|
-
return callDelegate("humanPress", page, [targetOrKey, maybeKey, options]);
|
|
4718
|
-
}
|
|
4719
|
-
return callDelegate("humanPress", page, [targetOrKey, maybeKey || options]);
|
|
4720
|
-
},
|
|
4721
|
-
humanClear(page, selector) {
|
|
4722
|
-
return callDelegate("humanClear", page, [selector]);
|
|
4723
|
-
},
|
|
4724
|
-
warmUpBrowsing(page, baseDuration = 3500) {
|
|
4725
|
-
return callDelegate("warmUpBrowsing", page, [baseDuration]);
|
|
4726
|
-
},
|
|
4727
|
-
naturalScroll(page, direction = "down", distance = 300, baseSteps = 5) {
|
|
4728
|
-
return callDelegate("naturalScroll", page, [direction, distance, baseSteps]);
|
|
4729
|
-
}
|
|
4730
|
-
};
|
|
4703
|
+
var DefaultHumanizeDevice = withPageReflect(
|
|
4704
|
+
"DefaultHumanize",
|
|
4705
|
+
resolveDelegate,
|
|
4706
|
+
[Humanize, MobileHumanize]
|
|
4707
|
+
);
|
|
4731
4708
|
|
|
4732
|
-
// src/internals/humanize/
|
|
4733
|
-
var
|
|
4734
|
-
|
|
4735
|
-
|
|
4736
|
-
|
|
4737
|
-
var
|
|
4738
|
-
|
|
4739
|
-
|
|
4740
|
-
|
|
4741
|
-
|
|
4742
|
-
|
|
4743
|
-
return jitterMs(base, jitterPercent);
|
|
4744
|
-
},
|
|
4709
|
+
// src/internals/humanize/cloak.js
|
|
4710
|
+
var FORCE_CLICK = Object.freeze({
|
|
4711
|
+
forceClick: true,
|
|
4712
|
+
clickOptions: { force: true }
|
|
4713
|
+
});
|
|
4714
|
+
var pointOrNull = async (target) => {
|
|
4715
|
+
if (!target || typeof target.boundingBox !== "function") return null;
|
|
4716
|
+
const box = await target.boundingBox().catch(() => null);
|
|
4717
|
+
return box ? { x: box.x + box.width / 2, y: box.y + box.height / 2 } : null;
|
|
4718
|
+
};
|
|
4719
|
+
var CloakHumanizeInput = {
|
|
4745
4720
|
async initializeCursor(page) {
|
|
4746
4721
|
return Boolean(page);
|
|
4747
4722
|
},
|
|
4748
4723
|
async humanMove(page, target) {
|
|
4749
|
-
|
|
4750
|
-
|
|
4751
|
-
await page.mouse.move(Number(target.x), Number(target.y));
|
|
4752
|
-
return true;
|
|
4753
|
-
}
|
|
4754
|
-
await resolveTarget(page, target).hover(FORCE_OPTIONS);
|
|
4755
|
-
return true;
|
|
4724
|
+
const point = target?.x != null && target?.y != null ? target : await pointOrNull(typeof target === "string" ? page.locator(target).first() : target);
|
|
4725
|
+
return point ? await DeviceInput.move(page, point, { forceMouse: true }) : false;
|
|
4756
4726
|
},
|
|
4757
4727
|
async humanScroll(page, target) {
|
|
4758
|
-
const element =
|
|
4728
|
+
const element = typeof target === "string" ? page.locator(target).first() : target;
|
|
4759
4729
|
if (!element) return { element: null, didScroll: false, restore: null };
|
|
4760
4730
|
await element.scrollIntoViewIfNeeded?.();
|
|
4761
4731
|
return { element, didScroll: true, restore: null };
|
|
4762
4732
|
},
|
|
4763
4733
|
async humanClick(page, target) {
|
|
4764
|
-
|
|
4765
|
-
await page.mouse.click(0, 0);
|
|
4766
|
-
return true;
|
|
4767
|
-
}
|
|
4768
|
-
if (isPoint2(target)) {
|
|
4769
|
-
await page.mouse.click(Number(target.x), Number(target.y));
|
|
4770
|
-
return true;
|
|
4771
|
-
}
|
|
4772
|
-
if (typeof target === "string") {
|
|
4773
|
-
await page.click(target, FORCE_OPTIONS);
|
|
4774
|
-
return true;
|
|
4775
|
-
}
|
|
4776
|
-
await target.click(FORCE_OPTIONS);
|
|
4777
|
-
return true;
|
|
4778
|
-
},
|
|
4779
|
-
async randomSleep(baseMs, jitterPercent = 0.3) {
|
|
4780
|
-
await sleep(baseMs, jitterPercent);
|
|
4781
|
-
},
|
|
4782
|
-
async simulateGaze(page, baseDurationMs = 2500) {
|
|
4783
|
-
const durationMs = jitterMs(baseDurationMs, 0.4);
|
|
4784
|
-
const startedAt = Date.now();
|
|
4785
|
-
const viewport = page.viewportSize() || { width: 1365, height: 900 };
|
|
4786
|
-
while (Date.now() - startedAt < durationMs) {
|
|
4787
|
-
await page.mouse.move(
|
|
4788
|
-
100 + Math.random() * Math.max(120, viewport.width - 200),
|
|
4789
|
-
100 + Math.random() * Math.max(120, viewport.height - 200)
|
|
4790
|
-
);
|
|
4791
|
-
await sleep(300, 0.5);
|
|
4792
|
-
}
|
|
4734
|
+
return await DeviceInput.click(page, target, FORCE_CLICK);
|
|
4793
4735
|
},
|
|
4794
4736
|
async humanType(page, selector, text) {
|
|
4795
|
-
|
|
4796
|
-
await
|
|
4797
|
-
await page.keyboard.type(text);
|
|
4737
|
+
await DeviceInput.click(page, selector, FORCE_CLICK);
|
|
4738
|
+
return await DeviceInput.keyboardType(page, text);
|
|
4798
4739
|
},
|
|
4799
4740
|
async humanPress(page, targetOrKey, maybeKey) {
|
|
4800
|
-
|
|
4801
|
-
|
|
4802
|
-
|
|
4803
|
-
}
|
|
4804
|
-
await resolveTarget(page, targetOrKey).click(FORCE_OPTIONS);
|
|
4805
|
-
await page.keyboard.press(maybeKey);
|
|
4806
|
-
return true;
|
|
4741
|
+
return await DeviceInput.press(page, targetOrKey, maybeKey, {
|
|
4742
|
+
clickOptions: FORCE_CLICK,
|
|
4743
|
+
keyboardOptions: {}
|
|
4744
|
+
});
|
|
4807
4745
|
},
|
|
4808
4746
|
async humanClear(page, selector) {
|
|
4809
|
-
|
|
4810
|
-
await page.fill(selector, "", FORCE_OPTIONS);
|
|
4811
|
-
return;
|
|
4812
|
-
}
|
|
4813
|
-
await selector.fill("", FORCE_OPTIONS);
|
|
4747
|
+
return await DeviceInput.fill(page, selector, "", { force: true });
|
|
4814
4748
|
},
|
|
4815
|
-
async
|
|
4816
|
-
await
|
|
4749
|
+
async simulateGaze(page) {
|
|
4750
|
+
return await DeviceInput.move(page, { x: 0, y: 0 }, { forceMouse: true });
|
|
4817
4751
|
},
|
|
4818
|
-
async
|
|
4819
|
-
|
|
4820
|
-
|
|
4821
|
-
|
|
4822
|
-
|
|
4823
|
-
|
|
4824
|
-
}
|
|
4752
|
+
async warmUpBrowsing(page) {
|
|
4753
|
+
return await this.simulateGaze(page);
|
|
4754
|
+
},
|
|
4755
|
+
async naturalScroll(page, direction = "down", distance = 300) {
|
|
4756
|
+
const sign = direction === "down" ? 1 : -1;
|
|
4757
|
+
await page.mouse.wheel(0, Number(distance || 0) * sign);
|
|
4825
4758
|
}
|
|
4826
4759
|
};
|
|
4827
|
-
|
|
4828
|
-
|
|
4829
|
-
var
|
|
4760
|
+
|
|
4761
|
+
// src/internals/humanize/index.js
|
|
4762
|
+
var HumanizeCommon = {
|
|
4830
4763
|
jitterMs(base, jitterPercent = 0.3) {
|
|
4831
4764
|
return jitterMs(base, jitterPercent);
|
|
4832
4765
|
},
|
|
4833
|
-
|
|
4834
|
-
|
|
4835
|
-
|
|
4836
|
-
|
|
4837
|
-
|
|
4838
|
-
},
|
|
4839
|
-
humanScroll(page, target, options = {}) {
|
|
4840
|
-
return callDelegate2("humanScroll", page, [target, options]);
|
|
4841
|
-
},
|
|
4842
|
-
humanClick(page, target, options = {}) {
|
|
4843
|
-
return callDelegate2("humanClick", page, [target, options]);
|
|
4844
|
-
},
|
|
4845
|
-
randomSleep(pageOrBaseMs, maybeBaseMs, maybeJitterPercent) {
|
|
4846
|
-
if (isPageLike2(pageOrBaseMs)) {
|
|
4847
|
-
return resolveDelegate2(pageOrBaseMs).randomSleep(maybeBaseMs, maybeJitterPercent);
|
|
4848
|
-
}
|
|
4849
|
-
return DesktopCloakHumanize.randomSleep(pageOrBaseMs, maybeBaseMs);
|
|
4850
|
-
},
|
|
4851
|
-
simulateGaze(page, baseDurationMs = 2500) {
|
|
4852
|
-
return callDelegate2("simulateGaze", page, [baseDurationMs]);
|
|
4853
|
-
},
|
|
4854
|
-
humanType(page, selector, text, options = {}) {
|
|
4855
|
-
return callDelegate2("humanType", page, [selector, text, options]);
|
|
4856
|
-
},
|
|
4857
|
-
humanPress(page, targetOrKey, maybeKey, options = {}) {
|
|
4858
|
-
if (typeof maybeKey === "string") {
|
|
4859
|
-
return callDelegate2("humanPress", page, [targetOrKey, maybeKey, options]);
|
|
4860
|
-
}
|
|
4861
|
-
return callDelegate2("humanPress", page, [targetOrKey, maybeKey || options]);
|
|
4862
|
-
},
|
|
4863
|
-
humanClear(page, selector) {
|
|
4864
|
-
return callDelegate2("humanClear", page, [selector]);
|
|
4865
|
-
},
|
|
4866
|
-
warmUpBrowsing(page, baseDuration = 3500) {
|
|
4867
|
-
return callDelegate2("warmUpBrowsing", page, [baseDuration]);
|
|
4868
|
-
},
|
|
4869
|
-
naturalScroll(page, direction = "down", distance = 300, baseSteps = 5) {
|
|
4870
|
-
return callDelegate2("naturalScroll", page, [direction, distance, baseSteps]);
|
|
4766
|
+
async randomSleep(pageOrBaseMs, maybeBaseMs, maybeJitterPercent) {
|
|
4767
|
+
const hasPage = pageOrBaseMs && typeof pageOrBaseMs === "object" && typeof pageOrBaseMs.evaluate === "function";
|
|
4768
|
+
const baseMs = hasPage ? maybeBaseMs : pageOrBaseMs;
|
|
4769
|
+
const jitterPercent = hasPage ? maybeJitterPercent : maybeBaseMs;
|
|
4770
|
+
await (0, import_delay4.default)(jitterMs(baseMs, jitterPercent ?? 0.3));
|
|
4871
4771
|
}
|
|
4872
4772
|
};
|
|
4773
|
+
var DefaultHumanize = Object.assign({}, DefaultHumanizeDevice, HumanizeCommon);
|
|
4774
|
+
var CloakHumanize = Object.assign({}, CloakHumanizeInput, HumanizeCommon);
|
|
4873
4775
|
|
|
4874
4776
|
// src/humanize.js
|
|
4875
4777
|
var humanizeStrategies = {
|
|
4876
4778
|
[Mode.Default]: DefaultHumanize,
|
|
4877
|
-
[Mode.
|
|
4878
|
-
};
|
|
4879
|
-
var Humanize2 =
|
|
4880
|
-
"jitterMs",
|
|
4881
|
-
"initializeCursor",
|
|
4882
|
-
"humanMove",
|
|
4883
|
-
"humanScroll",
|
|
4884
|
-
"humanClick",
|
|
4885
|
-
"randomSleep",
|
|
4886
|
-
"simulateGaze",
|
|
4887
|
-
"humanType",
|
|
4888
|
-
"humanPress",
|
|
4889
|
-
"humanClear",
|
|
4890
|
-
"warmUpBrowsing",
|
|
4891
|
-
"naturalScroll"
|
|
4892
|
-
]);
|
|
4779
|
+
[Mode.Cloak]: CloakHumanize
|
|
4780
|
+
};
|
|
4781
|
+
var Humanize2 = withModeReflect("Humanize", humanizeStrategies);
|
|
4893
4782
|
|
|
4894
4783
|
// src/internals/launch/default.js
|
|
4895
4784
|
var import_node_child_process = require("node:child_process");
|
|
@@ -5327,10 +5216,10 @@ var DefaultLaunch = {
|
|
|
5327
5216
|
}
|
|
5328
5217
|
};
|
|
5329
5218
|
|
|
5330
|
-
// src/internals/launch/
|
|
5219
|
+
// src/internals/launch/cloak.js
|
|
5331
5220
|
var import_node_child_process2 = require("node:child_process");
|
|
5332
5221
|
var import_node_util = require("node:util");
|
|
5333
|
-
var logger8 = createInternalLogger("
|
|
5222
|
+
var logger8 = createInternalLogger("Cloak");
|
|
5334
5223
|
var execFileAsync = (0, import_node_util.promisify)(import_node_child_process2.execFile);
|
|
5335
5224
|
var DEFAULT_CLOAK_CRAWLER_BASE_OPTIONS = Object.freeze({
|
|
5336
5225
|
maxConcurrency: 1,
|
|
@@ -5344,21 +5233,21 @@ var DEFAULT_CLOAK_HUMANIZE_OPTIONS = Object.freeze({
|
|
|
5344
5233
|
var DEFAULT_CLOAK_GOTO_OPTIONS = Object.freeze({
|
|
5345
5234
|
waitUntil: "commit"
|
|
5346
5235
|
});
|
|
5347
|
-
var
|
|
5236
|
+
var cachedCloakModulePromise = null;
|
|
5348
5237
|
var hasOwn = (target, key) => Object.prototype.hasOwnProperty.call(target, key);
|
|
5349
|
-
var
|
|
5350
|
-
if (!
|
|
5351
|
-
|
|
5352
|
-
|
|
5353
|
-
throw new Error("
|
|
5238
|
+
var loadCloakModule = async () => {
|
|
5239
|
+
if (!cachedCloakModulePromise) {
|
|
5240
|
+
cachedCloakModulePromise = import("cloakbrowser").catch((error) => {
|
|
5241
|
+
cachedCloakModulePromise = null;
|
|
5242
|
+
throw new Error("Cloak \u6A21\u5757\u52A0\u8F7D\u5931\u8D25\uFF0C\u8BF7\u786E\u8BA4\u5F53\u524D\u8FD0\u884C\u73AF\u5883\u5DF2\u5B89\u88C5 cloakbrowser\u3002", {
|
|
5354
5243
|
cause: error
|
|
5355
5244
|
});
|
|
5356
5245
|
});
|
|
5357
5246
|
}
|
|
5358
|
-
return
|
|
5247
|
+
return cachedCloakModulePromise;
|
|
5359
5248
|
};
|
|
5360
5249
|
var buildCloakLaunchOptions = async (options = {}) => {
|
|
5361
|
-
const { buildLaunchOptions } = await
|
|
5250
|
+
const { buildLaunchOptions } = await loadCloakModule();
|
|
5362
5251
|
return await buildLaunchOptions(normalizeObject(options));
|
|
5363
5252
|
};
|
|
5364
5253
|
var normalizeObject = (value) => {
|
|
@@ -5373,7 +5262,7 @@ var normalizeStringArray = (value) => {
|
|
|
5373
5262
|
}
|
|
5374
5263
|
return value.map((item) => String(item || "").trim()).filter(Boolean);
|
|
5375
5264
|
};
|
|
5376
|
-
var
|
|
5265
|
+
var resolveCloakProxy = (proxyConfiguration = {}) => {
|
|
5377
5266
|
const config = normalizeObject(proxyConfiguration);
|
|
5378
5267
|
const proxyUrl = String(config.proxy_url || "").trim();
|
|
5379
5268
|
const enableProxy = typeof config.enable_proxy === "boolean" ? config.enable_proxy : proxyUrl !== "";
|
|
@@ -5407,7 +5296,7 @@ var createStableGotoHook = (recommendedGotoOptions = DEFAULT_CLOAK_GOTO_OPTIONS)
|
|
|
5407
5296
|
}
|
|
5408
5297
|
};
|
|
5409
5298
|
};
|
|
5410
|
-
var
|
|
5299
|
+
var attachCloakHumanizeHook = ({
|
|
5411
5300
|
browserPoolOptions = {},
|
|
5412
5301
|
activeBrowsers,
|
|
5413
5302
|
patchedBrowsers,
|
|
@@ -5438,7 +5327,7 @@ var attachCloakBrowserHumanizeHook = ({
|
|
|
5438
5327
|
if (!shouldHumanize || patchedBrowsers.has(browser)) {
|
|
5439
5328
|
return;
|
|
5440
5329
|
}
|
|
5441
|
-
const { humanizeBrowser } = await
|
|
5330
|
+
const { humanizeBrowser } = await loadCloakModule();
|
|
5442
5331
|
await humanizeBrowser(browser, normalizedHumanizeOptions);
|
|
5443
5332
|
patchedBrowsers.add(browser);
|
|
5444
5333
|
}
|
|
@@ -5466,12 +5355,12 @@ var forceTerminateBrowsersByFingerprintArg = async (fingerprintArg) => {
|
|
|
5466
5355
|
if (error?.code === 1 || error?.code === "ENOENT") {
|
|
5467
5356
|
return;
|
|
5468
5357
|
}
|
|
5469
|
-
logger8.info(`\u5F3A\u5236\u5173\u95ED
|
|
5358
|
+
logger8.info(`\u5F3A\u5236\u5173\u95ED Cloak \u8FDB\u7A0B\u5931\u8D25\uFF08\u5FFD\u7565\uFF09: ${error?.message || String(error)}`);
|
|
5470
5359
|
});
|
|
5471
5360
|
};
|
|
5472
|
-
var
|
|
5361
|
+
var CloakLaunch = {
|
|
5473
5362
|
resolveProxyConfiguration(proxyConfiguration = {}) {
|
|
5474
|
-
return
|
|
5363
|
+
return resolveCloakProxy(proxyConfiguration);
|
|
5475
5364
|
},
|
|
5476
5365
|
extractFingerprintArg(launchOptions = {}) {
|
|
5477
5366
|
return extractFingerprintArg(launchOptions);
|
|
@@ -5480,7 +5369,7 @@ var CloakBrowserLaunch = {
|
|
|
5480
5369
|
return createStableGotoHook(recommendedGotoOptions);
|
|
5481
5370
|
},
|
|
5482
5371
|
async getPlaywrightCrawlerOptions(options = {}) {
|
|
5483
|
-
const runtime2 = await
|
|
5372
|
+
const runtime2 = await CloakLaunch.createPlaywrightCrawlerRuntime(options);
|
|
5484
5373
|
return Object.defineProperties(runtime2.crawlerOptions, {
|
|
5485
5374
|
cleanup: {
|
|
5486
5375
|
enumerable: false,
|
|
@@ -5520,7 +5409,7 @@ var CloakBrowserLaunch = {
|
|
|
5520
5409
|
const patchedBrowsers = /* @__PURE__ */ new WeakSet();
|
|
5521
5410
|
const defaultArgs = isRunningOnApify ? ["--no-sandbox", "--disable-setuid-sandbox"] : [];
|
|
5522
5411
|
const extraArgs = normalizeStringArray(normalizedCloakOptions.args);
|
|
5523
|
-
const proxy = hasOwn(normalizedCloakOptions, "proxy") ? normalizedCloakOptions.proxy :
|
|
5412
|
+
const proxy = hasOwn(normalizedCloakOptions, "proxy") ? normalizedCloakOptions.proxy : resolveCloakProxy(proxyConfiguration);
|
|
5524
5413
|
const headless = hasOwn(normalizedCloakOptions, "headless") ? normalizedCloakOptions.headless : !runInHeadfulMode || isRunningOnApify;
|
|
5525
5414
|
const mergedCloakOptions = {
|
|
5526
5415
|
...normalizedCloakOptions,
|
|
@@ -5543,7 +5432,7 @@ var CloakBrowserLaunch = {
|
|
|
5543
5432
|
...launcher ? { launcher } : {},
|
|
5544
5433
|
launchOptions
|
|
5545
5434
|
},
|
|
5546
|
-
browserPoolOptions:
|
|
5435
|
+
browserPoolOptions: attachCloakHumanizeHook({
|
|
5547
5436
|
browserPoolOptions,
|
|
5548
5437
|
activeBrowsers,
|
|
5549
5438
|
patchedBrowsers,
|
|
@@ -5577,11 +5466,9 @@ var CloakBrowserLaunch = {
|
|
|
5577
5466
|
// src/launch.js
|
|
5578
5467
|
var launchStrategies = {
|
|
5579
5468
|
[Mode.Default]: DefaultLaunch,
|
|
5580
|
-
[Mode.
|
|
5469
|
+
[Mode.Cloak]: CloakLaunch
|
|
5581
5470
|
};
|
|
5582
|
-
var Launch =
|
|
5583
|
-
"getPlaywrightCrawlerOptions"
|
|
5584
|
-
]);
|
|
5471
|
+
var Launch = withModeReflect("Launch", launchStrategies);
|
|
5585
5472
|
|
|
5586
5473
|
// src/live-view.js
|
|
5587
5474
|
var import_express = __toESM(require("express"), 1);
|
|
@@ -6670,7 +6557,7 @@ var Mutation = {
|
|
|
6670
6557
|
const overallTimeout = options.timeout ?? 180 * 1e3;
|
|
6671
6558
|
const onMutation = options.onMutation;
|
|
6672
6559
|
const pollInterval = 500;
|
|
6673
|
-
const
|
|
6560
|
+
const sleep = (ms) => new Promise((resolve) => {
|
|
6674
6561
|
setTimeout(resolve, ms);
|
|
6675
6562
|
});
|
|
6676
6563
|
const truncate = (value, max = 800) => {
|
|
@@ -6862,7 +6749,7 @@ var Mutation = {
|
|
|
6862
6749
|
const deadline = Date.now() + overallTimeout;
|
|
6863
6750
|
let lastState = state2;
|
|
6864
6751
|
while (Date.now() < deadline) {
|
|
6865
|
-
await
|
|
6752
|
+
await sleep(pollInterval);
|
|
6866
6753
|
lastState = await buildState();
|
|
6867
6754
|
if (!lastState?.hasMatched) {
|
|
6868
6755
|
continue;
|
|
@@ -8447,7 +8334,7 @@ var buildWatermarkifyRenderHtml = ({ imageSrc, overlaySvg, width, height, imageH
|
|
|
8447
8334
|
`;
|
|
8448
8335
|
};
|
|
8449
8336
|
var normalizeWatermarkifyRenderMode = (value) => {
|
|
8450
|
-
return String(value || "default").trim().toLowerCase() === "
|
|
8337
|
+
return String(value || "default").trim().toLowerCase() === "cloak" ? "cloak" : "default";
|
|
8451
8338
|
};
|
|
8452
8339
|
var composeScreenshotBufferWithBrowser = async (page, buffer, overlaySvg, imageInfo = {}, options = {}) => {
|
|
8453
8340
|
if (!page || typeof page.context !== "function") {
|
|
@@ -8474,7 +8361,7 @@ var composeScreenshotBufferWithBrowser = async (page, buffer, overlaySvg, imageI
|
|
|
8474
8361
|
}).catch(() => {
|
|
8475
8362
|
});
|
|
8476
8363
|
const renderMode = normalizeWatermarkifyRenderMode(options.mode);
|
|
8477
|
-
if (renderMode === "
|
|
8364
|
+
if (renderMode === "cloak") {
|
|
8478
8365
|
const renderHtml = buildWatermarkifyRenderHtml({
|
|
8479
8366
|
imageSrc: `data:${imageInfo.mimeType || "image/png"};base64,${buffer.toString("base64")}`,
|
|
8480
8367
|
overlaySvg,
|
|
@@ -10055,7 +9942,7 @@ var Share = {
|
|
|
10055
9942
|
* @param {number} [options.maxBytes] 默认 5MiB,返回 base64 超过后会压缩
|
|
10056
9943
|
* @param {'jpeg'|'jpg'} [options.type] 压缩输出格式,默认 jpeg
|
|
10057
9944
|
* @param {boolean|Object} [options.compression] 传 false 可关闭压缩
|
|
10058
|
-
* @param {'default'|'
|
|
9945
|
+
* @param {'default'|'cloak'} [options.mode] 截图水印合成模式,默认 default
|
|
10059
9946
|
* @returns {Promise<string>} base64 image
|
|
10060
9947
|
*/
|
|
10061
9948
|
async captureScreen(page, options = {}) {
|
|
@@ -10077,7 +9964,7 @@ var Share = {
|
|
|
10077
9964
|
capturedAt
|
|
10078
9965
|
});
|
|
10079
9966
|
outputBuffer = await watermarkifyScreenshotBuffer(rawBuffer, watermarkifyMeta, page, {
|
|
10080
|
-
mode: options.mode
|
|
9967
|
+
mode: options.mode
|
|
10081
9968
|
});
|
|
10082
9969
|
}
|
|
10083
9970
|
return await compressImageBufferToBase64(outputBuffer, compression);
|