@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.js
CHANGED
|
@@ -39,7 +39,7 @@ var Device = Object.freeze({
|
|
|
39
39
|
});
|
|
40
40
|
var Mode = Object.freeze({
|
|
41
41
|
Default: "default",
|
|
42
|
-
|
|
42
|
+
Cloak: "cloak"
|
|
43
43
|
});
|
|
44
44
|
var normalizeDevice = (value, fallback = Device.Desktop) => {
|
|
45
45
|
const normalizedFallback = String(fallback || "").trim().toLowerCase() === Device.Mobile ? Device.Mobile : Device.Desktop;
|
|
@@ -49,9 +49,9 @@ var normalizeDevice = (value, fallback = Device.Desktop) => {
|
|
|
49
49
|
return normalizedFallback;
|
|
50
50
|
};
|
|
51
51
|
var normalizeMode = (value, fallback = Mode.Default) => {
|
|
52
|
-
const normalizedFallback = String(fallback || "").trim().toLowerCase() === Mode.
|
|
52
|
+
const normalizedFallback = String(fallback || "").trim().toLowerCase() === Mode.Cloak ? Mode.Cloak : Mode.Default;
|
|
53
53
|
const raw = String(value || "").trim().toLowerCase();
|
|
54
|
-
if (raw === Mode.
|
|
54
|
+
if (raw === Mode.Cloak) return Mode.Cloak;
|
|
55
55
|
if (raw === Mode.Default) return Mode.Default;
|
|
56
56
|
return normalizedFallback;
|
|
57
57
|
};
|
|
@@ -2481,35 +2481,59 @@ var setToolkitMode = (mode = Mode.Default) => ToolkitContext.setMode(mode);
|
|
|
2481
2481
|
var resolveModeStrategy = (strategies = {}, mode = getToolkitMode(), fallbackMode = Mode.Default) => {
|
|
2482
2482
|
const normalizedStrategies = normalizeStrategies(strategies);
|
|
2483
2483
|
const normalizedMode = normalizeMode(mode, fallbackMode);
|
|
2484
|
-
const
|
|
2484
|
+
const strategy = normalizedStrategies[normalizedMode] ?? normalizedStrategies[fallbackMode] ?? Object.values(normalizedStrategies).find(Boolean) ?? null;
|
|
2485
2485
|
return {
|
|
2486
2486
|
mode: normalizedMode,
|
|
2487
|
-
|
|
2487
|
+
strategy
|
|
2488
2488
|
};
|
|
2489
2489
|
};
|
|
2490
2490
|
|
|
2491
|
-
// src/internals/
|
|
2492
|
-
var
|
|
2493
|
-
|
|
2494
|
-
|
|
2491
|
+
// src/internals/reflect.js
|
|
2492
|
+
var normalizeStrategies2 = (strategies) => strategies && typeof strategies === "object" ? strategies : {};
|
|
2493
|
+
var collectFunctionNames = (strategies = []) => {
|
|
2494
|
+
const names = /* @__PURE__ */ new Set();
|
|
2495
|
+
for (const strategy of strategies) {
|
|
2496
|
+
if (!strategy || typeof strategy !== "object") continue;
|
|
2497
|
+
for (const name of Reflect.ownKeys(strategy)) {
|
|
2498
|
+
if (typeof name === "string" && typeof strategy[name] === "function") {
|
|
2499
|
+
names.add(name);
|
|
2500
|
+
}
|
|
2501
|
+
}
|
|
2502
|
+
}
|
|
2503
|
+
return names;
|
|
2495
2504
|
};
|
|
2496
|
-
var
|
|
2497
|
-
enumerable,
|
|
2505
|
+
var methodDescriptor = (namespace, name, resolveTarget) => ({
|
|
2506
|
+
enumerable: true,
|
|
2507
|
+
configurable: true,
|
|
2508
|
+
writable: true,
|
|
2498
2509
|
value: (...args) => {
|
|
2499
|
-
const { mode,
|
|
2500
|
-
|
|
2501
|
-
|
|
2510
|
+
const { mode, strategy } = resolveTarget(args);
|
|
2511
|
+
const method = strategy?.[name];
|
|
2512
|
+
if (typeof method !== "function") {
|
|
2513
|
+
throw new Error(`${namespace}.${name} is not available in ${mode} mode`);
|
|
2502
2514
|
}
|
|
2503
|
-
return
|
|
2515
|
+
return method.apply(strategy, args);
|
|
2504
2516
|
}
|
|
2505
2517
|
});
|
|
2506
|
-
var
|
|
2507
|
-
const
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2518
|
+
var withModeReflect = (namespace, strategies = {}) => {
|
|
2519
|
+
const normalizedStrategies = normalizeStrategies2(strategies);
|
|
2520
|
+
const baseStrategy = normalizedStrategies.default ?? Object.values(normalizedStrategies).find(Boolean);
|
|
2521
|
+
const names = collectFunctionNames([baseStrategy]);
|
|
2522
|
+
const descriptors = {};
|
|
2523
|
+
for (const name of names) {
|
|
2524
|
+
descriptors[name] = methodDescriptor(namespace, name, () => resolveModeStrategy(normalizedStrategies));
|
|
2525
|
+
}
|
|
2526
|
+
return Object.defineProperties({}, descriptors);
|
|
2527
|
+
};
|
|
2528
|
+
var withPageReflect = (namespace, resolveStrategy, strategies = []) => {
|
|
2529
|
+
const names = collectFunctionNames(strategies);
|
|
2530
|
+
const descriptors = {};
|
|
2531
|
+
for (const name of names) {
|
|
2532
|
+
descriptors[name] = methodDescriptor(namespace, name, ([page]) => ({
|
|
2533
|
+
mode: "page",
|
|
2534
|
+
strategy: resolveStrategy(page)
|
|
2535
|
+
}));
|
|
2536
|
+
}
|
|
2513
2537
|
return Object.defineProperties({}, descriptors);
|
|
2514
2538
|
};
|
|
2515
2539
|
|
|
@@ -2585,8 +2609,8 @@ var DefaultAntiCheat = {
|
|
|
2585
2609
|
}
|
|
2586
2610
|
};
|
|
2587
2611
|
|
|
2588
|
-
// src/internals/anti-cheat/
|
|
2589
|
-
var
|
|
2612
|
+
// src/internals/anti-cheat/cloak.js
|
|
2613
|
+
var CLOAK_BASE_CONFIG = Object.freeze({
|
|
2590
2614
|
locale: "",
|
|
2591
2615
|
acceptLanguage: "",
|
|
2592
2616
|
timezoneId: "",
|
|
@@ -2594,12 +2618,12 @@ var CLOAK_BROWSER_BASE_CONFIG = Object.freeze({
|
|
|
2594
2618
|
geolocation: null
|
|
2595
2619
|
});
|
|
2596
2620
|
var normalizeHeaders = (headers) => headers && typeof headers === "object" ? headers : {};
|
|
2597
|
-
var
|
|
2621
|
+
var CloakAntiCheat = {
|
|
2598
2622
|
/**
|
|
2599
|
-
*
|
|
2623
|
+
* Cloak 自身会负责浏览器指纹,toolkit 在该模式下尽量不再注入额外反检测配置。
|
|
2600
2624
|
*/
|
|
2601
2625
|
getBaseConfig() {
|
|
2602
|
-
return { ...
|
|
2626
|
+
return { ...CLOAK_BASE_CONFIG };
|
|
2603
2627
|
},
|
|
2604
2628
|
getFingerprintGeneratorOptions() {
|
|
2605
2629
|
return {};
|
|
@@ -2622,15 +2646,9 @@ var CloakBrowserAntiCheat = {
|
|
|
2622
2646
|
// src/anti-cheat.js
|
|
2623
2647
|
var antiCheatStrategies = {
|
|
2624
2648
|
[Mode.Default]: DefaultAntiCheat,
|
|
2625
|
-
[Mode.
|
|
2626
|
-
};
|
|
2627
|
-
var AntiCheat =
|
|
2628
|
-
"getBaseConfig",
|
|
2629
|
-
"getFingerprintGeneratorOptions",
|
|
2630
|
-
"getLaunchArgs",
|
|
2631
|
-
"getTlsFingerprintOptions",
|
|
2632
|
-
"applyLocaleHeaders"
|
|
2633
|
-
]);
|
|
2649
|
+
[Mode.Cloak]: CloakAntiCheat
|
|
2650
|
+
};
|
|
2651
|
+
var AntiCheat = withModeReflect("AntiCheat", antiCheatStrategies);
|
|
2634
2652
|
|
|
2635
2653
|
// src/device-input.js
|
|
2636
2654
|
var resolveDeviceFromPage = (page) => normalizeDevice(page?.[PageRuntimeStateKey]?.device);
|
|
@@ -3182,6 +3200,9 @@ var DeviceView = {
|
|
|
3182
3200
|
}
|
|
3183
3201
|
};
|
|
3184
3202
|
|
|
3203
|
+
// src/internals/humanize/index.js
|
|
3204
|
+
import delay4 from "delay";
|
|
3205
|
+
|
|
3185
3206
|
// src/internals/humanize/desktop.js
|
|
3186
3207
|
import delay2 from "delay";
|
|
3187
3208
|
import { createCursor } from "ghost-cursor-playwright";
|
|
@@ -4651,217 +4672,85 @@ var resolveDeviceFromPage2 = (page) => normalizeDevice(page?.[PageRuntimeStateKe
|
|
|
4651
4672
|
var resolveDelegate = (page) => {
|
|
4652
4673
|
return resolveDeviceFromPage2(page) === Device.Mobile ? MobileHumanize : Humanize;
|
|
4653
4674
|
};
|
|
4654
|
-
var
|
|
4655
|
-
|
|
4656
|
-
|
|
4657
|
-
|
|
4658
|
-
|
|
4659
|
-
jitterMs(base, jitterPercent = 0.3) {
|
|
4660
|
-
return Humanize.jitterMs(base, jitterPercent);
|
|
4661
|
-
},
|
|
4662
|
-
initializeCursor(page) {
|
|
4663
|
-
return callDelegate("initializeCursor", page, []);
|
|
4664
|
-
},
|
|
4665
|
-
humanMove(page, target) {
|
|
4666
|
-
return callDelegate("humanMove", page, [target]);
|
|
4667
|
-
},
|
|
4668
|
-
humanScroll(page, target, options = {}) {
|
|
4669
|
-
return callDelegate("humanScroll", page, [target, options]);
|
|
4670
|
-
},
|
|
4671
|
-
humanClick(page, target, options = {}) {
|
|
4672
|
-
return callDelegate("humanClick", page, [target, options]);
|
|
4673
|
-
},
|
|
4674
|
-
randomSleep(pageOrBaseMs, maybeBaseMs, maybeJitterPercent) {
|
|
4675
|
-
if (pageOrBaseMs && typeof pageOrBaseMs === "object" && typeof pageOrBaseMs.evaluate === "function") {
|
|
4676
|
-
const delegate = resolveDelegate(pageOrBaseMs);
|
|
4677
|
-
return delegate.randomSleep(maybeBaseMs, maybeJitterPercent);
|
|
4678
|
-
}
|
|
4679
|
-
return Humanize.randomSleep(pageOrBaseMs, maybeBaseMs);
|
|
4680
|
-
},
|
|
4681
|
-
simulateGaze(page, baseDurationMs = 2500) {
|
|
4682
|
-
return callDelegate("simulateGaze", page, [baseDurationMs]);
|
|
4683
|
-
},
|
|
4684
|
-
humanType(page, selector, text, options = {}) {
|
|
4685
|
-
return callDelegate("humanType", page, [selector, text, options]);
|
|
4686
|
-
},
|
|
4687
|
-
humanPress(page, targetOrKey, maybeKey, options = {}) {
|
|
4688
|
-
if (typeof maybeKey === "string") {
|
|
4689
|
-
return callDelegate("humanPress", page, [targetOrKey, maybeKey, options]);
|
|
4690
|
-
}
|
|
4691
|
-
return callDelegate("humanPress", page, [targetOrKey, maybeKey || options]);
|
|
4692
|
-
},
|
|
4693
|
-
humanClear(page, selector) {
|
|
4694
|
-
return callDelegate("humanClear", page, [selector]);
|
|
4695
|
-
},
|
|
4696
|
-
warmUpBrowsing(page, baseDuration = 3500) {
|
|
4697
|
-
return callDelegate("warmUpBrowsing", page, [baseDuration]);
|
|
4698
|
-
},
|
|
4699
|
-
naturalScroll(page, direction = "down", distance = 300, baseSteps = 5) {
|
|
4700
|
-
return callDelegate("naturalScroll", page, [direction, distance, baseSteps]);
|
|
4701
|
-
}
|
|
4702
|
-
};
|
|
4675
|
+
var DefaultHumanizeDevice = withPageReflect(
|
|
4676
|
+
"DefaultHumanize",
|
|
4677
|
+
resolveDelegate,
|
|
4678
|
+
[Humanize, MobileHumanize]
|
|
4679
|
+
);
|
|
4703
4680
|
|
|
4704
|
-
// src/internals/humanize/
|
|
4705
|
-
|
|
4706
|
-
|
|
4707
|
-
|
|
4708
|
-
|
|
4709
|
-
var
|
|
4710
|
-
|
|
4711
|
-
|
|
4712
|
-
|
|
4713
|
-
|
|
4714
|
-
|
|
4715
|
-
return jitterMs(base, jitterPercent);
|
|
4716
|
-
},
|
|
4681
|
+
// src/internals/humanize/cloak.js
|
|
4682
|
+
var FORCE_CLICK = Object.freeze({
|
|
4683
|
+
forceClick: true,
|
|
4684
|
+
clickOptions: { force: true }
|
|
4685
|
+
});
|
|
4686
|
+
var pointOrNull = async (target) => {
|
|
4687
|
+
if (!target || typeof target.boundingBox !== "function") return null;
|
|
4688
|
+
const box = await target.boundingBox().catch(() => null);
|
|
4689
|
+
return box ? { x: box.x + box.width / 2, y: box.y + box.height / 2 } : null;
|
|
4690
|
+
};
|
|
4691
|
+
var CloakHumanizeInput = {
|
|
4717
4692
|
async initializeCursor(page) {
|
|
4718
4693
|
return Boolean(page);
|
|
4719
4694
|
},
|
|
4720
4695
|
async humanMove(page, target) {
|
|
4721
|
-
|
|
4722
|
-
|
|
4723
|
-
await page.mouse.move(Number(target.x), Number(target.y));
|
|
4724
|
-
return true;
|
|
4725
|
-
}
|
|
4726
|
-
await resolveTarget(page, target).hover(FORCE_OPTIONS);
|
|
4727
|
-
return true;
|
|
4696
|
+
const point = target?.x != null && target?.y != null ? target : await pointOrNull(typeof target === "string" ? page.locator(target).first() : target);
|
|
4697
|
+
return point ? await DeviceInput.move(page, point, { forceMouse: true }) : false;
|
|
4728
4698
|
},
|
|
4729
4699
|
async humanScroll(page, target) {
|
|
4730
|
-
const element =
|
|
4700
|
+
const element = typeof target === "string" ? page.locator(target).first() : target;
|
|
4731
4701
|
if (!element) return { element: null, didScroll: false, restore: null };
|
|
4732
4702
|
await element.scrollIntoViewIfNeeded?.();
|
|
4733
4703
|
return { element, didScroll: true, restore: null };
|
|
4734
4704
|
},
|
|
4735
4705
|
async humanClick(page, target) {
|
|
4736
|
-
|
|
4737
|
-
await page.mouse.click(0, 0);
|
|
4738
|
-
return true;
|
|
4739
|
-
}
|
|
4740
|
-
if (isPoint2(target)) {
|
|
4741
|
-
await page.mouse.click(Number(target.x), Number(target.y));
|
|
4742
|
-
return true;
|
|
4743
|
-
}
|
|
4744
|
-
if (typeof target === "string") {
|
|
4745
|
-
await page.click(target, FORCE_OPTIONS);
|
|
4746
|
-
return true;
|
|
4747
|
-
}
|
|
4748
|
-
await target.click(FORCE_OPTIONS);
|
|
4749
|
-
return true;
|
|
4750
|
-
},
|
|
4751
|
-
async randomSleep(baseMs, jitterPercent = 0.3) {
|
|
4752
|
-
await sleep(baseMs, jitterPercent);
|
|
4753
|
-
},
|
|
4754
|
-
async simulateGaze(page, baseDurationMs = 2500) {
|
|
4755
|
-
const durationMs = jitterMs(baseDurationMs, 0.4);
|
|
4756
|
-
const startedAt = Date.now();
|
|
4757
|
-
const viewport = page.viewportSize() || { width: 1365, height: 900 };
|
|
4758
|
-
while (Date.now() - startedAt < durationMs) {
|
|
4759
|
-
await page.mouse.move(
|
|
4760
|
-
100 + Math.random() * Math.max(120, viewport.width - 200),
|
|
4761
|
-
100 + Math.random() * Math.max(120, viewport.height - 200)
|
|
4762
|
-
);
|
|
4763
|
-
await sleep(300, 0.5);
|
|
4764
|
-
}
|
|
4706
|
+
return await DeviceInput.click(page, target, FORCE_CLICK);
|
|
4765
4707
|
},
|
|
4766
4708
|
async humanType(page, selector, text) {
|
|
4767
|
-
|
|
4768
|
-
await
|
|
4769
|
-
await page.keyboard.type(text);
|
|
4709
|
+
await DeviceInput.click(page, selector, FORCE_CLICK);
|
|
4710
|
+
return await DeviceInput.keyboardType(page, text);
|
|
4770
4711
|
},
|
|
4771
4712
|
async humanPress(page, targetOrKey, maybeKey) {
|
|
4772
|
-
|
|
4773
|
-
|
|
4774
|
-
|
|
4775
|
-
}
|
|
4776
|
-
await resolveTarget(page, targetOrKey).click(FORCE_OPTIONS);
|
|
4777
|
-
await page.keyboard.press(maybeKey);
|
|
4778
|
-
return true;
|
|
4713
|
+
return await DeviceInput.press(page, targetOrKey, maybeKey, {
|
|
4714
|
+
clickOptions: FORCE_CLICK,
|
|
4715
|
+
keyboardOptions: {}
|
|
4716
|
+
});
|
|
4779
4717
|
},
|
|
4780
4718
|
async humanClear(page, selector) {
|
|
4781
|
-
|
|
4782
|
-
await page.fill(selector, "", FORCE_OPTIONS);
|
|
4783
|
-
return;
|
|
4784
|
-
}
|
|
4785
|
-
await selector.fill("", FORCE_OPTIONS);
|
|
4719
|
+
return await DeviceInput.fill(page, selector, "", { force: true });
|
|
4786
4720
|
},
|
|
4787
|
-
async
|
|
4788
|
-
await
|
|
4721
|
+
async simulateGaze(page) {
|
|
4722
|
+
return await DeviceInput.move(page, { x: 0, y: 0 }, { forceMouse: true });
|
|
4789
4723
|
},
|
|
4790
|
-
async
|
|
4791
|
-
|
|
4792
|
-
|
|
4793
|
-
|
|
4794
|
-
|
|
4795
|
-
|
|
4796
|
-
}
|
|
4724
|
+
async warmUpBrowsing(page) {
|
|
4725
|
+
return await this.simulateGaze(page);
|
|
4726
|
+
},
|
|
4727
|
+
async naturalScroll(page, direction = "down", distance = 300) {
|
|
4728
|
+
const sign = direction === "down" ? 1 : -1;
|
|
4729
|
+
await page.mouse.wheel(0, Number(distance || 0) * sign);
|
|
4797
4730
|
}
|
|
4798
4731
|
};
|
|
4799
|
-
|
|
4800
|
-
|
|
4801
|
-
var
|
|
4732
|
+
|
|
4733
|
+
// src/internals/humanize/index.js
|
|
4734
|
+
var HumanizeCommon = {
|
|
4802
4735
|
jitterMs(base, jitterPercent = 0.3) {
|
|
4803
4736
|
return jitterMs(base, jitterPercent);
|
|
4804
4737
|
},
|
|
4805
|
-
|
|
4806
|
-
|
|
4807
|
-
|
|
4808
|
-
|
|
4809
|
-
|
|
4810
|
-
},
|
|
4811
|
-
humanScroll(page, target, options = {}) {
|
|
4812
|
-
return callDelegate2("humanScroll", page, [target, options]);
|
|
4813
|
-
},
|
|
4814
|
-
humanClick(page, target, options = {}) {
|
|
4815
|
-
return callDelegate2("humanClick", page, [target, options]);
|
|
4816
|
-
},
|
|
4817
|
-
randomSleep(pageOrBaseMs, maybeBaseMs, maybeJitterPercent) {
|
|
4818
|
-
if (isPageLike2(pageOrBaseMs)) {
|
|
4819
|
-
return resolveDelegate2(pageOrBaseMs).randomSleep(maybeBaseMs, maybeJitterPercent);
|
|
4820
|
-
}
|
|
4821
|
-
return DesktopCloakHumanize.randomSleep(pageOrBaseMs, maybeBaseMs);
|
|
4822
|
-
},
|
|
4823
|
-
simulateGaze(page, baseDurationMs = 2500) {
|
|
4824
|
-
return callDelegate2("simulateGaze", page, [baseDurationMs]);
|
|
4825
|
-
},
|
|
4826
|
-
humanType(page, selector, text, options = {}) {
|
|
4827
|
-
return callDelegate2("humanType", page, [selector, text, options]);
|
|
4828
|
-
},
|
|
4829
|
-
humanPress(page, targetOrKey, maybeKey, options = {}) {
|
|
4830
|
-
if (typeof maybeKey === "string") {
|
|
4831
|
-
return callDelegate2("humanPress", page, [targetOrKey, maybeKey, options]);
|
|
4832
|
-
}
|
|
4833
|
-
return callDelegate2("humanPress", page, [targetOrKey, maybeKey || options]);
|
|
4834
|
-
},
|
|
4835
|
-
humanClear(page, selector) {
|
|
4836
|
-
return callDelegate2("humanClear", page, [selector]);
|
|
4837
|
-
},
|
|
4838
|
-
warmUpBrowsing(page, baseDuration = 3500) {
|
|
4839
|
-
return callDelegate2("warmUpBrowsing", page, [baseDuration]);
|
|
4840
|
-
},
|
|
4841
|
-
naturalScroll(page, direction = "down", distance = 300, baseSteps = 5) {
|
|
4842
|
-
return callDelegate2("naturalScroll", page, [direction, distance, baseSteps]);
|
|
4738
|
+
async randomSleep(pageOrBaseMs, maybeBaseMs, maybeJitterPercent) {
|
|
4739
|
+
const hasPage = pageOrBaseMs && typeof pageOrBaseMs === "object" && typeof pageOrBaseMs.evaluate === "function";
|
|
4740
|
+
const baseMs = hasPage ? maybeBaseMs : pageOrBaseMs;
|
|
4741
|
+
const jitterPercent = hasPage ? maybeJitterPercent : maybeBaseMs;
|
|
4742
|
+
await delay4(jitterMs(baseMs, jitterPercent ?? 0.3));
|
|
4843
4743
|
}
|
|
4844
4744
|
};
|
|
4745
|
+
var DefaultHumanize = Object.assign({}, DefaultHumanizeDevice, HumanizeCommon);
|
|
4746
|
+
var CloakHumanize = Object.assign({}, CloakHumanizeInput, HumanizeCommon);
|
|
4845
4747
|
|
|
4846
4748
|
// src/humanize.js
|
|
4847
4749
|
var humanizeStrategies = {
|
|
4848
4750
|
[Mode.Default]: DefaultHumanize,
|
|
4849
|
-
[Mode.
|
|
4850
|
-
};
|
|
4851
|
-
var Humanize2 =
|
|
4852
|
-
"jitterMs",
|
|
4853
|
-
"initializeCursor",
|
|
4854
|
-
"humanMove",
|
|
4855
|
-
"humanScroll",
|
|
4856
|
-
"humanClick",
|
|
4857
|
-
"randomSleep",
|
|
4858
|
-
"simulateGaze",
|
|
4859
|
-
"humanType",
|
|
4860
|
-
"humanPress",
|
|
4861
|
-
"humanClear",
|
|
4862
|
-
"warmUpBrowsing",
|
|
4863
|
-
"naturalScroll"
|
|
4864
|
-
]);
|
|
4751
|
+
[Mode.Cloak]: CloakHumanize
|
|
4752
|
+
};
|
|
4753
|
+
var Humanize2 = withModeReflect("Humanize", humanizeStrategies);
|
|
4865
4754
|
|
|
4866
4755
|
// src/internals/launch/default.js
|
|
4867
4756
|
import { execFileSync } from "node:child_process";
|
|
@@ -5299,10 +5188,10 @@ var DefaultLaunch = {
|
|
|
5299
5188
|
}
|
|
5300
5189
|
};
|
|
5301
5190
|
|
|
5302
|
-
// src/internals/launch/
|
|
5191
|
+
// src/internals/launch/cloak.js
|
|
5303
5192
|
import { execFile } from "node:child_process";
|
|
5304
5193
|
import { promisify } from "node:util";
|
|
5305
|
-
var logger8 = createInternalLogger("
|
|
5194
|
+
var logger8 = createInternalLogger("Cloak");
|
|
5306
5195
|
var execFileAsync = promisify(execFile);
|
|
5307
5196
|
var DEFAULT_CLOAK_CRAWLER_BASE_OPTIONS = Object.freeze({
|
|
5308
5197
|
maxConcurrency: 1,
|
|
@@ -5316,21 +5205,21 @@ var DEFAULT_CLOAK_HUMANIZE_OPTIONS = Object.freeze({
|
|
|
5316
5205
|
var DEFAULT_CLOAK_GOTO_OPTIONS = Object.freeze({
|
|
5317
5206
|
waitUntil: "commit"
|
|
5318
5207
|
});
|
|
5319
|
-
var
|
|
5208
|
+
var cachedCloakModulePromise = null;
|
|
5320
5209
|
var hasOwn = (target, key) => Object.prototype.hasOwnProperty.call(target, key);
|
|
5321
|
-
var
|
|
5322
|
-
if (!
|
|
5323
|
-
|
|
5324
|
-
|
|
5325
|
-
throw new Error("
|
|
5210
|
+
var loadCloakModule = async () => {
|
|
5211
|
+
if (!cachedCloakModulePromise) {
|
|
5212
|
+
cachedCloakModulePromise = import("cloakbrowser").catch((error) => {
|
|
5213
|
+
cachedCloakModulePromise = null;
|
|
5214
|
+
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", {
|
|
5326
5215
|
cause: error
|
|
5327
5216
|
});
|
|
5328
5217
|
});
|
|
5329
5218
|
}
|
|
5330
|
-
return
|
|
5219
|
+
return cachedCloakModulePromise;
|
|
5331
5220
|
};
|
|
5332
5221
|
var buildCloakLaunchOptions = async (options = {}) => {
|
|
5333
|
-
const { buildLaunchOptions } = await
|
|
5222
|
+
const { buildLaunchOptions } = await loadCloakModule();
|
|
5334
5223
|
return await buildLaunchOptions(normalizeObject(options));
|
|
5335
5224
|
};
|
|
5336
5225
|
var normalizeObject = (value) => {
|
|
@@ -5345,7 +5234,7 @@ var normalizeStringArray = (value) => {
|
|
|
5345
5234
|
}
|
|
5346
5235
|
return value.map((item) => String(item || "").trim()).filter(Boolean);
|
|
5347
5236
|
};
|
|
5348
|
-
var
|
|
5237
|
+
var resolveCloakProxy = (proxyConfiguration = {}) => {
|
|
5349
5238
|
const config = normalizeObject(proxyConfiguration);
|
|
5350
5239
|
const proxyUrl = String(config.proxy_url || "").trim();
|
|
5351
5240
|
const enableProxy = typeof config.enable_proxy === "boolean" ? config.enable_proxy : proxyUrl !== "";
|
|
@@ -5379,7 +5268,7 @@ var createStableGotoHook = (recommendedGotoOptions = DEFAULT_CLOAK_GOTO_OPTIONS)
|
|
|
5379
5268
|
}
|
|
5380
5269
|
};
|
|
5381
5270
|
};
|
|
5382
|
-
var
|
|
5271
|
+
var attachCloakHumanizeHook = ({
|
|
5383
5272
|
browserPoolOptions = {},
|
|
5384
5273
|
activeBrowsers,
|
|
5385
5274
|
patchedBrowsers,
|
|
@@ -5410,7 +5299,7 @@ var attachCloakBrowserHumanizeHook = ({
|
|
|
5410
5299
|
if (!shouldHumanize || patchedBrowsers.has(browser)) {
|
|
5411
5300
|
return;
|
|
5412
5301
|
}
|
|
5413
|
-
const { humanizeBrowser } = await
|
|
5302
|
+
const { humanizeBrowser } = await loadCloakModule();
|
|
5414
5303
|
await humanizeBrowser(browser, normalizedHumanizeOptions);
|
|
5415
5304
|
patchedBrowsers.add(browser);
|
|
5416
5305
|
}
|
|
@@ -5438,12 +5327,12 @@ var forceTerminateBrowsersByFingerprintArg = async (fingerprintArg) => {
|
|
|
5438
5327
|
if (error?.code === 1 || error?.code === "ENOENT") {
|
|
5439
5328
|
return;
|
|
5440
5329
|
}
|
|
5441
|
-
logger8.info(`\u5F3A\u5236\u5173\u95ED
|
|
5330
|
+
logger8.info(`\u5F3A\u5236\u5173\u95ED Cloak \u8FDB\u7A0B\u5931\u8D25\uFF08\u5FFD\u7565\uFF09: ${error?.message || String(error)}`);
|
|
5442
5331
|
});
|
|
5443
5332
|
};
|
|
5444
|
-
var
|
|
5333
|
+
var CloakLaunch = {
|
|
5445
5334
|
resolveProxyConfiguration(proxyConfiguration = {}) {
|
|
5446
|
-
return
|
|
5335
|
+
return resolveCloakProxy(proxyConfiguration);
|
|
5447
5336
|
},
|
|
5448
5337
|
extractFingerprintArg(launchOptions = {}) {
|
|
5449
5338
|
return extractFingerprintArg(launchOptions);
|
|
@@ -5452,7 +5341,7 @@ var CloakBrowserLaunch = {
|
|
|
5452
5341
|
return createStableGotoHook(recommendedGotoOptions);
|
|
5453
5342
|
},
|
|
5454
5343
|
async getPlaywrightCrawlerOptions(options = {}) {
|
|
5455
|
-
const runtime2 = await
|
|
5344
|
+
const runtime2 = await CloakLaunch.createPlaywrightCrawlerRuntime(options);
|
|
5456
5345
|
return Object.defineProperties(runtime2.crawlerOptions, {
|
|
5457
5346
|
cleanup: {
|
|
5458
5347
|
enumerable: false,
|
|
@@ -5492,7 +5381,7 @@ var CloakBrowserLaunch = {
|
|
|
5492
5381
|
const patchedBrowsers = /* @__PURE__ */ new WeakSet();
|
|
5493
5382
|
const defaultArgs = isRunningOnApify ? ["--no-sandbox", "--disable-setuid-sandbox"] : [];
|
|
5494
5383
|
const extraArgs = normalizeStringArray(normalizedCloakOptions.args);
|
|
5495
|
-
const proxy = hasOwn(normalizedCloakOptions, "proxy") ? normalizedCloakOptions.proxy :
|
|
5384
|
+
const proxy = hasOwn(normalizedCloakOptions, "proxy") ? normalizedCloakOptions.proxy : resolveCloakProxy(proxyConfiguration);
|
|
5496
5385
|
const headless = hasOwn(normalizedCloakOptions, "headless") ? normalizedCloakOptions.headless : !runInHeadfulMode || isRunningOnApify;
|
|
5497
5386
|
const mergedCloakOptions = {
|
|
5498
5387
|
...normalizedCloakOptions,
|
|
@@ -5515,7 +5404,7 @@ var CloakBrowserLaunch = {
|
|
|
5515
5404
|
...launcher ? { launcher } : {},
|
|
5516
5405
|
launchOptions
|
|
5517
5406
|
},
|
|
5518
|
-
browserPoolOptions:
|
|
5407
|
+
browserPoolOptions: attachCloakHumanizeHook({
|
|
5519
5408
|
browserPoolOptions,
|
|
5520
5409
|
activeBrowsers,
|
|
5521
5410
|
patchedBrowsers,
|
|
@@ -5549,11 +5438,9 @@ var CloakBrowserLaunch = {
|
|
|
5549
5438
|
// src/launch.js
|
|
5550
5439
|
var launchStrategies = {
|
|
5551
5440
|
[Mode.Default]: DefaultLaunch,
|
|
5552
|
-
[Mode.
|
|
5441
|
+
[Mode.Cloak]: CloakLaunch
|
|
5553
5442
|
};
|
|
5554
|
-
var Launch =
|
|
5555
|
-
"getPlaywrightCrawlerOptions"
|
|
5556
|
-
]);
|
|
5443
|
+
var Launch = withModeReflect("Launch", launchStrategies);
|
|
5557
5444
|
|
|
5558
5445
|
// src/live-view.js
|
|
5559
5446
|
import express from "express";
|
|
@@ -6642,7 +6529,7 @@ var Mutation = {
|
|
|
6642
6529
|
const overallTimeout = options.timeout ?? 180 * 1e3;
|
|
6643
6530
|
const onMutation = options.onMutation;
|
|
6644
6531
|
const pollInterval = 500;
|
|
6645
|
-
const
|
|
6532
|
+
const sleep = (ms) => new Promise((resolve) => {
|
|
6646
6533
|
setTimeout(resolve, ms);
|
|
6647
6534
|
});
|
|
6648
6535
|
const truncate = (value, max = 800) => {
|
|
@@ -6834,7 +6721,7 @@ var Mutation = {
|
|
|
6834
6721
|
const deadline = Date.now() + overallTimeout;
|
|
6835
6722
|
let lastState = state2;
|
|
6836
6723
|
while (Date.now() < deadline) {
|
|
6837
|
-
await
|
|
6724
|
+
await sleep(pollInterval);
|
|
6838
6725
|
lastState = await buildState();
|
|
6839
6726
|
if (!lastState?.hasMatched) {
|
|
6840
6727
|
continue;
|
|
@@ -8419,7 +8306,7 @@ var buildWatermarkifyRenderHtml = ({ imageSrc, overlaySvg, width, height, imageH
|
|
|
8419
8306
|
`;
|
|
8420
8307
|
};
|
|
8421
8308
|
var normalizeWatermarkifyRenderMode = (value) => {
|
|
8422
|
-
return String(value || "default").trim().toLowerCase() === "
|
|
8309
|
+
return String(value || "default").trim().toLowerCase() === "cloak" ? "cloak" : "default";
|
|
8423
8310
|
};
|
|
8424
8311
|
var composeScreenshotBufferWithBrowser = async (page, buffer, overlaySvg, imageInfo = {}, options = {}) => {
|
|
8425
8312
|
if (!page || typeof page.context !== "function") {
|
|
@@ -8446,7 +8333,7 @@ var composeScreenshotBufferWithBrowser = async (page, buffer, overlaySvg, imageI
|
|
|
8446
8333
|
}).catch(() => {
|
|
8447
8334
|
});
|
|
8448
8335
|
const renderMode = normalizeWatermarkifyRenderMode(options.mode);
|
|
8449
|
-
if (renderMode === "
|
|
8336
|
+
if (renderMode === "cloak") {
|
|
8450
8337
|
const renderHtml = buildWatermarkifyRenderHtml({
|
|
8451
8338
|
imageSrc: `data:${imageInfo.mimeType || "image/png"};base64,${buffer.toString("base64")}`,
|
|
8452
8339
|
overlaySvg,
|
|
@@ -10027,7 +9914,7 @@ var Share = {
|
|
|
10027
9914
|
* @param {number} [options.maxBytes] 默认 5MiB,返回 base64 超过后会压缩
|
|
10028
9915
|
* @param {'jpeg'|'jpg'} [options.type] 压缩输出格式,默认 jpeg
|
|
10029
9916
|
* @param {boolean|Object} [options.compression] 传 false 可关闭压缩
|
|
10030
|
-
* @param {'default'|'
|
|
9917
|
+
* @param {'default'|'cloak'} [options.mode] 截图水印合成模式,默认 default
|
|
10031
9918
|
* @returns {Promise<string>} base64 image
|
|
10032
9919
|
*/
|
|
10033
9920
|
async captureScreen(page, options = {}) {
|
|
@@ -10049,7 +9936,7 @@ var Share = {
|
|
|
10049
9936
|
capturedAt
|
|
10050
9937
|
});
|
|
10051
9938
|
outputBuffer = await watermarkifyScreenshotBuffer(rawBuffer, watermarkifyMeta, page, {
|
|
10052
|
-
mode: options.mode
|
|
9939
|
+
mode: options.mode
|
|
10053
9940
|
});
|
|
10054
9941
|
}
|
|
10055
9942
|
return await compressImageBufferToBase64(outputBuffer, compression);
|