@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.cjs
CHANGED
|
@@ -43,6 +43,7 @@ __export(constants_exports, {
|
|
|
43
43
|
Mode: () => Mode,
|
|
44
44
|
PresetOfLiveViewKey: () => PresetOfLiveViewKey,
|
|
45
45
|
Status: () => Status,
|
|
46
|
+
mode: () => mode,
|
|
46
47
|
normalizeDevice: () => normalizeDevice,
|
|
47
48
|
normalizeMode: () => normalizeMode
|
|
48
49
|
});
|
|
@@ -68,6 +69,10 @@ var Mode = Object.freeze({
|
|
|
68
69
|
Default: "default",
|
|
69
70
|
Cloak: "cloak"
|
|
70
71
|
});
|
|
72
|
+
var mode = Object.freeze({
|
|
73
|
+
default: Mode.Default,
|
|
74
|
+
cloak: Mode.Cloak
|
|
75
|
+
});
|
|
71
76
|
var normalizeDevice = (value, fallback = Device.Desktop) => {
|
|
72
77
|
const normalizedFallback = String(fallback || "").trim().toLowerCase() === Device.Mobile ? Device.Mobile : Device.Desktop;
|
|
73
78
|
const raw = String(value || "").trim().toLowerCase();
|
|
@@ -96,7 +101,7 @@ var createActorInfo = (info) => {
|
|
|
96
101
|
const normalizeShare2 = (value) => {
|
|
97
102
|
const raw = value && typeof value === "object" ? value : {};
|
|
98
103
|
const modeRaw = String(raw.mode || "dom").trim().toLowerCase();
|
|
99
|
-
const
|
|
104
|
+
const mode2 = ["dom", "response", "custom"].includes(modeRaw) ? modeRaw : "dom";
|
|
100
105
|
const prefix = String(raw.prefix || "").trim();
|
|
101
106
|
const rawXurl = Array.isArray(raw.xurl) ? raw.xurl : [];
|
|
102
107
|
const normalizeMatcherList = (input) => {
|
|
@@ -141,7 +146,7 @@ var createActorInfo = (info) => {
|
|
|
141
146
|
xurl.push(...extraPaths);
|
|
142
147
|
}
|
|
143
148
|
return {
|
|
144
|
-
mode,
|
|
149
|
+
mode: mode2,
|
|
145
150
|
prefix,
|
|
146
151
|
xurl
|
|
147
152
|
};
|
|
@@ -2522,16 +2527,16 @@ var ToolkitContext = {
|
|
|
2522
2527
|
get mode() {
|
|
2523
2528
|
return state.mode;
|
|
2524
2529
|
},
|
|
2525
|
-
setMode(
|
|
2526
|
-
state.mode = normalizeMode(
|
|
2530
|
+
setMode(mode2 = Mode.Default) {
|
|
2531
|
+
state.mode = normalizeMode(mode2, Mode.Default);
|
|
2527
2532
|
return state.mode;
|
|
2528
2533
|
}
|
|
2529
2534
|
};
|
|
2530
2535
|
var getToolkitMode = () => state.mode;
|
|
2531
|
-
var setToolkitMode = (
|
|
2532
|
-
var resolveModeStrategy = (strategies = {},
|
|
2536
|
+
var setToolkitMode = (mode2 = Mode.Default) => ToolkitContext.setMode(mode2);
|
|
2537
|
+
var resolveModeStrategy = (strategies = {}, mode2 = getToolkitMode(), fallbackMode = Mode.Default) => {
|
|
2533
2538
|
const normalizedStrategies = normalizeStrategies(strategies);
|
|
2534
|
-
const normalizedMode = normalizeMode(
|
|
2539
|
+
const normalizedMode = normalizeMode(mode2, fallbackMode);
|
|
2535
2540
|
const strategy = normalizedStrategies[normalizedMode] ?? normalizedStrategies[fallbackMode] ?? Object.values(normalizedStrategies).find(Boolean) ?? null;
|
|
2536
2541
|
return {
|
|
2537
2542
|
mode: normalizedMode,
|
|
@@ -2558,10 +2563,10 @@ var methodDescriptor = (namespace, name, resolveTarget) => ({
|
|
|
2558
2563
|
configurable: true,
|
|
2559
2564
|
writable: true,
|
|
2560
2565
|
value: (...args) => {
|
|
2561
|
-
const { mode, strategy } = resolveTarget(args);
|
|
2566
|
+
const { mode: mode2, strategy } = resolveTarget(args);
|
|
2562
2567
|
const method = strategy?.[name];
|
|
2563
2568
|
if (typeof method !== "function") {
|
|
2564
|
-
throw new Error(`${namespace}.${name} is not available in ${
|
|
2569
|
+
throw new Error(`${namespace}.${name} is not available in ${mode2} mode`);
|
|
2565
2570
|
}
|
|
2566
2571
|
return method.apply(strategy, args);
|
|
2567
2572
|
}
|
|
@@ -4807,6 +4812,7 @@ var Humanize2 = withModeReflect("Humanize", humanizeStrategies);
|
|
|
4807
4812
|
var import_node_child_process = require("node:child_process");
|
|
4808
4813
|
var import_fingerprint_generator = require("fingerprint-generator");
|
|
4809
4814
|
var import_fingerprint_injector = require("fingerprint-injector");
|
|
4815
|
+
var import_playwright2 = require("playwright");
|
|
4810
4816
|
|
|
4811
4817
|
// src/proxy-bypass.js
|
|
4812
4818
|
var import_picomatch = __toESM(require("picomatch"), 1);
|
|
@@ -5212,13 +5218,14 @@ var DefaultLaunch = {
|
|
|
5212
5218
|
runtimeState = null
|
|
5213
5219
|
} = normalizedOptions;
|
|
5214
5220
|
const device = resolveRuntimeDevice(runtimeState);
|
|
5221
|
+
const effectiveLauncher = launcher || import_playwright2.chromium;
|
|
5215
5222
|
const enableByPassLogger = Boolean(logOptions && logOptions.enable);
|
|
5216
5223
|
const traffic = resolveLaunchTraffic({ proxyConfiguration, debugMode });
|
|
5217
5224
|
const trafficHook = createLaunchTrafficHook({
|
|
5218
5225
|
...traffic,
|
|
5219
5226
|
enabled: enableByPassLogger
|
|
5220
5227
|
});
|
|
5221
|
-
const replayContext = buildReplayableBrowserProfile(runtimeState,
|
|
5228
|
+
const replayContext = buildReplayableBrowserProfile(runtimeState, effectiveLauncher);
|
|
5222
5229
|
const replayBrowserPoolOptions = buildReplayBrowserPoolOptions(replayContext.browserProfileCore);
|
|
5223
5230
|
const launchLocale = String(replayContext.browserProfileCore?.locale || DEFAULT_LOCALE).trim() || DEFAULT_LOCALE;
|
|
5224
5231
|
const launchOptions = {
|
|
@@ -5248,11 +5255,9 @@ var DefaultLaunch = {
|
|
|
5248
5255
|
};
|
|
5249
5256
|
const launchContext = {
|
|
5250
5257
|
useIncognitoPages: true,
|
|
5251
|
-
launchOptions
|
|
5258
|
+
launchOptions,
|
|
5259
|
+
launcher: effectiveLauncher
|
|
5252
5260
|
};
|
|
5253
|
-
if (launcher) {
|
|
5254
|
-
launchContext.launcher = launcher;
|
|
5255
|
-
}
|
|
5256
5261
|
const crawlerBaseOptions = {
|
|
5257
5262
|
...DEFAULT_CRAWLER_BASE_OPTIONS,
|
|
5258
5263
|
headless: !runInHeadfulMode || isRunningOnApify,
|
|
@@ -6910,8 +6915,8 @@ var Mutation = {
|
|
|
6910
6915
|
const selectorList = Array.isArray(selectors) ? selectors : [selectors];
|
|
6911
6916
|
const onMutation = options.onMutation;
|
|
6912
6917
|
const rawMode = String(options.mode || MUTATION_MONITOR_MODE.Added).toLowerCase();
|
|
6913
|
-
const
|
|
6914
|
-
logger13.start("useMonitor", `\u76D1\u63A7 ${selectorList.length} \u4E2A\u9009\u62E9\u5668, mode=${
|
|
6918
|
+
const mode2 = [MUTATION_MONITOR_MODE.Added, MUTATION_MONITOR_MODE.Changed, MUTATION_MONITOR_MODE.All].includes(rawMode) ? rawMode : MUTATION_MONITOR_MODE.Added;
|
|
6919
|
+
logger13.start("useMonitor", `\u76D1\u63A7 ${selectorList.length} \u4E2A\u9009\u62E9\u5668, mode=${mode2}`);
|
|
6915
6920
|
const monitorKey = generateKey("pk_mon");
|
|
6916
6921
|
const callbackName = generateKey("pk_mon_cb");
|
|
6917
6922
|
const cleanerName = generateKey("pk_mon_clean");
|
|
@@ -6926,7 +6931,7 @@ var Mutation = {
|
|
|
6926
6931
|
} catch (e) {
|
|
6927
6932
|
}
|
|
6928
6933
|
}
|
|
6929
|
-
await page.evaluate(({ selectorList: selectorList2, monitorKey: monitorKey2, callbackName: callbackName2, cleanerName: cleanerName2, hasCallback, mode:
|
|
6934
|
+
await page.evaluate(({ selectorList: selectorList2, monitorKey: monitorKey2, callbackName: callbackName2, cleanerName: cleanerName2, hasCallback, mode: mode3 }) => {
|
|
6930
6935
|
const monitor = {
|
|
6931
6936
|
observers: [],
|
|
6932
6937
|
totalMutations: 0,
|
|
@@ -6970,7 +6975,7 @@ var Mutation = {
|
|
|
6970
6975
|
const collectMutationNodes = (mutations) => {
|
|
6971
6976
|
const mutationNodes = [];
|
|
6972
6977
|
for (const mutation of mutations) {
|
|
6973
|
-
if (
|
|
6978
|
+
if (mode3 === "added") {
|
|
6974
6979
|
if (mutation.type !== "childList") continue;
|
|
6975
6980
|
const added = Array.from(mutation.addedNodes || []);
|
|
6976
6981
|
for (const node of added) {
|
|
@@ -6978,7 +6983,7 @@ var Mutation = {
|
|
|
6978
6983
|
}
|
|
6979
6984
|
continue;
|
|
6980
6985
|
}
|
|
6981
|
-
if (
|
|
6986
|
+
if (mode3 === "changed") {
|
|
6982
6987
|
if (mutation.type === "attributes" || mutation.type === "characterData") {
|
|
6983
6988
|
mutationNodes.push(serializeNode(mutation.target, mutation.type));
|
|
6984
6989
|
} else if (mutation.type === "childList") {
|
|
@@ -7038,8 +7043,8 @@ var Mutation = {
|
|
|
7038
7043
|
observer.observe(element, {
|
|
7039
7044
|
childList: true,
|
|
7040
7045
|
subtree: true,
|
|
7041
|
-
characterData:
|
|
7042
|
-
attributes:
|
|
7046
|
+
characterData: mode3 !== "added",
|
|
7047
|
+
attributes: mode3 !== "added"
|
|
7043
7048
|
});
|
|
7044
7049
|
monitor.observers.push(observer);
|
|
7045
7050
|
});
|
|
@@ -7053,7 +7058,7 @@ var Mutation = {
|
|
|
7053
7058
|
delete window[cleanerName2];
|
|
7054
7059
|
return total;
|
|
7055
7060
|
};
|
|
7056
|
-
}, { selectorList, monitorKey, callbackName, cleanerName, hasCallback: !!onMutation, mode });
|
|
7061
|
+
}, { selectorList, monitorKey, callbackName, cleanerName, hasCallback: !!onMutation, mode: mode2 });
|
|
7057
7062
|
logger13.success("useMonitor", "\u76D1\u63A7\u5668\u5DF2\u542F\u52A8");
|
|
7058
7063
|
return {
|
|
7059
7064
|
stop: async () => {
|
|
@@ -8448,7 +8453,7 @@ var buildWatermarkifyRenderHtml = ({ imageSrc, overlaySvg, width, height, imageH
|
|
|
8448
8453
|
`;
|
|
8449
8454
|
};
|
|
8450
8455
|
var normalizeWatermarkifyRenderMode = (value) => {
|
|
8451
|
-
return String(value ||
|
|
8456
|
+
return String(value || Mode.Default).trim().toLowerCase() === Mode.Cloak ? Mode.Cloak : Mode.Default;
|
|
8452
8457
|
};
|
|
8453
8458
|
var composeScreenshotBufferWithBrowser = async (page, buffer, overlaySvg, imageInfo = {}, options = {}) => {
|
|
8454
8459
|
if (!page || typeof page.context !== "function") {
|
|
@@ -8475,7 +8480,7 @@ var composeScreenshotBufferWithBrowser = async (page, buffer, overlaySvg, imageI
|
|
|
8475
8480
|
}).catch(() => {
|
|
8476
8481
|
});
|
|
8477
8482
|
const renderMode = normalizeWatermarkifyRenderMode(options.mode);
|
|
8478
|
-
if (renderMode ===
|
|
8483
|
+
if (renderMode === Mode.Cloak) {
|
|
8479
8484
|
const renderHtml = buildWatermarkifyRenderHtml({
|
|
8480
8485
|
imageSrc: `data:${imageInfo.mimeType || "image/png"};base64,${buffer.toString("base64")}`,
|
|
8481
8486
|
overlaySvg,
|
|
@@ -9671,9 +9676,9 @@ var normalizeXurl = (value) => {
|
|
|
9671
9676
|
var normalizeShare = (share) => {
|
|
9672
9677
|
const source = share && typeof share === "object" ? share : {};
|
|
9673
9678
|
const modeRaw = String(source.mode || "dom").trim().toLowerCase();
|
|
9674
|
-
const
|
|
9679
|
+
const mode2 = ["dom", "response", "custom"].includes(modeRaw) ? modeRaw : "dom";
|
|
9675
9680
|
return {
|
|
9676
|
-
mode,
|
|
9681
|
+
mode: mode2,
|
|
9677
9682
|
prefix: normalizePrefix(source.prefix),
|
|
9678
9683
|
xurl: normalizeXurl(source.xurl)
|
|
9679
9684
|
};
|
|
@@ -9734,13 +9739,13 @@ var parseJsonSafely = (text) => {
|
|
|
9734
9739
|
var createDomShareMonitor = async (page, options = {}) => {
|
|
9735
9740
|
const prefix = normalizePrefix(options.prefix);
|
|
9736
9741
|
const selectors = options.selectors ?? "html";
|
|
9737
|
-
const
|
|
9742
|
+
const mode2 = options.mode ?? Mutation.Mode.All;
|
|
9738
9743
|
const onMatch = typeof options.onMatch === "function" ? options.onMatch : null;
|
|
9739
9744
|
const onTelemetry = typeof options.onTelemetry === "function" ? options.onTelemetry : null;
|
|
9740
9745
|
let matched = false;
|
|
9741
|
-
logger16.info(`DOM \u76D1\u542C\u51C6\u5907\u6302\u8F7D: selectors=${toJsonInline(selectors, 120)}, mode=${
|
|
9746
|
+
logger16.info(`DOM \u76D1\u542C\u51C6\u5907\u6302\u8F7D: selectors=${toJsonInline(selectors, 120)}, mode=${mode2}`);
|
|
9742
9747
|
const monitor = await Mutation.useMonitor(page, selectors, {
|
|
9743
|
-
mode,
|
|
9748
|
+
mode: mode2,
|
|
9744
9749
|
onMutation: (context = {}) => {
|
|
9745
9750
|
if (matched) return;
|
|
9746
9751
|
const mutationCount = Number(context.mutationCount || 0);
|
|
@@ -10056,13 +10061,14 @@ var Share = {
|
|
|
10056
10061
|
* @param {number} [options.maxBytes] 默认 5MiB,返回 base64 超过后会压缩
|
|
10057
10062
|
* @param {'jpeg'|'jpg'} [options.type] 压缩输出格式,默认 jpeg
|
|
10058
10063
|
* @param {boolean|Object} [options.compression] 传 false 可关闭压缩
|
|
10059
|
-
* @param {'default'|'cloak'} [options.mode]
|
|
10064
|
+
* @param {'default'|'cloak'} [options.mode] 截图水印合成模式,默认取当前 toolkit mode
|
|
10060
10065
|
* @returns {Promise<string>} base64 image
|
|
10061
10066
|
*/
|
|
10062
10067
|
async captureScreen(page, options = {}) {
|
|
10063
10068
|
const restore = options.restore ?? false;
|
|
10064
10069
|
const screenshotWatermarkify = resolveCaptureScreenWatermarkify(page, options.watermarkify);
|
|
10065
10070
|
const compression = resolveImageCompression(options);
|
|
10071
|
+
const screenshotMode = options.mode ?? getToolkitMode();
|
|
10066
10072
|
const captureOptions = {
|
|
10067
10073
|
restore,
|
|
10068
10074
|
maxHeight: options.maxHeight,
|
|
@@ -10078,7 +10084,7 @@ var Share = {
|
|
|
10078
10084
|
capturedAt
|
|
10079
10085
|
});
|
|
10080
10086
|
outputBuffer = await watermarkifyScreenshotBuffer(rawBuffer, watermarkifyMeta, page, {
|
|
10081
|
-
mode:
|
|
10087
|
+
mode: screenshotMode
|
|
10082
10088
|
});
|
|
10083
10089
|
}
|
|
10084
10090
|
return await compressImageBufferToBase64(outputBuffer, compression);
|
|
@@ -10087,8 +10093,12 @@ var Share = {
|
|
|
10087
10093
|
|
|
10088
10094
|
// entrys/node.js
|
|
10089
10095
|
Logger.setLogger(import_crawlee.log);
|
|
10090
|
-
var
|
|
10091
|
-
|
|
10096
|
+
var ToolkitMode = Object.freeze({
|
|
10097
|
+
default: Mode.Default,
|
|
10098
|
+
cloak: Mode.Cloak
|
|
10099
|
+
});
|
|
10100
|
+
var usePlaywrightToolKit = (mode2 = Mode.Default) => {
|
|
10101
|
+
setToolkitMode(mode2);
|
|
10092
10102
|
const toolkit = {
|
|
10093
10103
|
ApifyKit,
|
|
10094
10104
|
AntiCheat,
|
|
@@ -10111,6 +10121,7 @@ var usePlaywrightToolKit = (mode = "default") => {
|
|
|
10111
10121
|
};
|
|
10112
10122
|
return toolkit;
|
|
10113
10123
|
};
|
|
10124
|
+
usePlaywrightToolKit.Mode = ToolkitMode;
|
|
10114
10125
|
// Annotate the CommonJS export names for ESM import in node:
|
|
10115
10126
|
0 && (module.exports = {
|
|
10116
10127
|
usePlaywrightToolKit
|