@aomex-contrib/playwright 0.0.0-stage → 0.3.0
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/CHANGELOG.md +13 -0
- package/LICENSE +21 -0
- package/README.md +252 -2
- package/dist/index.d.ts +1792 -0
- package/dist/index.js +330 -0
- package/dist/index.js.map +1 -0
- package/package.json +45 -3
package/dist/index.js
ADDED
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
import { I18n, Service, createI18n, parseDuration, sleep } from "@aomex/common";
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { chromium } from "playwright";
|
|
7
|
+
import { addExtra } from "playwright-extra";
|
|
8
|
+
import RecaptchaPlugin from "puppeteer-extra-plugin-recaptcha";
|
|
9
|
+
import StealthPlugin from "puppeteer-extra-plugin-stealth";
|
|
10
|
+
// src/i18n/locales/zh-cn.ts
|
|
11
|
+
const zh = I18n.define({
|
|
12
|
+
browser_not_ready: "[Playwright] Browser 未就绪或已断开",
|
|
13
|
+
close_browser_timeout: "关闭浏览器超时",
|
|
14
|
+
close_browser_failed: "[Playwright] 关闭失败,准备强杀:{{message}}",
|
|
15
|
+
force_kill_browser: "[Playwright] 已强杀 Chromium 进程 pid={{pid}}",
|
|
16
|
+
force_kill_failed: "[Playwright] 强杀失败:{{message}}",
|
|
17
|
+
close_context_timeout: "关闭 Context 超时",
|
|
18
|
+
close_context_failed: "[Playwright] 关闭 Context 失败:{{message}}",
|
|
19
|
+
xvfb_exited: "Xvfb 退出,code={{code}}",
|
|
20
|
+
xvfb_start_failed: "Xvfb 启动失败",
|
|
21
|
+
max_concurrent_invalid: "maxConcurrent 必须是 >= 1 的整数"
|
|
22
|
+
});
|
|
23
|
+
// src/i18n/locales/en-us.ts
|
|
24
|
+
const en = I18n.satisfies(zh).define({
|
|
25
|
+
browser_not_ready: "[Playwright] Browser is not ready or has disconnected",
|
|
26
|
+
close_browser_timeout: "Timed out while closing browser",
|
|
27
|
+
close_browser_failed: "[Playwright] Failed to close browser, force-killing: {{message}}",
|
|
28
|
+
force_kill_browser: "[Playwright] Force-killed Chromium process pid={{pid}}",
|
|
29
|
+
force_kill_failed: "[Playwright] Force-kill failed: {{message}}",
|
|
30
|
+
close_context_timeout: "Timed out while closing context",
|
|
31
|
+
close_context_failed: "[Playwright] Failed to close context: {{message}}",
|
|
32
|
+
xvfb_exited: "Xvfb exited with code={{code}}",
|
|
33
|
+
xvfb_start_failed: "Xvfb failed to start",
|
|
34
|
+
max_concurrent_invalid: "maxConcurrent must be an integer >= 1"
|
|
35
|
+
});
|
|
36
|
+
// src/i18n/index.ts
|
|
37
|
+
const i18n = createI18n({
|
|
38
|
+
zh,
|
|
39
|
+
en,
|
|
40
|
+
load: (file) => import(new URL(`./locales/${file}.js`, import.meta.url).href)
|
|
41
|
+
});
|
|
42
|
+
// src/utils.ts
|
|
43
|
+
const INVALID_DIR_CHARS = /[<>:"/\\|?*\u0000-\u001f]/g;
|
|
44
|
+
/** 净化为可用的会话目录名 */
|
|
45
|
+
function sanitizeUserDataDirName(dir) {
|
|
46
|
+
let sanitized = dir || "default";
|
|
47
|
+
sanitized = sanitized.replaceAll(INVALID_DIR_CHARS, "_").replace(/[.\s]+$/, "");
|
|
48
|
+
return sanitized && sanitized !== "." && sanitized !== ".." ? sanitized : "default";
|
|
49
|
+
}
|
|
50
|
+
function mergeProxy(base, auth) {
|
|
51
|
+
if (!base && !auth) return void 0;
|
|
52
|
+
return {
|
|
53
|
+
...base,
|
|
54
|
+
...auth?.username ? {
|
|
55
|
+
username: auth.username,
|
|
56
|
+
password: auth.password ?? ""
|
|
57
|
+
} : null
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/** 将 `BrowserProxy` 转为 Playwright `proxy`;无效则返回 `undefined` */
|
|
61
|
+
function toPlaywrightProxy(proxy) {
|
|
62
|
+
if (!proxy) return void 0;
|
|
63
|
+
const server = proxy.server?.trim() ? proxy.server.trim() : proxy.host && proxy.port != null ? `http://${proxy.host}:${proxy.port}` : void 0;
|
|
64
|
+
if (!server) return void 0;
|
|
65
|
+
return {
|
|
66
|
+
server,
|
|
67
|
+
...proxy.username ? {
|
|
68
|
+
username: proxy.username,
|
|
69
|
+
password: proxy.password ?? ""
|
|
70
|
+
} : null
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function chromeUserAgentFromVersion(version) {
|
|
74
|
+
return `Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${version.replace(/^Chrome\//i, "").split(" ")[0] || version} Safari/537.36`;
|
|
75
|
+
}
|
|
76
|
+
// src/playwright.service.ts
|
|
77
|
+
const DEFAULT_VIEWPORT = {
|
|
78
|
+
width: 1400,
|
|
79
|
+
height: 800
|
|
80
|
+
};
|
|
81
|
+
const DEFAULT_LAUNCH_ARGS = [
|
|
82
|
+
"--lang=en-US,en",
|
|
83
|
+
"--disable-blink-features=AutomationControlled",
|
|
84
|
+
"--disable-gpu",
|
|
85
|
+
"--disable-dev-shm-usage",
|
|
86
|
+
"--disable-setuid-sandbox",
|
|
87
|
+
"--no-sandbox",
|
|
88
|
+
"--disable-infobars",
|
|
89
|
+
"--no-first-run",
|
|
90
|
+
"--no-zygote"
|
|
91
|
+
];
|
|
92
|
+
function createPlaywrightService(opts) {
|
|
93
|
+
const headless = opts.headless ?? true;
|
|
94
|
+
const stealth = opts.stealth ?? true;
|
|
95
|
+
const viewport = opts.viewport ?? DEFAULT_VIEWPORT;
|
|
96
|
+
const timezoneId = opts.timezoneId ?? "America/New_York";
|
|
97
|
+
const locale = opts.locale ?? "en-US";
|
|
98
|
+
const defaultTimeoutMs = parseDuration(opts.defaultTimeout ?? "2 minutes");
|
|
99
|
+
const closeTimeoutMs = parseDuration(opts.closeTimeout ?? "10 seconds");
|
|
100
|
+
const idleTimeoutMs = parseDuration(opts.idleTimeout);
|
|
101
|
+
const maxConcurrent = opts.maxConcurrent;
|
|
102
|
+
if (maxConcurrent != null && (!Number.isInteger(maxConcurrent) || maxConcurrent < 1)) throw new Error(i18n.t("max_concurrent_invalid"));
|
|
103
|
+
const chromium$1 = addExtra(chromium);
|
|
104
|
+
if (stealth) chromium$1.use(StealthPlugin());
|
|
105
|
+
if (opts.recaptcha) chromium$1.use(RecaptchaPlugin(opts.recaptcha));
|
|
106
|
+
return class PlaywrightService extends Service {
|
|
107
|
+
_browser = null;
|
|
108
|
+
/** 进行中的 `withPage` 数量;>0 时禁止 idle 关闭 */
|
|
109
|
+
_active = 0;
|
|
110
|
+
/** `maxConcurrent` 排队等待者 */
|
|
111
|
+
_waiters = [];
|
|
112
|
+
_idleTimer = null;
|
|
113
|
+
/** close / launch 互斥队列 */
|
|
114
|
+
_mutex = Promise.resolve();
|
|
115
|
+
/** 是否已调用 `onDestroy`;避免多次重复关闭 */
|
|
116
|
+
_destroyed = false;
|
|
117
|
+
async onInit() {
|
|
118
|
+
if (!headless) await this.ensureDisplay();
|
|
119
|
+
await this.runExclusive(async () => {
|
|
120
|
+
this._browser = await this.launchBrowser();
|
|
121
|
+
});
|
|
122
|
+
this.scheduleIdleClose();
|
|
123
|
+
}
|
|
124
|
+
async onDestroy() {
|
|
125
|
+
this._destroyed = true;
|
|
126
|
+
this.clearIdleTimer();
|
|
127
|
+
this.wakeAllWaiters();
|
|
128
|
+
await this.runExclusive(async () => {
|
|
129
|
+
await this.closeBrowser();
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
runExclusive(fn) {
|
|
133
|
+
const run = this._mutex.then(fn, fn);
|
|
134
|
+
this._mutex = run.then(() => void 0, () => void 0);
|
|
135
|
+
return run;
|
|
136
|
+
}
|
|
137
|
+
async launchBrowser() {
|
|
138
|
+
const { args: extraArgs, ...launchRest } = opts.launch ?? {};
|
|
139
|
+
return chromium$1.launch({
|
|
140
|
+
headless,
|
|
141
|
+
ignoreDefaultArgs: ["--enable-automation"],
|
|
142
|
+
...launchRest,
|
|
143
|
+
args: [
|
|
144
|
+
...DEFAULT_LAUNCH_ARGS,
|
|
145
|
+
`--window-size=${viewport.width},${viewport.height}`,
|
|
146
|
+
...extraArgs ?? []
|
|
147
|
+
]
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* 占用一个并发名额(`_active++`);达到 `maxConcurrent` 时排队。
|
|
152
|
+
*/
|
|
153
|
+
async acquireSlot() {
|
|
154
|
+
for (;;) {
|
|
155
|
+
if (this._destroyed) throw new Error(i18n.t("browser_not_ready"));
|
|
156
|
+
if (maxConcurrent == null || this._active < maxConcurrent) {
|
|
157
|
+
this._active += 1;
|
|
158
|
+
this.clearIdleTimer();
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
await new Promise((resolve) => {
|
|
162
|
+
this._waiters.push(resolve);
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
releaseSlot() {
|
|
167
|
+
this._active = Math.max(0, this._active - 1);
|
|
168
|
+
this._waiters.shift()?.();
|
|
169
|
+
if (this._active === 0) this.scheduleIdleClose();
|
|
170
|
+
}
|
|
171
|
+
wakeAllWaiters() {
|
|
172
|
+
const waiters = this._waiters.splice(0);
|
|
173
|
+
for (const wake of waiters) wake();
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* 确保 Browser 可用(互斥);idle 关闭或断开后会重新 launch。
|
|
177
|
+
*/
|
|
178
|
+
async ensureBrowser() {
|
|
179
|
+
return this.runExclusive(async () => {
|
|
180
|
+
if (this._destroyed) throw new Error(i18n.t("browser_not_ready"));
|
|
181
|
+
this.clearIdleTimer();
|
|
182
|
+
if (!this._browser?.isConnected()) this._browser = await this.launchBrowser();
|
|
183
|
+
return this.requireBrowser();
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
clearIdleTimer() {
|
|
187
|
+
if (this._idleTimer) {
|
|
188
|
+
clearTimeout(this._idleTimer);
|
|
189
|
+
this._idleTimer = null;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
scheduleIdleClose() {
|
|
193
|
+
if (idleTimeoutMs == null || this._destroyed) return;
|
|
194
|
+
this.clearIdleTimer();
|
|
195
|
+
this._idleTimer = setTimeout(() => {
|
|
196
|
+
this.runExclusive(async () => {
|
|
197
|
+
if (this._destroyed || this._active > 0 || !this._browser) return;
|
|
198
|
+
await this.closeBrowser();
|
|
199
|
+
});
|
|
200
|
+
}, idleTimeoutMs);
|
|
201
|
+
this._idleTimer.unref?.();
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* 在已启动的 Browser 上开 Context/Page 执行任务;结束后关闭 Page+Context,**不**关 Browser。
|
|
205
|
+
* (若配置了 `idleTimeout` 且随后空闲,会异步关闭 Browser)
|
|
206
|
+
*/
|
|
207
|
+
async withPage(pageOpts, onHandle) {
|
|
208
|
+
await this.acquireSlot();
|
|
209
|
+
try {
|
|
210
|
+
const browser = await this.ensureBrowser();
|
|
211
|
+
const { proxy: proxyOpt, cookies, ...contextOpts } = pageOpts;
|
|
212
|
+
const proxy = toPlaywrightProxy(proxyOpt);
|
|
213
|
+
const context = await browser.newContext({
|
|
214
|
+
viewport,
|
|
215
|
+
locale,
|
|
216
|
+
timezoneId,
|
|
217
|
+
ignoreHTTPSErrors: true,
|
|
218
|
+
userAgent: opts.userAgent ?? chromeUserAgentFromVersion(browser.version()),
|
|
219
|
+
...contextOpts,
|
|
220
|
+
...proxy ? { proxy } : null
|
|
221
|
+
});
|
|
222
|
+
context.setDefaultTimeout(defaultTimeoutMs);
|
|
223
|
+
context.setDefaultNavigationTimeout(defaultTimeoutMs);
|
|
224
|
+
if (cookies?.length) await context.addCookies(cookies);
|
|
225
|
+
const page = await context.newPage();
|
|
226
|
+
try {
|
|
227
|
+
return await onHandle(page, context);
|
|
228
|
+
} finally {
|
|
229
|
+
await this.closeContextQuietly(context);
|
|
230
|
+
}
|
|
231
|
+
} finally {
|
|
232
|
+
this.releaseSlot();
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
/** 当前并发占用与 Browser 连接状态 */
|
|
236
|
+
getStats() {
|
|
237
|
+
return {
|
|
238
|
+
active: this._active,
|
|
239
|
+
waiting: this._waiters.length,
|
|
240
|
+
connected: !!this._browser?.isConnected()
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
/** 关闭 Browser,超时则强杀。调用方需已持有互斥(或确认无并发)。 */
|
|
244
|
+
async closeBrowser() {
|
|
245
|
+
const browser = this._browser;
|
|
246
|
+
if (!browser) return;
|
|
247
|
+
this._browser = null;
|
|
248
|
+
try {
|
|
249
|
+
await Promise.race([browser.close(), sleep(closeTimeoutMs).then(() => {
|
|
250
|
+
throw new Error(i18n.t("close_browser_timeout"));
|
|
251
|
+
})]);
|
|
252
|
+
} catch (error) {
|
|
253
|
+
this.warn(i18n.t("close_browser_failed", { message: error.message }));
|
|
254
|
+
this.forceKillBrowser(browser);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
requireBrowser() {
|
|
258
|
+
const browser = this._browser;
|
|
259
|
+
if (!browser?.isConnected()) throw new Error(i18n.t("browser_not_ready"));
|
|
260
|
+
return browser;
|
|
261
|
+
}
|
|
262
|
+
warn(message) {
|
|
263
|
+
opts.logger.warn(message);
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Linux 无头服务器上跑有界面 Chromium 时,若无 `DISPLAY` 则尝试启动 Xvfb。
|
|
267
|
+
* 需镜像已安装 `xvfb`。
|
|
268
|
+
*/
|
|
269
|
+
async ensureDisplay() {
|
|
270
|
+
if (process.env["DISPLAY"] || process.platform !== "linux") return;
|
|
271
|
+
const XVFB_DISPLAY_NUM = 99;
|
|
272
|
+
const display = `:${XVFB_DISPLAY_NUM}`;
|
|
273
|
+
const socketPath = path.join(tmpdir(), ".X11-unix", `X${XVFB_DISPLAY_NUM}`);
|
|
274
|
+
if (existsSync(socketPath)) {
|
|
275
|
+
process.env["DISPLAY"] = display;
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
const { width, height } = viewport;
|
|
279
|
+
const xvfb = spawn("Xvfb", [
|
|
280
|
+
display,
|
|
281
|
+
"-screen",
|
|
282
|
+
"0",
|
|
283
|
+
`${width}x${height}x24`,
|
|
284
|
+
"-nolisten",
|
|
285
|
+
"tcp"
|
|
286
|
+
], { stdio: "ignore" });
|
|
287
|
+
await new Promise((resolve, reject) => {
|
|
288
|
+
xvfb.once("error", reject);
|
|
289
|
+
xvfb.once("exit", (code) => {
|
|
290
|
+
if (code !== null && code !== 0) reject(new Error(i18n.t("xvfb_exited", { code: String(code) })));
|
|
291
|
+
});
|
|
292
|
+
const waitReady = async () => {
|
|
293
|
+
for (let i = 0; i < 40; i++) {
|
|
294
|
+
if (existsSync(socketPath)) {
|
|
295
|
+
process.env["DISPLAY"] = display;
|
|
296
|
+
resolve();
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
await sleep(50);
|
|
300
|
+
}
|
|
301
|
+
reject(new Error(i18n.t("xvfb_start_failed")));
|
|
302
|
+
};
|
|
303
|
+
waitReady();
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
forceKillBrowser(browser) {
|
|
307
|
+
try {
|
|
308
|
+
const proc = browser.process?.();
|
|
309
|
+
if (proc && !proc.killed) {
|
|
310
|
+
proc.kill("SIGKILL");
|
|
311
|
+
this.warn(i18n.t("force_kill_browser", { pid: String(proc.pid ?? "") }));
|
|
312
|
+
}
|
|
313
|
+
} catch (error) {
|
|
314
|
+
this.warn(i18n.t("force_kill_failed", { message: error.message }));
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
async closeContextQuietly(context) {
|
|
318
|
+
try {
|
|
319
|
+
await Promise.race([context.close(), sleep(closeTimeoutMs).then(() => {
|
|
320
|
+
throw new Error(i18n.t("close_context_timeout"));
|
|
321
|
+
})]);
|
|
322
|
+
} catch (error) {
|
|
323
|
+
this.warn(i18n.t("close_context_failed", { message: error.message }));
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
export { chromeUserAgentFromVersion, createPlaywrightService, i18n, mergeProxy, sanitizeUserDataDirName, toPlaywrightProxy };
|
|
329
|
+
|
|
330
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["chromium","vanillaChromium"],"sources":["../src/i18n/locales/zh-cn.ts","../src/i18n/locales/en-us.ts","../src/i18n/index.ts","../src/utils.ts","../src/playwright.service.ts"],"sourcesContent":["import { I18n } from '@aomex/common';\n\nexport const zh = I18n.define({\n browser_not_ready: '[Playwright] Browser 未就绪或已断开',\n close_browser_timeout: '关闭浏览器超时',\n close_browser_failed: '[Playwright] 关闭失败,准备强杀:{{message}}',\n force_kill_browser: '[Playwright] 已强杀 Chromium 进程 pid={{pid}}',\n force_kill_failed: '[Playwright] 强杀失败:{{message}}',\n close_context_timeout: '关闭 Context 超时',\n close_context_failed: '[Playwright] 关闭 Context 失败:{{message}}',\n xvfb_exited: 'Xvfb 退出,code={{code}}',\n xvfb_start_failed: 'Xvfb 启动失败',\n max_concurrent_invalid: 'maxConcurrent 必须是 >= 1 的整数',\n});\n","import { I18n } from '@aomex/common';\nimport { zh } from './zh-cn';\n\nexport const en = I18n.satisfies(zh).define({\n browser_not_ready: '[Playwright] Browser is not ready or has disconnected',\n close_browser_timeout: 'Timed out while closing browser',\n close_browser_failed:\n '[Playwright] Failed to close browser, force-killing: {{message}}',\n force_kill_browser: '[Playwright] Force-killed Chromium process pid={{pid}}',\n force_kill_failed: '[Playwright] Force-kill failed: {{message}}',\n close_context_timeout: 'Timed out while closing context',\n close_context_failed: '[Playwright] Failed to close context: {{message}}',\n xvfb_exited: 'Xvfb exited with code={{code}}',\n xvfb_start_failed: 'Xvfb failed to start',\n max_concurrent_invalid: 'maxConcurrent must be an integer >= 1',\n});\n","import { createI18n } from '@aomex/common';\nimport { en } from './locales/en-us';\nimport { zh } from './locales/zh-cn';\n\nexport const i18n = createI18n({\n zh,\n en,\n load: (file) => import(new URL(`./locales/${file}.js`, import.meta.url).href),\n});\n","import type { BrowserProxy } from './types';\n\nconst INVALID_DIR_CHARS = /[<>:\"/\\\\|?*\\u0000-\\u001f]/g;\n\n/** 净化为可用的会话目录名 */\nexport function sanitizeUserDataDirName(dir: string | undefined): string {\n let sanitized = dir || 'default';\n sanitized = sanitized.replaceAll(INVALID_DIR_CHARS, '_').replace(/[.\\s]+$/, '');\n return sanitized && sanitized !== '.' && sanitized !== '..' ? sanitized : 'default';\n}\n\nexport function mergeProxy(\n base: BrowserProxy | undefined,\n auth: { username: string; password: string } | undefined,\n): BrowserProxy | undefined {\n if (!base && !auth) return undefined;\n return {\n ...base,\n ...(auth?.username\n ? { username: auth.username, password: auth.password ?? '' }\n : null),\n };\n}\n\n/** 将 `BrowserProxy` 转为 Playwright `proxy`;无效则返回 `undefined` */\nexport function toPlaywrightProxy(\n proxy: BrowserProxy | undefined,\n): { server: string; username?: string; password?: string } | undefined {\n if (!proxy) return undefined;\n const server = proxy.server?.trim()\n ? proxy.server.trim()\n : proxy.host && proxy.port != null\n ? `http://${proxy.host}:${proxy.port}`\n : undefined;\n if (!server) return undefined;\n return {\n server,\n ...(proxy.username\n ? { username: proxy.username, password: proxy.password ?? '' }\n : null),\n };\n}\n\nexport function chromeUserAgentFromVersion(version: string): string {\n const chromeVersion = version.replace(/^Chrome\\//i, '').split(' ')[0] || version;\n return `Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${chromeVersion} Safari/537.36`;\n}\n","import { parseDuration, Service, sleep } from '@aomex/common';\nimport { spawn } from 'node:child_process';\nimport { existsSync } from 'node:fs';\nimport { tmpdir } from 'node:os';\nimport path from 'node:path';\nimport {\n chromium as vanillaChromium,\n type Browser,\n type BrowserContext,\n} from 'playwright';\nimport { addExtra } from 'playwright-extra';\nimport RecaptchaPlugin from 'puppeteer-extra-plugin-recaptcha';\nimport StealthPlugin from 'puppeteer-extra-plugin-stealth';\nimport { i18n } from './i18n';\nimport type {\n CreatePlaywrightServiceOptions,\n PlaywrightPage,\n PlaywrightServiceStats,\n PlaywrightViewport,\n RecaptchaOptions,\n WithPageOptions,\n} from './types';\nimport { chromeUserAgentFromVersion, toPlaywrightProxy } from './utils';\n\nconst DEFAULT_VIEWPORT: PlaywrightViewport = { width: 1400, height: 800 };\n\nconst DEFAULT_LAUNCH_ARGS = [\n '--lang=en-US,en',\n '--disable-blink-features=AutomationControlled',\n '--disable-gpu',\n '--disable-dev-shm-usage',\n '--disable-setuid-sandbox',\n '--no-sandbox',\n '--disable-infobars',\n '--no-first-run',\n '--no-zygote',\n];\n\n/** `createPlaywrightService` 返回类的实例公开 API */\nexport type PlaywrightService<HasRecaptcha extends boolean = false> = Service & {\n withPage<T>(\n opts: WithPageOptions,\n onHandle: (page: PlaywrightPage<HasRecaptcha>, context: BrowserContext) => Promise<T>,\n ): Promise<T>;\n getStats(): PlaywrightServiceStats;\n};\n\nexport type PlaywrightServiceCtor<HasRecaptcha extends boolean = false> =\n new () => PlaywrightService<HasRecaptcha>;\n\n/**\n * 创建 Playwright Browser Service 子类。\n *\n * - `onInit`:启动唯一 Chromium 进程(默认经 playwright-extra + stealth)\n * - `withPage`:每次新建带代理的 `BrowserContext` + `Page`,用完关闭 Context\n * - `getStats`:并发占用与 Browser 连接状态\n * - `idleTimeout`:空闲且无进行中任务时关闭 Browser;下次 `withPage` 再启\n * - `maxConcurrent`:同时进行的 `withPage` 上限,超出排队\n * - `recaptcha`:可选挂载 recaptcha 插件;传入后 `withPage` 的 page 类型带解题方法\n * - `onDestroy`:关闭进程;超时则强杀\n *\n * 站点点击流等业务逻辑请放在业务 Service,不要塞进本类。\n */\nexport function createPlaywrightService(\n opts: CreatePlaywrightServiceOptions & { recaptcha: RecaptchaOptions },\n): PlaywrightServiceCtor<true>;\nexport function createPlaywrightService(\n opts: CreatePlaywrightServiceOptions,\n): PlaywrightServiceCtor<false>;\nexport function createPlaywrightService(\n opts: CreatePlaywrightServiceOptions,\n): PlaywrightServiceCtor<boolean> {\n const headless = opts.headless ?? true;\n const stealth = opts.stealth ?? true;\n const viewport = opts.viewport ?? DEFAULT_VIEWPORT;\n const timezoneId = opts.timezoneId ?? 'America/New_York';\n const locale = opts.locale ?? 'en-US';\n const defaultTimeoutMs = parseDuration(opts.defaultTimeout ?? '2 minutes');\n const closeTimeoutMs = parseDuration(opts.closeTimeout ?? '10 seconds');\n const idleTimeoutMs = parseDuration(opts.idleTimeout);\n const maxConcurrent = opts.maxConcurrent;\n if (maxConcurrent != null && (!Number.isInteger(maxConcurrent) || maxConcurrent < 1)) {\n throw new Error(i18n.t('max_concurrent_invalid'));\n }\n // 每次工厂调用独立 launcher,避免多次 create 时往全局 chromium 重复挂插件\n const chromium = addExtra(vanillaChromium);\n if (stealth) {\n chromium.use(StealthPlugin());\n }\n if (opts.recaptcha) {\n chromium.use(RecaptchaPlugin(opts.recaptcha));\n }\n\n return class PlaywrightService extends Service {\n protected _browser: Browser | null = null;\n /** 进行中的 `withPage` 数量;>0 时禁止 idle 关闭 */\n protected _active = 0;\n /** `maxConcurrent` 排队等待者 */\n protected _waiters: Array<() => void> = [];\n protected _idleTimer: ReturnType<typeof setTimeout> | null = null;\n /** close / launch 互斥队列 */\n protected _mutex: Promise<unknown> = Promise.resolve();\n /** 是否已调用 `onDestroy`;避免多次重复关闭 */\n protected _destroyed = false;\n\n protected override async onInit(): Promise<void> {\n if (!headless) {\n await this.ensureDisplay();\n }\n await this.runExclusive(async () => {\n this._browser = await this.launchBrowser();\n });\n this.scheduleIdleClose();\n }\n\n protected override async onDestroy(): Promise<void> {\n this._destroyed = true;\n this.clearIdleTimer();\n this.wakeAllWaiters();\n await this.runExclusive(async () => {\n await this.closeBrowser();\n });\n }\n\n protected runExclusive<T>(fn: () => Promise<T>): Promise<T> {\n const run = this._mutex.then(fn, fn);\n this._mutex = run.then(\n () => undefined,\n () => undefined,\n );\n return run;\n }\n\n protected async launchBrowser(): Promise<Browser> {\n const { args: extraArgs, ...launchRest } = opts.launch ?? {};\n return chromium.launch({\n headless,\n ignoreDefaultArgs: ['--enable-automation'],\n ...launchRest,\n args: [\n ...DEFAULT_LAUNCH_ARGS,\n `--window-size=${viewport.width},${viewport.height}`,\n ...(extraArgs ?? []),\n ],\n });\n }\n\n /**\n * 占用一个并发名额(`_active++`);达到 `maxConcurrent` 时排队。\n */\n protected async acquireSlot(): Promise<void> {\n for (;;) {\n if (this._destroyed) {\n throw new Error(i18n.t('browser_not_ready'));\n }\n if (maxConcurrent == null || this._active < maxConcurrent) {\n this._active += 1;\n this.clearIdleTimer();\n return;\n }\n await new Promise<void>((resolve) => {\n this._waiters.push(resolve);\n });\n }\n }\n\n protected releaseSlot(): void {\n this._active = Math.max(0, this._active - 1);\n const next = this._waiters.shift();\n next?.();\n if (this._active === 0) {\n this.scheduleIdleClose();\n }\n }\n\n protected wakeAllWaiters(): void {\n const waiters = this._waiters.splice(0);\n for (const wake of waiters) wake();\n }\n\n /**\n * 确保 Browser 可用(互斥);idle 关闭或断开后会重新 launch。\n */\n protected async ensureBrowser(): Promise<Browser> {\n return this.runExclusive(async () => {\n if (this._destroyed) {\n throw new Error(i18n.t('browser_not_ready'));\n }\n this.clearIdleTimer();\n if (!this._browser?.isConnected()) {\n this._browser = await this.launchBrowser();\n }\n return this.requireBrowser();\n });\n }\n\n protected clearIdleTimer(): void {\n if (this._idleTimer) {\n clearTimeout(this._idleTimer);\n this._idleTimer = null;\n }\n }\n\n protected scheduleIdleClose(): void {\n if (idleTimeoutMs == null || this._destroyed) return;\n this.clearIdleTimer();\n this._idleTimer = setTimeout(() => {\n void this.runExclusive(async () => {\n if (this._destroyed || this._active > 0 || !this._browser) return;\n await this.closeBrowser();\n });\n }, idleTimeoutMs);\n this._idleTimer.unref?.();\n }\n\n /**\n * 在已启动的 Browser 上开 Context/Page 执行任务;结束后关闭 Page+Context,**不**关 Browser。\n * (若配置了 `idleTimeout` 且随后空闲,会异步关闭 Browser)\n */\n async withPage<T>(\n pageOpts: WithPageOptions,\n onHandle: (page: PlaywrightPage<boolean>, context: BrowserContext) => Promise<T>,\n ): Promise<T> {\n await this.acquireSlot();\n try {\n const browser = await this.ensureBrowser();\n const { proxy: proxyOpt, cookies, ...contextOpts } = pageOpts;\n const proxy = toPlaywrightProxy(proxyOpt);\n\n const context = await browser.newContext({\n viewport,\n locale,\n timezoneId,\n ignoreHTTPSErrors: true,\n userAgent: opts.userAgent ?? chromeUserAgentFromVersion(browser.version()),\n ...contextOpts,\n ...(proxy ? { proxy } : null),\n });\n\n context.setDefaultTimeout(defaultTimeoutMs);\n context.setDefaultNavigationTimeout(defaultTimeoutMs);\n\n if (cookies?.length) {\n await context.addCookies(cookies);\n }\n\n const page = await context.newPage();\n\n try {\n return await onHandle(page as PlaywrightPage<boolean>, context);\n } finally {\n await this.closeContextQuietly(context);\n }\n } finally {\n this.releaseSlot();\n }\n }\n\n /** 当前并发占用与 Browser 连接状态 */\n getStats(): PlaywrightServiceStats {\n return {\n active: this._active,\n waiting: this._waiters.length,\n connected: !!this._browser?.isConnected(),\n };\n }\n\n /** 关闭 Browser,超时则强杀。调用方需已持有互斥(或确认无并发)。 */\n protected async closeBrowser(): Promise<void> {\n const browser = this._browser;\n if (!browser) return;\n\n this._browser = null;\n try {\n await Promise.race([\n browser.close(),\n sleep(closeTimeoutMs).then(() => {\n throw new Error(i18n.t('close_browser_timeout'));\n }),\n ]);\n } catch (error) {\n this.warn(\n i18n.t('close_browser_failed', {\n message: (error as Error).message,\n }),\n );\n this.forceKillBrowser(browser);\n }\n }\n\n protected requireBrowser(): Browser {\n const browser = this._browser;\n if (!browser?.isConnected()) {\n throw new Error(i18n.t('browser_not_ready'));\n }\n return browser;\n }\n\n protected warn(message: string): void {\n opts.logger.warn(message);\n }\n\n /**\n * Linux 无头服务器上跑有界面 Chromium 时,若无 `DISPLAY` 则尝试启动 Xvfb。\n * 需镜像已安装 `xvfb`。\n */\n protected async ensureDisplay(): Promise<void> {\n if (process.env['DISPLAY'] || process.platform !== 'linux') return;\n\n const XVFB_DISPLAY_NUM = 99;\n const display = `:${XVFB_DISPLAY_NUM}`;\n const socketPath = path.join(tmpdir(), '.X11-unix', `X${XVFB_DISPLAY_NUM}`);\n\n if (existsSync(socketPath)) {\n process.env['DISPLAY'] = display;\n return;\n }\n\n const { width, height } = viewport;\n const xvfb = spawn(\n 'Xvfb',\n [display, '-screen', '0', `${width}x${height}x24`, '-nolisten', 'tcp'],\n { stdio: 'ignore' },\n );\n\n await new Promise<void>((resolve, reject) => {\n xvfb.once('error', reject);\n xvfb.once('exit', (code) => {\n if (code !== null && code !== 0) {\n reject(new Error(i18n.t('xvfb_exited', { code: String(code) })));\n }\n });\n\n const waitReady = async () => {\n for (let i = 0; i < 40; i++) {\n if (existsSync(socketPath)) {\n process.env['DISPLAY'] = display;\n resolve();\n return;\n }\n await sleep(50);\n }\n reject(new Error(i18n.t('xvfb_start_failed')));\n };\n\n void waitReady();\n });\n }\n\n protected forceKillBrowser(browser: Browser): void {\n try {\n // playwright 类型上 Browser.process 偶发缺失;运行时 chromium.launch 实例有此方法\n const proc = (\n browser as Browser & {\n process?: () => {\n kill: (signal?: NodeJS.Signals) => boolean;\n killed?: boolean;\n pid?: number;\n } | null;\n }\n ).process?.();\n if (proc && !proc.killed) {\n proc.kill('SIGKILL');\n this.warn(i18n.t('force_kill_browser', { pid: String(proc.pid ?? '') }));\n }\n } catch (error) {\n this.warn(i18n.t('force_kill_failed', { message: (error as Error).message }));\n }\n }\n\n protected async closeContextQuietly(context: BrowserContext): Promise<void> {\n try {\n await Promise.race([\n context.close(),\n sleep(closeTimeoutMs).then(() => {\n throw new Error(i18n.t('close_context_timeout'));\n }),\n ]);\n } catch (error) {\n this.warn(\n i18n.t('close_context_failed', {\n message: (error as Error).message,\n }),\n );\n }\n }\n } as PlaywrightService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AED,MAAM,YAAY,YAAY;KAC5B,KAAK,IAAI,IAAI,GAAG,IAAI,IAAI,KAAK;MAC3B,IAAI,WAAW,UAAU,GAAG;OAC1B,QAAQ,IAAI,aAAa;OACzB,QAAQ;OACR;MACF;MACA,MAAM,MAAM,EAAE;KAChB;KACA,OAAO,IAAI,MAAM,KAAK,EAAE,mBAAmB,CAAC,CAAC;IAC/C;IAEK,UAAU;GACjB,CAAC;EACH;EAEU,iBAAiB,SAAwB;GACjD,IAAI;IAEF,MAAM,OACJ,QAOA,UAAU;IACZ,IAAI,QAAQ,CAAC,KAAK,QAAQ;KACxB,KAAK,KAAK,SAAS;KACnB,KAAK,KAAK,KAAK,EAAE,sBAAsB,EAAE,KAAK,OAAO,KAAK,OAAO,EAAE,EAAE,CAAC,CAAC;IACzE;GACF,SAAS,OAAO;IACd,KAAK,KAAK,KAAK,EAAE,qBAAqB,EAAE,SAAU,MAAgB,QAAQ,CAAC,CAAC;GAC9E;EACF;EAEA,MAAgB,oBAAoB,SAAwC;GAC1E,IAAI;IACF,MAAM,QAAQ,KAAK,CACjB,QAAQ,MAAM,GACd,MAAM,cAAc,CAAC,CAAC,WAAW;KAC/B,MAAM,IAAI,MAAM,KAAK,EAAE,uBAAuB,CAAC;IACjD,CAAC,CACH,CAAC;GACH,SAAS,OAAO;IACd,KAAK,KACH,KAAK,EAAE,wBAAwB,EAC7B,SAAU,MAAgB,QAC5B,CAAC,CACH;GACF;EACF;CACF;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,48 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aomex-contrib/playwright",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "基于 Playwright 的浏览器服务",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git@github.com:aomex/aomex-contrib.git"
|
|
8
|
+
},
|
|
9
|
+
"homepage": "https://aomex.js.org",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"type": "module",
|
|
12
|
+
"sideEffects": false,
|
|
13
|
+
"types": "dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./package.json": "./package.json"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"LICENSE",
|
|
24
|
+
"package.json",
|
|
25
|
+
"README.md",
|
|
26
|
+
"CHANGELOG.md"
|
|
27
|
+
],
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"@aomex/common": "^4.7.0",
|
|
33
|
+
"@aomex/logger": "^4.7.0",
|
|
34
|
+
"playwright": "^1.40.0"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"playwright-extra": "^4.3.6",
|
|
38
|
+
"puppeteer-extra-plugin-recaptcha": "^3.6.8",
|
|
39
|
+
"puppeteer-extra-plugin-stealth": "^2.11.2"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@aomex/common": "^4.7.0",
|
|
43
|
+
"@aomex/logger": "^4.7.0",
|
|
44
|
+
"@types/debug": "^4.1.13",
|
|
45
|
+
"playwright": "^1.65.1"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {}
|
|
6
48
|
}
|