@skrillex1224/playwright-toolkit 2.1.161 → 2.1.163
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/README.md +9 -7
- package/dist/index.cjs +46 -12
- package/dist/index.cjs.map +2 -2
- package/dist/index.js +46 -12
- package/dist/index.js.map +2 -2
- package/index.d.ts +33 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -31,12 +31,16 @@ const ApifyKit = await KitHook.useApifyKit();
|
|
|
31
31
|
// LiveView
|
|
32
32
|
const { startLiveViewServer, takeLiveScreenshot } = LiveView.useLiveView();
|
|
33
33
|
|
|
34
|
+
const crawlerOptions = Launch.getPlaywrightCrawlerOptions({
|
|
35
|
+
runInHeadfulMode: false,
|
|
36
|
+
isRunningOnApify: Actor.isAtHome(),
|
|
37
|
+
launcher: chromium,
|
|
38
|
+
});
|
|
39
|
+
|
|
34
40
|
const crawler = new PlaywrightCrawler({
|
|
35
|
-
|
|
36
|
-
launcher: chromium,
|
|
37
|
-
launchOptions: Launch.getAdvancedLaunchOptions(),
|
|
38
|
-
},
|
|
41
|
+
...crawlerOptions,
|
|
39
42
|
preNavigationHooks: [
|
|
43
|
+
...crawlerOptions.preNavigationHooks,
|
|
40
44
|
async ({ page }) => {
|
|
41
45
|
// 验证码监控
|
|
42
46
|
Captcha.useCaptchaMonitor(page, {
|
|
@@ -84,9 +88,7 @@ await Actor.exit();
|
|
|
84
88
|
|
|
85
89
|
| 模块 | 方法 | 说明 |
|
|
86
90
|
| ----------- | ------------------------------------------------ | ------------------------------------------------------------------------------------ |
|
|
87
|
-
| `Launch` | `
|
|
88
|
-
| `Launch` | `getLaunchOptions({ proxyConfiguration, log? })` | 基础启动参数(返回 `onPageCreated(page) => { waitUntil }`,默认 `domcontentloaded`) |
|
|
89
|
-
| `Launch` | `getFingerprintGeneratorOptions()` | 指纹生成器选项 |
|
|
91
|
+
| `Launch` | `getPlaywrightCrawlerOptions(options)` | 一次性返回 PlaywrightCrawler 所需公共配置(超时/指纹/代理/导航 hook) |
|
|
90
92
|
| `AntiCheat` | `applyPage(page, options?)` | 应用时区/语言/权限/视口 |
|
|
91
93
|
| `AntiCheat` | `applyContext(context, options?)` | 仅应用 Context 设置 |
|
|
92
94
|
| `AntiCheat` | `syncViewportWithScreen(page)` | 同步视口与屏幕 |
|
package/dist/index.cjs
CHANGED
|
@@ -631,7 +631,7 @@ async function createApifyKit() {
|
|
|
631
631
|
logger2.success(`[RetryStep] before \u94A9\u5B50\u5B8C\u6210`);
|
|
632
632
|
} else if (retryMode === "refresh") {
|
|
633
633
|
logger2.start(`[RetryStep] \u5237\u65B0\u9875\u9762 (\u7B2C ${attemptNumber} \u6B21\u91CD\u8BD5)`);
|
|
634
|
-
await page.reload({ waitUntil: "
|
|
634
|
+
await page.reload({ waitUntil: "commit" });
|
|
635
635
|
logger2.success(`[RetryStep] \u9875\u9762\u5237\u65B0\u5B8C\u6210`);
|
|
636
636
|
} else {
|
|
637
637
|
logger2.start(`[RetryStep] \u7B49\u5F85 3 \u79D2 (\u7B2C ${attemptNumber} \u6B21\u91CD\u8BD5)`);
|
|
@@ -1619,6 +1619,12 @@ var createTrafficMeter = ({
|
|
|
1619
1619
|
|
|
1620
1620
|
// src/launch.js
|
|
1621
1621
|
var logger7 = createInternalLogger("Launch");
|
|
1622
|
+
var DEFAULT_CRAWLER_BASE_OPTIONS = Object.freeze({
|
|
1623
|
+
maxConcurrency: 1,
|
|
1624
|
+
maxRequestRetries: 0,
|
|
1625
|
+
requestHandlerTimeoutSecs: 240,
|
|
1626
|
+
navigationTimeoutSecs: 120
|
|
1627
|
+
});
|
|
1622
1628
|
var resolveProxyLaunchOptions = (proxyConfiguration = {}) => {
|
|
1623
1629
|
const config = proxyConfiguration && typeof proxyConfiguration === "object" && !Array.isArray(proxyConfiguration) ? proxyConfiguration : {};
|
|
1624
1630
|
const proxyUrl = String(config.proxy_url || "").trim();
|
|
@@ -1644,12 +1650,17 @@ var resolveProxyLaunchOptions = (proxyConfiguration = {}) => {
|
|
|
1644
1650
|
return { launchProxy, byPassDomains, enableProxy, proxyUrl };
|
|
1645
1651
|
};
|
|
1646
1652
|
var Launch = {
|
|
1647
|
-
|
|
1653
|
+
getPlaywrightCrawlerOptions(options = {}) {
|
|
1648
1654
|
const normalizedOptions = Array.isArray(options) ? { customArgs: options } : options || {};
|
|
1649
1655
|
const {
|
|
1650
1656
|
customArgs = [],
|
|
1651
1657
|
proxyConfiguration = {},
|
|
1652
|
-
log: logOptions = null
|
|
1658
|
+
log: logOptions = null,
|
|
1659
|
+
runInHeadfulMode = false,
|
|
1660
|
+
isRunningOnApify = false,
|
|
1661
|
+
launcher = null,
|
|
1662
|
+
preNavigationHooks = [],
|
|
1663
|
+
postNavigationHooks = []
|
|
1653
1664
|
} = normalizedOptions;
|
|
1654
1665
|
const { launchProxy, byPassDomains, enableProxy, proxyUrl } = resolveProxyLaunchOptions(proxyConfiguration);
|
|
1655
1666
|
const byPassRules = buildByPassDomainRules(byPassDomains);
|
|
@@ -1684,7 +1695,7 @@ var Launch = {
|
|
|
1684
1695
|
}
|
|
1685
1696
|
const onPageCreated = (page) => {
|
|
1686
1697
|
const recommendedGotoOptions = {
|
|
1687
|
-
waitUntil: "
|
|
1698
|
+
waitUntil: "commit"
|
|
1688
1699
|
};
|
|
1689
1700
|
if (page && typeof page.on === "function") {
|
|
1690
1701
|
trafficMeter2.attachPage(page);
|
|
@@ -1701,14 +1712,37 @@ var Launch = {
|
|
|
1701
1712
|
page.on("request", requestHandler);
|
|
1702
1713
|
return recommendedGotoOptions;
|
|
1703
1714
|
};
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1715
|
+
const launchContext = {
|
|
1716
|
+
useIncognitoPages: true,
|
|
1717
|
+
launchOptions
|
|
1718
|
+
};
|
|
1719
|
+
if (launcher) {
|
|
1720
|
+
launchContext.launcher = launcher;
|
|
1721
|
+
}
|
|
1722
|
+
const crawlerBaseOptions = {
|
|
1723
|
+
...DEFAULT_CRAWLER_BASE_OPTIONS,
|
|
1724
|
+
headless: !runInHeadfulMode || isRunningOnApify,
|
|
1725
|
+
browserPoolOptions: {
|
|
1726
|
+
useFingerprints: true,
|
|
1727
|
+
fingerprintOptions: {
|
|
1728
|
+
fingerprintGeneratorOptions: AntiCheat.getFingerprintGeneratorOptions()
|
|
1729
|
+
}
|
|
1730
|
+
},
|
|
1731
|
+
launchContext
|
|
1732
|
+
};
|
|
1733
|
+
const normalizedPreNavigationHooks = Array.isArray(preNavigationHooks) ? preNavigationHooks : [];
|
|
1734
|
+
const normalizedPostNavigationHooks = Array.isArray(postNavigationHooks) ? postNavigationHooks : [];
|
|
1735
|
+
const internalPreNavigationHook = async ({ page }, gotoOptions = {}) => {
|
|
1736
|
+
const recommendedGotoOptions = onPageCreated(page);
|
|
1737
|
+
if (recommendedGotoOptions && typeof recommendedGotoOptions === "object") {
|
|
1738
|
+
Object.assign(gotoOptions, recommendedGotoOptions);
|
|
1739
|
+
}
|
|
1740
|
+
};
|
|
1741
|
+
return {
|
|
1742
|
+
...crawlerBaseOptions,
|
|
1743
|
+
preNavigationHooks: [internalPreNavigationHook, ...normalizedPreNavigationHooks],
|
|
1744
|
+
...normalizedPostNavigationHooks.length > 0 ? { postNavigationHooks: normalizedPostNavigationHooks } : {}
|
|
1745
|
+
};
|
|
1712
1746
|
}
|
|
1713
1747
|
};
|
|
1714
1748
|
|