@skrillex1224/playwright-toolkit 3.0.14 → 3.0.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/browser.d.ts +6 -0
- package/dist/browser.js +15 -5
- package/dist/browser.js.map +3 -3
- package/dist/index.cjs +44 -33
- package/dist/index.cjs.map +3 -3
- package/dist/index.js +44 -33
- package/dist/index.js.map +3 -3
- package/index.d.ts +10 -1
- package/package.json +3 -1
- package/scripts/postinstall.js +203 -0
package/dist/index.js
CHANGED
|
@@ -16,6 +16,7 @@ __export(constants_exports, {
|
|
|
16
16
|
Mode: () => Mode,
|
|
17
17
|
PresetOfLiveViewKey: () => PresetOfLiveViewKey,
|
|
18
18
|
Status: () => Status,
|
|
19
|
+
mode: () => mode,
|
|
19
20
|
normalizeDevice: () => normalizeDevice,
|
|
20
21
|
normalizeMode: () => normalizeMode
|
|
21
22
|
});
|
|
@@ -41,6 +42,10 @@ var Mode = Object.freeze({
|
|
|
41
42
|
Default: "default",
|
|
42
43
|
Cloak: "cloak"
|
|
43
44
|
});
|
|
45
|
+
var mode = Object.freeze({
|
|
46
|
+
default: Mode.Default,
|
|
47
|
+
cloak: Mode.Cloak
|
|
48
|
+
});
|
|
44
49
|
var normalizeDevice = (value, fallback = Device.Desktop) => {
|
|
45
50
|
const normalizedFallback = String(fallback || "").trim().toLowerCase() === Device.Mobile ? Device.Mobile : Device.Desktop;
|
|
46
51
|
const raw = String(value || "").trim().toLowerCase();
|
|
@@ -69,7 +74,7 @@ var createActorInfo = (info) => {
|
|
|
69
74
|
const normalizeShare2 = (value) => {
|
|
70
75
|
const raw = value && typeof value === "object" ? value : {};
|
|
71
76
|
const modeRaw = String(raw.mode || "dom").trim().toLowerCase();
|
|
72
|
-
const
|
|
77
|
+
const mode2 = ["dom", "response", "custom"].includes(modeRaw) ? modeRaw : "dom";
|
|
73
78
|
const prefix = String(raw.prefix || "").trim();
|
|
74
79
|
const rawXurl = Array.isArray(raw.xurl) ? raw.xurl : [];
|
|
75
80
|
const normalizeMatcherList = (input) => {
|
|
@@ -114,7 +119,7 @@ var createActorInfo = (info) => {
|
|
|
114
119
|
xurl.push(...extraPaths);
|
|
115
120
|
}
|
|
116
121
|
return {
|
|
117
|
-
mode,
|
|
122
|
+
mode: mode2,
|
|
118
123
|
prefix,
|
|
119
124
|
xurl
|
|
120
125
|
};
|
|
@@ -2494,16 +2499,16 @@ var ToolkitContext = {
|
|
|
2494
2499
|
get mode() {
|
|
2495
2500
|
return state.mode;
|
|
2496
2501
|
},
|
|
2497
|
-
setMode(
|
|
2498
|
-
state.mode = normalizeMode(
|
|
2502
|
+
setMode(mode2 = Mode.Default) {
|
|
2503
|
+
state.mode = normalizeMode(mode2, Mode.Default);
|
|
2499
2504
|
return state.mode;
|
|
2500
2505
|
}
|
|
2501
2506
|
};
|
|
2502
2507
|
var getToolkitMode = () => state.mode;
|
|
2503
|
-
var setToolkitMode = (
|
|
2504
|
-
var resolveModeStrategy = (strategies = {},
|
|
2508
|
+
var setToolkitMode = (mode2 = Mode.Default) => ToolkitContext.setMode(mode2);
|
|
2509
|
+
var resolveModeStrategy = (strategies = {}, mode2 = getToolkitMode(), fallbackMode = Mode.Default) => {
|
|
2505
2510
|
const normalizedStrategies = normalizeStrategies(strategies);
|
|
2506
|
-
const normalizedMode = normalizeMode(
|
|
2511
|
+
const normalizedMode = normalizeMode(mode2, fallbackMode);
|
|
2507
2512
|
const strategy = normalizedStrategies[normalizedMode] ?? normalizedStrategies[fallbackMode] ?? Object.values(normalizedStrategies).find(Boolean) ?? null;
|
|
2508
2513
|
return {
|
|
2509
2514
|
mode: normalizedMode,
|
|
@@ -2530,10 +2535,10 @@ var methodDescriptor = (namespace, name, resolveTarget) => ({
|
|
|
2530
2535
|
configurable: true,
|
|
2531
2536
|
writable: true,
|
|
2532
2537
|
value: (...args) => {
|
|
2533
|
-
const { mode, strategy } = resolveTarget(args);
|
|
2538
|
+
const { mode: mode2, strategy } = resolveTarget(args);
|
|
2534
2539
|
const method = strategy?.[name];
|
|
2535
2540
|
if (typeof method !== "function") {
|
|
2536
|
-
throw new Error(`${namespace}.${name} is not available in ${
|
|
2541
|
+
throw new Error(`${namespace}.${name} is not available in ${mode2} mode`);
|
|
2537
2542
|
}
|
|
2538
2543
|
return method.apply(strategy, args);
|
|
2539
2544
|
}
|
|
@@ -4779,6 +4784,7 @@ var Humanize2 = withModeReflect("Humanize", humanizeStrategies);
|
|
|
4779
4784
|
import { execFileSync } from "node:child_process";
|
|
4780
4785
|
import { FingerprintGenerator } from "fingerprint-generator";
|
|
4781
4786
|
import { FingerprintInjector } from "fingerprint-injector";
|
|
4787
|
+
import { chromium as defaultChromiumLauncher } from "playwright";
|
|
4782
4788
|
|
|
4783
4789
|
// src/proxy-bypass.js
|
|
4784
4790
|
import picomatch from "picomatch";
|
|
@@ -5184,13 +5190,14 @@ var DefaultLaunch = {
|
|
|
5184
5190
|
runtimeState = null
|
|
5185
5191
|
} = normalizedOptions;
|
|
5186
5192
|
const device = resolveRuntimeDevice(runtimeState);
|
|
5193
|
+
const effectiveLauncher = launcher || defaultChromiumLauncher;
|
|
5187
5194
|
const enableByPassLogger = Boolean(logOptions && logOptions.enable);
|
|
5188
5195
|
const traffic = resolveLaunchTraffic({ proxyConfiguration, debugMode });
|
|
5189
5196
|
const trafficHook = createLaunchTrafficHook({
|
|
5190
5197
|
...traffic,
|
|
5191
5198
|
enabled: enableByPassLogger
|
|
5192
5199
|
});
|
|
5193
|
-
const replayContext = buildReplayableBrowserProfile(runtimeState,
|
|
5200
|
+
const replayContext = buildReplayableBrowserProfile(runtimeState, effectiveLauncher);
|
|
5194
5201
|
const replayBrowserPoolOptions = buildReplayBrowserPoolOptions(replayContext.browserProfileCore);
|
|
5195
5202
|
const launchLocale = String(replayContext.browserProfileCore?.locale || DEFAULT_LOCALE).trim() || DEFAULT_LOCALE;
|
|
5196
5203
|
const launchOptions = {
|
|
@@ -5220,11 +5227,9 @@ var DefaultLaunch = {
|
|
|
5220
5227
|
};
|
|
5221
5228
|
const launchContext = {
|
|
5222
5229
|
useIncognitoPages: true,
|
|
5223
|
-
launchOptions
|
|
5230
|
+
launchOptions,
|
|
5231
|
+
launcher: effectiveLauncher
|
|
5224
5232
|
};
|
|
5225
|
-
if (launcher) {
|
|
5226
|
-
launchContext.launcher = launcher;
|
|
5227
|
-
}
|
|
5228
5233
|
const crawlerBaseOptions = {
|
|
5229
5234
|
...DEFAULT_CRAWLER_BASE_OPTIONS,
|
|
5230
5235
|
headless: !runInHeadfulMode || isRunningOnApify,
|
|
@@ -6882,8 +6887,8 @@ var Mutation = {
|
|
|
6882
6887
|
const selectorList = Array.isArray(selectors) ? selectors : [selectors];
|
|
6883
6888
|
const onMutation = options.onMutation;
|
|
6884
6889
|
const rawMode = String(options.mode || MUTATION_MONITOR_MODE.Added).toLowerCase();
|
|
6885
|
-
const
|
|
6886
|
-
logger13.start("useMonitor", `\u76D1\u63A7 ${selectorList.length} \u4E2A\u9009\u62E9\u5668, mode=${
|
|
6890
|
+
const mode2 = [MUTATION_MONITOR_MODE.Added, MUTATION_MONITOR_MODE.Changed, MUTATION_MONITOR_MODE.All].includes(rawMode) ? rawMode : MUTATION_MONITOR_MODE.Added;
|
|
6891
|
+
logger13.start("useMonitor", `\u76D1\u63A7 ${selectorList.length} \u4E2A\u9009\u62E9\u5668, mode=${mode2}`);
|
|
6887
6892
|
const monitorKey = generateKey("pk_mon");
|
|
6888
6893
|
const callbackName = generateKey("pk_mon_cb");
|
|
6889
6894
|
const cleanerName = generateKey("pk_mon_clean");
|
|
@@ -6898,7 +6903,7 @@ var Mutation = {
|
|
|
6898
6903
|
} catch (e) {
|
|
6899
6904
|
}
|
|
6900
6905
|
}
|
|
6901
|
-
await page.evaluate(({ selectorList: selectorList2, monitorKey: monitorKey2, callbackName: callbackName2, cleanerName: cleanerName2, hasCallback, mode:
|
|
6906
|
+
await page.evaluate(({ selectorList: selectorList2, monitorKey: monitorKey2, callbackName: callbackName2, cleanerName: cleanerName2, hasCallback, mode: mode3 }) => {
|
|
6902
6907
|
const monitor = {
|
|
6903
6908
|
observers: [],
|
|
6904
6909
|
totalMutations: 0,
|
|
@@ -6942,7 +6947,7 @@ var Mutation = {
|
|
|
6942
6947
|
const collectMutationNodes = (mutations) => {
|
|
6943
6948
|
const mutationNodes = [];
|
|
6944
6949
|
for (const mutation of mutations) {
|
|
6945
|
-
if (
|
|
6950
|
+
if (mode3 === "added") {
|
|
6946
6951
|
if (mutation.type !== "childList") continue;
|
|
6947
6952
|
const added = Array.from(mutation.addedNodes || []);
|
|
6948
6953
|
for (const node of added) {
|
|
@@ -6950,7 +6955,7 @@ var Mutation = {
|
|
|
6950
6955
|
}
|
|
6951
6956
|
continue;
|
|
6952
6957
|
}
|
|
6953
|
-
if (
|
|
6958
|
+
if (mode3 === "changed") {
|
|
6954
6959
|
if (mutation.type === "attributes" || mutation.type === "characterData") {
|
|
6955
6960
|
mutationNodes.push(serializeNode(mutation.target, mutation.type));
|
|
6956
6961
|
} else if (mutation.type === "childList") {
|
|
@@ -7010,8 +7015,8 @@ var Mutation = {
|
|
|
7010
7015
|
observer.observe(element, {
|
|
7011
7016
|
childList: true,
|
|
7012
7017
|
subtree: true,
|
|
7013
|
-
characterData:
|
|
7014
|
-
attributes:
|
|
7018
|
+
characterData: mode3 !== "added",
|
|
7019
|
+
attributes: mode3 !== "added"
|
|
7015
7020
|
});
|
|
7016
7021
|
monitor.observers.push(observer);
|
|
7017
7022
|
});
|
|
@@ -7025,7 +7030,7 @@ var Mutation = {
|
|
|
7025
7030
|
delete window[cleanerName2];
|
|
7026
7031
|
return total;
|
|
7027
7032
|
};
|
|
7028
|
-
}, { selectorList, monitorKey, callbackName, cleanerName, hasCallback: !!onMutation, mode });
|
|
7033
|
+
}, { selectorList, monitorKey, callbackName, cleanerName, hasCallback: !!onMutation, mode: mode2 });
|
|
7029
7034
|
logger13.success("useMonitor", "\u76D1\u63A7\u5668\u5DF2\u542F\u52A8");
|
|
7030
7035
|
return {
|
|
7031
7036
|
stop: async () => {
|
|
@@ -8420,7 +8425,7 @@ var buildWatermarkifyRenderHtml = ({ imageSrc, overlaySvg, width, height, imageH
|
|
|
8420
8425
|
`;
|
|
8421
8426
|
};
|
|
8422
8427
|
var normalizeWatermarkifyRenderMode = (value) => {
|
|
8423
|
-
return String(value ||
|
|
8428
|
+
return String(value || Mode.Default).trim().toLowerCase() === Mode.Cloak ? Mode.Cloak : Mode.Default;
|
|
8424
8429
|
};
|
|
8425
8430
|
var composeScreenshotBufferWithBrowser = async (page, buffer, overlaySvg, imageInfo = {}, options = {}) => {
|
|
8426
8431
|
if (!page || typeof page.context !== "function") {
|
|
@@ -8447,7 +8452,7 @@ var composeScreenshotBufferWithBrowser = async (page, buffer, overlaySvg, imageI
|
|
|
8447
8452
|
}).catch(() => {
|
|
8448
8453
|
});
|
|
8449
8454
|
const renderMode = normalizeWatermarkifyRenderMode(options.mode);
|
|
8450
|
-
if (renderMode ===
|
|
8455
|
+
if (renderMode === Mode.Cloak) {
|
|
8451
8456
|
const renderHtml = buildWatermarkifyRenderHtml({
|
|
8452
8457
|
imageSrc: `data:${imageInfo.mimeType || "image/png"};base64,${buffer.toString("base64")}`,
|
|
8453
8458
|
overlaySvg,
|
|
@@ -9643,9 +9648,9 @@ var normalizeXurl = (value) => {
|
|
|
9643
9648
|
var normalizeShare = (share) => {
|
|
9644
9649
|
const source = share && typeof share === "object" ? share : {};
|
|
9645
9650
|
const modeRaw = String(source.mode || "dom").trim().toLowerCase();
|
|
9646
|
-
const
|
|
9651
|
+
const mode2 = ["dom", "response", "custom"].includes(modeRaw) ? modeRaw : "dom";
|
|
9647
9652
|
return {
|
|
9648
|
-
mode,
|
|
9653
|
+
mode: mode2,
|
|
9649
9654
|
prefix: normalizePrefix(source.prefix),
|
|
9650
9655
|
xurl: normalizeXurl(source.xurl)
|
|
9651
9656
|
};
|
|
@@ -9706,13 +9711,13 @@ var parseJsonSafely = (text) => {
|
|
|
9706
9711
|
var createDomShareMonitor = async (page, options = {}) => {
|
|
9707
9712
|
const prefix = normalizePrefix(options.prefix);
|
|
9708
9713
|
const selectors = options.selectors ?? "html";
|
|
9709
|
-
const
|
|
9714
|
+
const mode2 = options.mode ?? Mutation.Mode.All;
|
|
9710
9715
|
const onMatch = typeof options.onMatch === "function" ? options.onMatch : null;
|
|
9711
9716
|
const onTelemetry = typeof options.onTelemetry === "function" ? options.onTelemetry : null;
|
|
9712
9717
|
let matched = false;
|
|
9713
|
-
logger16.info(`DOM \u76D1\u542C\u51C6\u5907\u6302\u8F7D: selectors=${toJsonInline(selectors, 120)}, mode=${
|
|
9718
|
+
logger16.info(`DOM \u76D1\u542C\u51C6\u5907\u6302\u8F7D: selectors=${toJsonInline(selectors, 120)}, mode=${mode2}`);
|
|
9714
9719
|
const monitor = await Mutation.useMonitor(page, selectors, {
|
|
9715
|
-
mode,
|
|
9720
|
+
mode: mode2,
|
|
9716
9721
|
onMutation: (context = {}) => {
|
|
9717
9722
|
if (matched) return;
|
|
9718
9723
|
const mutationCount = Number(context.mutationCount || 0);
|
|
@@ -10028,13 +10033,14 @@ var Share = {
|
|
|
10028
10033
|
* @param {number} [options.maxBytes] 默认 5MiB,返回 base64 超过后会压缩
|
|
10029
10034
|
* @param {'jpeg'|'jpg'} [options.type] 压缩输出格式,默认 jpeg
|
|
10030
10035
|
* @param {boolean|Object} [options.compression] 传 false 可关闭压缩
|
|
10031
|
-
* @param {'default'|'cloak'} [options.mode]
|
|
10036
|
+
* @param {'default'|'cloak'} [options.mode] 截图水印合成模式,默认取当前 toolkit mode
|
|
10032
10037
|
* @returns {Promise<string>} base64 image
|
|
10033
10038
|
*/
|
|
10034
10039
|
async captureScreen(page, options = {}) {
|
|
10035
10040
|
const restore = options.restore ?? false;
|
|
10036
10041
|
const screenshotWatermarkify = resolveCaptureScreenWatermarkify(page, options.watermarkify);
|
|
10037
10042
|
const compression = resolveImageCompression(options);
|
|
10043
|
+
const screenshotMode = options.mode ?? getToolkitMode();
|
|
10038
10044
|
const captureOptions = {
|
|
10039
10045
|
restore,
|
|
10040
10046
|
maxHeight: options.maxHeight,
|
|
@@ -10050,7 +10056,7 @@ var Share = {
|
|
|
10050
10056
|
capturedAt
|
|
10051
10057
|
});
|
|
10052
10058
|
outputBuffer = await watermarkifyScreenshotBuffer(rawBuffer, watermarkifyMeta, page, {
|
|
10053
|
-
mode:
|
|
10059
|
+
mode: screenshotMode
|
|
10054
10060
|
});
|
|
10055
10061
|
}
|
|
10056
10062
|
return await compressImageBufferToBase64(outputBuffer, compression);
|
|
@@ -10059,8 +10065,12 @@ var Share = {
|
|
|
10059
10065
|
|
|
10060
10066
|
// entrys/node.js
|
|
10061
10067
|
Logger.setLogger(crawleeLog);
|
|
10062
|
-
var
|
|
10063
|
-
|
|
10068
|
+
var ToolkitMode = Object.freeze({
|
|
10069
|
+
default: Mode.Default,
|
|
10070
|
+
cloak: Mode.Cloak
|
|
10071
|
+
});
|
|
10072
|
+
var usePlaywrightToolKit = (mode2 = Mode.Default) => {
|
|
10073
|
+
setToolkitMode(mode2);
|
|
10064
10074
|
const toolkit = {
|
|
10065
10075
|
ApifyKit,
|
|
10066
10076
|
AntiCheat,
|
|
@@ -10083,6 +10093,7 @@ var usePlaywrightToolKit = (mode = "default") => {
|
|
|
10083
10093
|
};
|
|
10084
10094
|
return toolkit;
|
|
10085
10095
|
};
|
|
10096
|
+
usePlaywrightToolKit.Mode = ToolkitMode;
|
|
10086
10097
|
export {
|
|
10087
10098
|
usePlaywrightToolKit
|
|
10088
10099
|
};
|