@skrillex1224/playwright-toolkit 2.1.197 → 2.1.199

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/index.d.ts CHANGED
@@ -1,665 +1,636 @@
1
- import type { Page, BrowserContext, Browser, ElementHandle } from 'playwright';
2
-
3
- // =============================================================================
4
- // Constants
5
- // =============================================================================
6
- export interface CodeType {
7
- Success: 0;
8
- UnknownError: -1;
9
- NotLogin: 30000001;
10
- Chaptcha: 30000002;
11
- Timeout: 30000003;
12
- InitialTimeout: 30000004;
13
- OverallTimeout: 30000005;
14
- }
15
-
16
- export interface StatusType {
17
- Success: 'SUCCESS';
18
- Failed: 'FAILED';
19
- }
20
-
21
- export interface ConstantsModule {
22
- Code: CodeType;
23
- Status: StatusType;
24
- PresetOfLiveViewKey: string;
25
- ActorInfo: Record<string, ActorInfoItem>;
26
- }
27
-
28
- export interface ActorShareInfo {
29
- mode: 'dom' | 'response';
30
- prefix: string;
31
- xurl: Array<string | string[]>;
32
- }
33
-
34
- export interface ActorInfoItem {
35
- key: string;
36
- name: string;
37
- icon: string;
38
- domain: string;
39
- protocol: string;
40
- path: string;
41
- share: ActorShareInfo;
42
- readonly landingUrl: string;
43
- }
44
-
45
- // =============================================================================
46
- // Errors
47
- // =============================================================================
48
- export interface CrawlerErrorInfo {
49
- message: string;
50
- code?: number;
51
- context?: Record<string, any>;
52
- }
53
-
54
- export declare class CrawlerError extends Error {
55
- name: 'CrawlerError';
56
- code: number;
57
- context: Record<string, any>;
58
- timestamp: string;
59
-
60
- constructor(info: string | CrawlerErrorInfo);
61
- toJSON(): Record<string, any>;
62
- static isCrawlerError(error: any): error is CrawlerError;
63
- static from(error: Error, options?: { code?: number; context?: Record<string, any> }): CrawlerError;
64
- }
65
-
66
- export interface ErrorsModule {
67
- CrawlerError: typeof CrawlerError;
68
- }
69
-
70
- // =============================================================================
71
- // Logger
72
- // =============================================================================
73
- export interface LoggerTemplate {
74
- step(
75
- step: string,
76
- status?: string,
77
- details?: string[],
78
- level?: 'info' | 'warn' | 'warning' | 'error' | 'success' | 'start'
79
- ): void;
80
- taskStart(url?: string): void;
81
- taskSuccess(): void;
82
- taskFail(url?: string, err?: unknown): void;
83
- runtimeHeadless(): void;
84
- loginInjectSuccess(detail?: string): void;
85
- loginInjectSkip(reason?: string): void;
86
- loginInjectFail(err?: unknown): void;
87
- loginVerifySuccess(detail?: string): void;
88
- loginVerifySkip(reason?: string): void;
89
- loginVerifyFail(err?: unknown): void;
90
- envCheckSuccess(detail?: string): void;
91
- envCheckFail(err?: unknown): void;
92
- inputQuery(query?: string): void;
93
- sendAction(): void;
94
- responseListenStart(label?: string, timeoutSec?: number): void;
95
- responseListenReady(label?: string): void;
96
- responseListenDetected(label?: string): void;
97
- responseListenTimeout(label?: string, err?: unknown): void;
98
- responseListenEnd(label?: string): void;
99
- domWaitStart(label?: string): void;
100
- domWaitSuccess(mutationCount?: number, stableTime?: number, wasPaused?: boolean): void;
101
- domWaitFail(label?: string, err?: unknown): void;
102
- domChunk(length?: number, snippet?: string, paused?: boolean): void;
103
- streamChunk(length?: number, snippet?: string): void;
104
- streamEventsParsed(count?: number): void;
105
- streamCompleteEvent(): void;
106
- streamEnd(): void;
107
- responseWaitStart(label?: string): void;
108
- responseWaitSuccess(label?: string): void;
109
- responseWaitFail(label?: string, err?: unknown): void;
110
- responseWaitRetry(label?: string, attempt?: number): void;
111
- referenceExpandStart(label?: string): void;
112
- referenceExpandFail(err?: unknown): void;
113
- screenshotStart(): void;
114
- screenshotSuccess(): void;
115
- screenshotFail(err?: unknown): void;
116
- shareStart(): void;
117
- shareProgress(label?: string): void;
118
- shareDomHit(link?: string, domSnapshot?: string): void;
119
- shareSource(source?: 'response' | 'dom' | 'none' | string, link?: string, domSnapshot?: string): void;
120
- shareSuccess(link?: string): void;
121
- shareFail(err?: unknown): void;
122
- shareSkip(reason?: string): void;
123
- dataPushSuccess(label?: string): void;
124
- dataPushFail(err?: unknown): void;
125
- popupDetected(detail?: string): void;
126
- popupCloseAttempt(detail?: string): void;
127
- popupCloseSuccess(): void;
128
- popupCloseFail(err?: unknown): void;
129
- info(message: string): void;
130
- success(message: string): void;
131
- warning(message: string): void;
132
- warn(message: string): void;
133
- error(message: string): void;
134
- debug(message: string): void;
135
- start(message: string): void;
136
- }
137
-
138
- export interface LoggerAdapter {
139
- info(message: string): void;
140
- warning?(message: string): void;
141
- warn?(message: string): void;
142
- error(message: string): void;
143
- debug?(message: string): void;
144
- }
145
-
146
- export interface LoggerModule {
147
- info(message: string): void;
148
- success(message: string): void;
149
- warning(message: string): void;
150
- warn(message: string): void;
151
- error(message: string): void;
152
- debug(message: string): void;
153
- start(message: string): void;
154
- setLogger(logger: LoggerAdapter | null): void;
155
- useTemplate(logger?: LoggerAdapter | null): LoggerTemplate;
156
- }
157
-
158
- export interface LogTemplate {
159
- key: string;
160
- label: string;
161
- group: string;
162
- attention: 'low' | 'medium' | 'high' | 'critical';
163
- patterns: RegExp[];
164
- defaultSelected?: boolean;
165
- }
166
-
167
-
168
- // =============================================================================
169
- // ApifyKit
170
- // =============================================================================
171
- export interface RetryOptions {
172
- /** 重试次数 */
173
- times?: number;
174
- /** 重试模式: 'direct' 等待 3 秒后直接重试, 'refresh' 刷新页面后重试 */
175
- mode?: 'direct' | 'refresh';
176
- /** 重试前的自定义钩子,会替代默认的等待/刷新行为 */
177
- before?: (page: Page, attemptNumber: number) => Promise<void>;
178
- }
179
-
180
- export interface RunStepOptions {
181
- failActor?: boolean;
182
- /** 重试配置 */
183
- retry?: RetryOptions;
184
- }
185
-
186
- export interface ApifyKitInstance {
187
- runStep<T>(step: string, page: Page | null, actionFn: () => Promise<T>, options?: RunStepOptions): Promise<T>;
188
- runStepLoose<T>(step: string, page: Page | null, fn: () => Promise<T>, options?: RunStepOptions): Promise<T>;
189
- pushSuccess(data: Record<string, any>, options?: { page?: Page | null }): Promise<void>;
190
- pushFailed(error: Error | CrawlerError, meta?: Record<string, any>, options?: { page?: Page | null }): Promise<void>;
191
- }
192
-
193
- export interface ApifyKitModule {
194
- useApifyKit(): Promise<ApifyKitInstance>;
195
- }
196
-
197
- // =============================================================================
198
- // Humanize
199
- // =============================================================================
200
- export interface HumanTypeOptions {
201
- baseDelay?: number;
202
- jitterPercent?: number;
203
- }
204
-
205
- export interface HumanClickOptions {
206
- reactionDelay?: number;
207
- jitterPercent?: number;
208
- throwOnMissing?: boolean;
209
- scrollIfNeeded?: boolean;
210
- }
211
-
212
- export interface HumanizeModule {
213
- initializeCursor(page: Page): Promise<void>;
214
- jitterMs(base: number, jitterPercent?: number): number;
215
- humanType(page: Page, selector: string, text: string, options?: HumanTypeOptions): Promise<void>;
216
- humanClick(page: Page, target: string | ElementHandle, options?: HumanClickOptions): Promise<void>;
217
- warmUpBrowsing(page: Page, baseDuration?: number): Promise<void>;
218
- simulateGaze(page: Page, baseDurationMs?: number): Promise<void>;
219
- randomSleep(baseMs: number, jitterPercent?: number): Promise<void>;
220
- }
221
-
222
- // =============================================================================
223
- // AntiCheat
224
- // =============================================================================
225
- export interface AntiDetectConfig {
226
- locale: string;
227
- acceptLanguage: string;
228
- timezoneId: string;
229
- timezoneOffset: number;
230
- geolocation: { latitude: number; longitude: number; accuracy?: number } | null;
231
- }
232
-
233
- export interface AntiDetectApplyOptions {
234
- locale?: string;
235
- acceptLanguage?: string;
236
- timezoneId?: string;
237
- timezoneOffset?: number;
238
- geolocation?: { latitude: number; longitude: number; accuracy?: number } | null;
239
- permissions?: string[];
240
- }
241
-
242
- export interface AntiDetectModule {
243
- getBaseConfig(): AntiDetectConfig;
244
- getFingerprintGeneratorOptions(): Record<string, any>;
245
- getLaunchArgs(): string[];
246
- getAdvancedLaunchArgs(): string[];
247
- applyContext(context: BrowserContext, options?: AntiDetectApplyOptions): Promise<void>;
248
- applyPage(page: Page, options?: AntiDetectApplyOptions): Promise<void>;
249
- syncViewportWithScreen(page: Page): Promise<void>;
250
- getTlsFingerprintOptions(userAgent?: string, acceptLanguage?: string): Record<string, any>;
251
- applyLocaleHeaders(headers: Record<string, string>, acceptLanguage?: string): Record<string, string>;
252
- }
253
-
254
- // =============================================================================
255
- // Launch
256
- // =============================================================================
257
- export interface LaunchOptions {
258
- headless?: boolean;
259
- args?: string[];
260
- ignoreDefaultArgs?: string[];
261
- proxy?: {
262
- server: string;
263
- username?: string;
264
- password?: string;
265
- bypass?: string;
266
- };
267
- [key: string]: any;
268
- }
269
-
270
- export interface ProxyConfiguration {
271
- proxy_url?: string;
272
- by_pass_domains?: string[];
273
- enable_proxy?: boolean;
274
- }
275
-
276
- export interface CrawlerBaseOptions {
277
- maxConcurrency: number;
278
- maxRequestRetries: number;
279
- requestHandlerTimeoutSecs: number;
280
- navigationTimeoutSecs: number;
281
- headless: boolean;
282
- browserPoolOptions: {
283
- useFingerprints: boolean;
284
- fingerprintOptions: {
285
- fingerprintGeneratorOptions: Record<string, any>;
286
- };
287
- };
288
- launchContext: {
289
- launcher?: any;
290
- useIncognitoPages: boolean;
291
- launchOptions: LaunchOptions;
292
- };
293
- }
294
-
295
- export interface CrawlerNavigationHook {
296
- (crawlingContext: any, gotoOptions: Record<string, any>): Promise<void> | void;
297
- }
298
-
299
- export interface GetPlaywrightCrawlerOptionsInput {
300
- customArgs?: string[];
301
- proxyConfiguration?: ProxyConfiguration;
302
- log?: {
303
- enable: boolean;
304
- };
305
- runInHeadfulMode?: boolean;
306
- debugMode?: boolean;
307
- isRunningOnApify?: boolean;
308
- launcher?: any;
309
- runtimeState?: RuntimeEnvState | null;
310
- preNavigationHooks?: CrawlerNavigationHook[];
311
- postNavigationHooks?: CrawlerNavigationHook[];
312
- }
313
-
314
- export interface PlaywrightCrawlerOptions extends CrawlerBaseOptions {
315
- preNavigationHooks: CrawlerNavigationHook[];
316
- postNavigationHooks?: CrawlerNavigationHook[];
317
- }
318
-
319
- export interface LaunchModule {
320
- getPlaywrightCrawlerOptions(options?: GetPlaywrightCrawlerOptionsInput): PlaywrightCrawlerOptions;
321
- }
322
-
323
- // =============================================================================
324
- // LiveView
325
- // =============================================================================
326
- export interface LiveViewInstance {
327
- startLiveViewServer(): Promise<void>;
328
- takeLiveScreenshot(page: Page, label?: string): Promise<void>;
329
- }
330
-
331
- export interface LiveViewModule {
332
- useLiveView(): LiveViewInstance;
333
- }
334
-
335
- // =============================================================================
336
- // Captcha
337
- // =============================================================================
1
+ import type { Page, BrowserContext, Browser, ElementHandle } from 'playwright';
2
+
3
+ // =============================================================================
4
+ // Constants
5
+ // =============================================================================
6
+ export interface CodeType {
7
+ Success: 0;
8
+ UnknownError: -1;
9
+ NotLogin: 30000001;
10
+ Chaptcha: 30000002;
11
+ Timeout: 30000003;
12
+ InitialTimeout: 30000004;
13
+ OverallTimeout: 30000005;
14
+ }
15
+
16
+ export interface StatusType {
17
+ Success: 'SUCCESS';
18
+ Failed: 'FAILED';
19
+ }
20
+
21
+ export interface ConstantsModule {
22
+ Code: CodeType;
23
+ Status: StatusType;
24
+ PresetOfLiveViewKey: string;
25
+ ActorInfo: Record<string, ActorInfoItem>;
26
+ }
27
+
28
+ export interface ActorShareInfo {
29
+ mode: 'dom' | 'response';
30
+ prefix: string;
31
+ xurl: Array<string | string[]>;
32
+ }
33
+
34
+ export interface ActorInfoItem {
35
+ key: string;
36
+ name: string;
37
+ icon: string;
38
+ domain: string;
39
+ protocol: string;
40
+ path: string;
41
+ share: ActorShareInfo;
42
+ readonly landingUrl: string;
43
+ }
44
+
45
+ // =============================================================================
46
+ // Errors
47
+ // =============================================================================
48
+ export interface CrawlerErrorInfo {
49
+ message: string;
50
+ code?: number;
51
+ context?: Record<string, any>;
52
+ }
53
+
54
+ export declare class CrawlerError extends Error {
55
+ name: 'CrawlerError';
56
+ code: number;
57
+ context: Record<string, any>;
58
+ timestamp: string;
59
+
60
+ constructor(info: string | CrawlerErrorInfo);
61
+ toJSON(): Record<string, any>;
62
+ static isCrawlerError(error: any): error is CrawlerError;
63
+ static from(error: Error, options?: { code?: number; context?: Record<string, any> }): CrawlerError;
64
+ }
65
+
66
+ export interface ErrorsModule {
67
+ CrawlerError: typeof CrawlerError;
68
+ }
69
+
70
+ // =============================================================================
71
+ // Logger
72
+ // =============================================================================
73
+ export interface LoggerTemplate {
74
+ step(
75
+ step: string,
76
+ status?: string,
77
+ details?: string[],
78
+ level?: 'info' | 'warn' | 'warning' | 'error' | 'success' | 'start'
79
+ ): void;
80
+ taskStart(url?: string): void;
81
+ taskSuccess(): void;
82
+ taskFail(url?: string, err?: unknown): void;
83
+ runtimeHeadless(): void;
84
+ loginInjectSuccess(detail?: string): void;
85
+ loginInjectSkip(reason?: string): void;
86
+ loginInjectFail(err?: unknown): void;
87
+ loginVerifySuccess(detail?: string): void;
88
+ loginVerifySkip(reason?: string): void;
89
+ loginVerifyFail(err?: unknown): void;
90
+ envCheckSuccess(detail?: string): void;
91
+ envCheckFail(err?: unknown): void;
92
+ inputQuery(query?: string): void;
93
+ sendAction(): void;
94
+ responseListenStart(label?: string, timeoutSec?: number): void;
95
+ responseListenReady(label?: string): void;
96
+ responseListenDetected(label?: string): void;
97
+ responseListenTimeout(label?: string, err?: unknown): void;
98
+ responseListenEnd(label?: string): void;
99
+ domWaitStart(label?: string): void;
100
+ domWaitSuccess(mutationCount?: number, stableTime?: number, wasPaused?: boolean): void;
101
+ domWaitFail(label?: string, err?: unknown): void;
102
+ domChunk(length?: number, snippet?: string, paused?: boolean): void;
103
+ streamChunk(length?: number, snippet?: string): void;
104
+ streamEventsParsed(count?: number): void;
105
+ streamCompleteEvent(): void;
106
+ streamEnd(): void;
107
+ responseWaitStart(label?: string): void;
108
+ responseWaitSuccess(label?: string): void;
109
+ responseWaitFail(label?: string, err?: unknown): void;
110
+ responseWaitRetry(label?: string, attempt?: number): void;
111
+ referenceExpandStart(label?: string): void;
112
+ referenceExpandFail(err?: unknown): void;
113
+ screenshotStart(): void;
114
+ screenshotSuccess(): void;
115
+ screenshotFail(err?: unknown): void;
116
+ shareStart(): void;
117
+ shareProgress(label?: string): void;
118
+ shareDomHit(link?: string, domSnapshot?: string): void;
119
+ shareSource(source?: 'response' | 'dom' | 'none' | string, link?: string, domSnapshot?: string): void;
120
+ shareSuccess(link?: string): void;
121
+ shareFail(err?: unknown): void;
122
+ shareSkip(reason?: string): void;
123
+ dataPushSuccess(label?: string): void;
124
+ dataPushFail(err?: unknown): void;
125
+ popupDetected(detail?: string): void;
126
+ popupCloseAttempt(detail?: string): void;
127
+ popupCloseSuccess(): void;
128
+ popupCloseFail(err?: unknown): void;
129
+ info(message: string): void;
130
+ success(message: string): void;
131
+ warning(message: string): void;
132
+ warn(message: string): void;
133
+ error(message: string): void;
134
+ debug(message: string): void;
135
+ start(message: string): void;
136
+ }
137
+
138
+ export interface LoggerAdapter {
139
+ info(message: string): void;
140
+ warning?(message: string): void;
141
+ warn?(message: string): void;
142
+ error(message: string): void;
143
+ debug?(message: string): void;
144
+ }
145
+
146
+ export interface LoggerModule {
147
+ info(message: string): void;
148
+ success(message: string): void;
149
+ warning(message: string): void;
150
+ warn(message: string): void;
151
+ error(message: string): void;
152
+ debug(message: string): void;
153
+ start(message: string): void;
154
+ setLogger(logger: LoggerAdapter | null): void;
155
+ useTemplate(logger?: LoggerAdapter | null): LoggerTemplate;
156
+ }
157
+
158
+ export interface LogTemplate {
159
+ key: string;
160
+ label: string;
161
+ group: string;
162
+ attention: 'low' | 'medium' | 'high' | 'critical';
163
+ patterns: RegExp[];
164
+ defaultSelected?: boolean;
165
+ }
166
+
167
+
168
+ // =============================================================================
169
+ // ApifyKit
170
+ // =============================================================================
171
+ export interface RetryOptions {
172
+ /** 重试次数 */
173
+ times?: number;
174
+ /** 重试模式: 'direct' 等待 3 秒后直接重试, 'refresh' 刷新页面后重试 */
175
+ mode?: 'direct' | 'refresh';
176
+ /** 重试前的自定义钩子,会替代默认的等待/刷新行为 */
177
+ before?: (page: Page, attemptNumber: number) => Promise<void>;
178
+ }
179
+
180
+ export interface RunStepOptions {
181
+ failActor?: boolean;
182
+ /** 重试配置 */
183
+ retry?: RetryOptions;
184
+ }
185
+
186
+ export interface ApifyKitInstance {
187
+ runStep<T>(step: string, page: Page | null, actionFn: () => Promise<T>, options?: RunStepOptions): Promise<T>;
188
+ runStepLoose<T>(step: string, page: Page | null, fn: () => Promise<T>, options?: RunStepOptions): Promise<T>;
189
+ pushSuccess(data: Record<string, any>, options?: { page?: Page | null }): Promise<void>;
190
+ pushFailed(error: Error | CrawlerError, meta?: Record<string, any>, options?: { page?: Page | null }): Promise<void>;
191
+ }
192
+
193
+ export interface ApifyKitModule {
194
+ useApifyKit(): Promise<ApifyKitInstance>;
195
+ }
196
+
197
+ // =============================================================================
198
+ // Humanize
199
+ // =============================================================================
200
+ export interface HumanTypeOptions {
201
+ baseDelay?: number;
202
+ jitterPercent?: number;
203
+ }
204
+
205
+ export interface HumanClickOptions {
206
+ reactionDelay?: number;
207
+ jitterPercent?: number;
208
+ throwOnMissing?: boolean;
209
+ scrollIfNeeded?: boolean;
210
+ }
211
+
212
+ export interface HumanizeModule {
213
+ initializeCursor(page: Page): Promise<void>;
214
+ jitterMs(base: number, jitterPercent?: number): number;
215
+ humanType(page: Page, selector: string, text: string, options?: HumanTypeOptions): Promise<void>;
216
+ humanClick(page: Page, target: string | ElementHandle, options?: HumanClickOptions): Promise<void>;
217
+ warmUpBrowsing(page: Page, baseDuration?: number): Promise<void>;
218
+ simulateGaze(page: Page, baseDurationMs?: number): Promise<void>;
219
+ randomSleep(baseMs: number, jitterPercent?: number): Promise<void>;
220
+ }
221
+
222
+ // =============================================================================
223
+ // AntiCheat
224
+ // =============================================================================
225
+ export interface AntiDetectConfig {
226
+ locale: string;
227
+ acceptLanguage: string;
228
+ timezoneId: string;
229
+ timezoneOffset: number;
230
+ geolocation: { latitude: number; longitude: number; accuracy?: number } | null;
231
+ }
232
+
233
+ export interface AntiDetectApplyOptions {
234
+ locale?: string;
235
+ acceptLanguage?: string;
236
+ timezoneId?: string;
237
+ timezoneOffset?: number;
238
+ geolocation?: { latitude: number; longitude: number; accuracy?: number } | null;
239
+ permissions?: string[];
240
+ }
241
+
242
+ export interface AntiDetectModule {
243
+ getBaseConfig(): AntiDetectConfig;
244
+ getFingerprintGeneratorOptions(): Record<string, any>;
245
+ getLaunchArgs(): string[];
246
+ getAdvancedLaunchArgs(): string[];
247
+ applyContext(context: BrowserContext, options?: AntiDetectApplyOptions): Promise<void>;
248
+ applyPage(page: Page, options?: AntiDetectApplyOptions): Promise<void>;
249
+ syncViewportWithScreen(page: Page): Promise<void>;
250
+ getTlsFingerprintOptions(userAgent?: string, acceptLanguage?: string): Record<string, any>;
251
+ applyLocaleHeaders(headers: Record<string, string>, acceptLanguage?: string): Record<string, string>;
252
+ }
253
+
254
+ // =============================================================================
255
+ // Launch
256
+ // =============================================================================
257
+ export interface LaunchOptions {
258
+ headless?: boolean;
259
+ args?: string[];
260
+ ignoreDefaultArgs?: string[];
261
+ proxy?: {
262
+ server: string;
263
+ username?: string;
264
+ password?: string;
265
+ bypass?: string;
266
+ };
267
+ [key: string]: any;
268
+ }
269
+
270
+ export interface ProxyConfiguration {
271
+ proxy_url?: string;
272
+ by_pass_domains?: string[];
273
+ enable_proxy?: boolean;
274
+ }
275
+
276
+ export interface CrawlerBaseOptions {
277
+ maxConcurrency: number;
278
+ maxRequestRetries: number;
279
+ requestHandlerTimeoutSecs: number;
280
+ navigationTimeoutSecs: number;
281
+ headless: boolean;
282
+ browserPoolOptions: {
283
+ useFingerprints: boolean;
284
+ fingerprintOptions: {
285
+ fingerprintGeneratorOptions: Record<string, any>;
286
+ };
287
+ };
288
+ launchContext: {
289
+ launcher?: any;
290
+ useIncognitoPages: boolean;
291
+ launchOptions: LaunchOptions;
292
+ };
293
+ }
294
+
295
+ export interface CrawlerNavigationHook {
296
+ (crawlingContext: any, gotoOptions: Record<string, any>): Promise<void> | void;
297
+ }
298
+
299
+ export interface GetPlaywrightCrawlerOptionsInput {
300
+ customArgs?: string[];
301
+ proxyConfiguration?: ProxyConfiguration;
302
+ log?: {
303
+ enable: boolean;
304
+ };
305
+ runInHeadfulMode?: boolean;
306
+ debugMode?: boolean;
307
+ isRunningOnApify?: boolean;
308
+ launcher?: any;
309
+ runtimeState?: RuntimeEnvState | null;
310
+ preNavigationHooks?: CrawlerNavigationHook[];
311
+ postNavigationHooks?: CrawlerNavigationHook[];
312
+ }
313
+
314
+ export interface PlaywrightCrawlerOptions extends CrawlerBaseOptions {
315
+ preNavigationHooks: CrawlerNavigationHook[];
316
+ postNavigationHooks?: CrawlerNavigationHook[];
317
+ }
318
+
319
+ export interface LaunchModule {
320
+ getPlaywrightCrawlerOptions(options?: GetPlaywrightCrawlerOptionsInput): PlaywrightCrawlerOptions;
321
+ }
322
+
323
+ // =============================================================================
324
+ // LiveView
325
+ // =============================================================================
326
+ export interface LiveViewInstance {
327
+ startLiveViewServer(): Promise<void>;
328
+ takeLiveScreenshot(page: Page, label?: string): Promise<void>;
329
+ }
330
+
331
+ export interface LiveViewModule {
332
+ useLiveView(): LiveViewInstance;
333
+ }
334
+
335
+ // =============================================================================
336
+ // Captcha
337
+ // =============================================================================
338
338
  export interface CaptchaMonitorOptions {
339
339
  domSelector?: string;
340
340
  urlPattern?: string;
341
341
  onDetected?: () => Promise<void>;
342
342
  }
343
343
 
344
- export interface SolveBytedanceCaptchaOptions {
345
- token?: string;
346
- maxRetries?: number;
347
- apiUrl?: string;
348
- apiType?: string;
349
- containerSelector?: string;
350
- iframeSelector?: string;
351
- iframeFallbackSelector?: string;
352
- sourceImageSelector?: string;
353
- dropTargetContainerSelector?: string;
354
- dropTargetTexts?: string[];
355
- refreshTexts?: string[];
356
- submitTexts?: string[];
357
- recognitionSuccessCode?: number;
358
- containerVisibleTimeoutMs?: number;
359
- iframeVisibleTimeoutMs?: number;
360
- iframeFallbackVisibleTimeoutMs?: number;
361
- contentFrameResolveRetries?: number;
362
- contentFrameResolveDelayMs?: number;
363
- actionVisibleTimeoutMs?: number;
364
- sourceImageVisibleTimeoutMs?: number;
365
- recognitionDelayMs?: number;
366
- refreshWaitMs?: number;
367
- submitWaitMs?: number;
368
- retryDelayBaseMs?: number;
369
- retryDelayStepMs?: number;
370
- }
371
-
372
344
  export interface CaptchaModule {
373
345
  useCaptchaMonitor(page: Page, options: CaptchaMonitorOptions): { stop: () => Promise<void> };
374
- solveBytedanceCaptcha(page: Page, options?: SolveBytedanceCaptchaOptions): Promise<boolean>;
375
- }
376
-
377
- // =============================================================================
378
- // Utils
379
- // =============================================================================
380
- export interface ParsedCookie {
381
- name: string;
382
- value: string;
383
- domain: string;
384
- path?: string;
385
- }
386
-
387
- export interface UtilsModule {
388
- parseCookies(cookieString: string, domain: string): ParsedCookie[];
389
- parseLinks(text: string, options?: { prefix?: string }): string[];
390
- }
391
-
392
- export interface RuntimeEnvState {
393
- actor: string;
394
- runtime: Record<string, any>;
395
- envId: string;
396
- auth: Record<string, string>;
397
- cookies: ParsedCookie[];
398
- cookieMap: Record<string, string>;
399
- localStorage: Record<string, string>;
400
- sessionStorage: Record<string, string>;
401
- browserProfile: {
402
- core?: Record<string, any>;
403
- observed?: Record<string, any>;
404
- };
405
- browserProfileCore: Record<string, any>;
406
- browserProfileObserved: Record<string, any>;
407
- }
408
-
409
- export interface RuntimeEnvApplyOptions {
410
- actor?: string;
411
- }
412
-
413
- export interface RuntimeEnvSnapshot {
414
- page_url?: string;
415
- pageUrl?: string;
416
- frame_urls?: string[];
417
- frameUrls?: string[];
418
- resource_urls?: string[];
419
- resourceUrls?: string[];
420
- cookies?: Array<Record<string, any>>;
421
- local_storage?: Record<string, any>;
422
- localStorage?: Record<string, any>;
423
- session_storage?: Record<string, any>;
424
- sessionStorage?: Record<string, any>;
425
- browser_profile?: Record<string, any>;
426
- browserProfile?: Record<string, any>;
427
- browser_profile_observed?: Record<string, any>;
428
- browserProfileObserved?: Record<string, any>;
429
- auth?: Record<string, any>;
430
- }
431
-
432
- export interface RuntimeEnvModule {
433
- parseInput(input?: Record<string, any>, actor?: string): RuntimeEnvState;
434
- buildEnvPatch(source?: Record<string, any>, actor?: string): Record<string, any> | null;
435
- normalizeSnapshot(snapshot?: RuntimeEnvSnapshot): RuntimeEnvSnapshot;
436
- collectCookieUrls(snapshot?: RuntimeEnvSnapshot): string[];
437
- buildRuntimeEnvFromSnapshot(snapshot?: RuntimeEnvSnapshot, options?: { browserProfileCore?: Record<string, any>; auth?: Record<string, any> }): Record<string, any> | null;
438
- buildEnvPatchFromSnapshot(snapshot?: RuntimeEnvSnapshot, options?: { browserProfileCore?: Record<string, any>; auth?: Record<string, any> }): Record<string, any> | null;
439
- mergeEnvPatches(...patches: Array<Record<string, any> | null | undefined>): Record<string, any> | null;
440
- hasLoginState(source?: Record<string, any>, actor?: string): boolean;
441
- getAuthValue(source?: Record<string, any>, key?: string, actor?: string): string;
442
- rememberState(source?: Record<string, any>): RuntimeEnvState | null;
443
- peekRememberedState(): RuntimeEnvState | null;
444
- getBrowserProfileCore(source?: Record<string, any>, actor?: string): Record<string, any>;
445
- setBrowserProfileCore(source?: Record<string, any>, core?: Record<string, any>, actor?: string): RuntimeEnvState;
446
- applyToPage(page: Page, source?: Record<string, any>, options?: RuntimeEnvApplyOptions): Promise<void>;
447
- captureEnvPatch(page: Page | null, source?: Record<string, any>, options?: RuntimeEnvApplyOptions): Promise<Record<string, any> | null>;
448
- tryParseJSON(value: any): any;
449
- normalizeCookies(value: any): ParsedCookie[];
450
- normalizeLocalStorage(value: any): Record<string, string>;
451
- normalizeSessionStorage(value: any): Record<string, string>;
452
- normalizeAuth(value: any): Record<string, string>;
453
- normalizeBrowserProfileCore(value: any): Record<string, any>;
454
- normalizeObservedBrowserProfile(value: any): Record<string, any>;
455
- }
456
-
457
- // =============================================================================
458
- // Share
459
- // =============================================================================
460
- export interface ShareLinkCaptureOptions {
461
- share: {
462
- mode?: 'dom' | 'response';
463
- /** 允许空串 '',但不允许 undefined/null */
464
- prefix: string;
465
- xurl?: Array<string | string[]>;
466
- };
467
- timeoutMs?: number;
468
- payloadSnapshotMaxLen?: number;
469
- domSelectors?: string | string[];
470
- domMode?: 'added' | 'changed' | 'all';
471
- performActions?: () => Promise<void>;
472
- }
473
-
474
- export interface ShareLinkCaptureResult {
475
- link: string | null;
476
- payloadText: string;
477
- payloadSnapshot: string;
478
- source: 'response' | 'dom' | 'none';
479
- }
480
-
481
- export interface ShareScreenCaptureOptions {
482
- /** 额外缓冲高度 (默认: 视口高度的一半) */
483
- buffer?: number;
484
- /** 截图后是否恢复页面高度和样式 (默认: false) */
485
- restore?: boolean;
486
- /** 最大截图高度 (默认: 8000px) */
487
- maxHeight?: number;
488
- }
489
-
490
- export interface ShareModule {
491
- captureLink(page: Page, options?: ShareLinkCaptureOptions): Promise<ShareLinkCaptureResult>;
492
- captureScreen(page: Page, options?: ShareScreenCaptureOptions): Promise<string>;
493
- }
494
-
495
- // =============================================================================
496
- // Display
497
- // =============================================================================
498
- export interface DisplayModule {
499
- parseTokenDisplayName(value?: string): { owner: string; envType: string; note: string };
500
- parseEnvDisplayName(value?: string): { env: string; owner: string; envType: string; note: string };
501
- buildTokenDisplayName(input: { owner: string; envType: string; note?: string }): string;
502
- shortId(value?: string, max?: number): string;
503
- resolveTokenIdentity(
504
- displayName?: string,
505
- tokenId?: string
506
- ): { primary: string; secondary: string; fullId: string; shortId: string };
507
- resolveEnvIdentity(
508
- displayName?: string,
509
- envId?: string
510
- ): { primary: string; secondary: string; fullId: string; shortId: string; parts: { env: string; owner: string; envType: string; note: string } };
511
- }
512
-
513
- // =============================================================================
514
- // Mutation
515
- // =============================================================================
516
- export interface MutationNodeSnapshot {
517
- /** 节点 HTML 快照(实际来源 outerHTML) */
518
- html: string;
519
- /** 节点文本快照(实际来源 innerText/textContent) */
520
- text: string;
521
- /** 变化类型 */
522
- mutationType: string;
523
- }
524
-
525
- export interface OnMutationContext {
526
- /** 当前累计变化次数 */
527
- mutationCount: number;
528
- /** 本次变化节点聚合 HTML(实际来源 outerHTML) */
529
- html: string;
530
- /** 本次变化节点聚合文本(实际来源 innerText) */
531
- text: string;
532
- /** 本次全部变化节点快照 */
533
- mutationNodes: MutationNodeSnapshot[];
534
- }
535
-
536
- export interface WaitForStableOptions {
537
- /** 等待元素出现的超时 (毫秒, 默认: 30000) */
538
- initialTimeout?: number;
539
- /** 无变化持续时间后 resolve (毫秒, 默认: 5000) */
540
- stableTime?: number;
541
- /** 整体超时时间 (毫秒, 默认: 120000) */
542
- timeout?: number;
543
- /** 变化时的回调钩子
544
- * 返回 null/undefined: 正常重置稳定计时
545
- * 返回其他值: 暂停稳定计时(timeout 仍然生效)
546
- */
547
- onMutation?: (context: OnMutationContext) => any;
548
- }
549
-
550
- export interface WaitForStableResult {
551
- /** 总变化次数 */
552
- mutationCount: number;
553
- /** 稳定时长 */
554
- stableTime: number;
555
- /** 是否曾经暂停过计时 */
556
- wasPaused: boolean;
557
- }
558
-
559
- export type MutationMonitorMode = 'added' | 'changed' | 'all';
560
-
561
- export interface MutationModeConstants {
562
- Added: 'added';
563
- Changed: 'changed';
564
- All: 'all';
565
- }
566
-
567
- export interface useMonitorOptions {
568
- /** 变化时的回调 */
569
- onMutation?: (context: OnMutationContext) => void;
570
- /** 监控模式 (默认 'added') */
571
- mode?: MutationMonitorMode;
572
- }
573
-
574
- export interface MutationMonitor {
575
- /** 停止监控并返回统计 */
576
- stop: () => Promise<{ totalMutations: number }>;
577
- }
578
-
579
- export interface MutationModule {
580
- /** 监控模式常量 */
581
- Mode: MutationModeConstants;
582
- /** 等待 DOM 元素稳定(无变化) */
583
- waitForStable(page: Page, selectors: string | string[], options?: WaitForStableOptions): Promise<WaitForStableResult>;
584
- /** 等待跨 root DOM 元素稳定(主文档 + iframe 内容) */
585
- waitForStableAcrossRoots(page: Page, selectors: string | string[], options?: WaitForStableOptions): Promise<WaitForStableResult>;
586
- /** 创建持续监控 DOM 变化的监控器,selectors 支持 'document.documentElement' */
587
- useMonitor(page: Page, selectors: string | string[], options?: useMonitorOptions): Promise<MutationMonitor>;
588
- }
589
-
590
- // =============================================================================
591
- // ByPass Matcher
592
- // =============================================================================
593
- export interface ByPassDomainRule {
594
- pattern: string;
595
- test(hostname: string): boolean;
596
- }
597
-
598
- export interface ByPassMatchResult {
599
- rule: ByPassDomainRule | null;
600
- hostname: string;
601
- }
602
-
603
- export interface ByPassRouteResult {
604
- route: 'direct' | 'proxy';
605
- matchedRule: ByPassDomainRule | null;
606
- hostname: string;
607
- }
608
-
609
- export interface ResolveRouteByProxyInput {
610
- requestUrl?: string;
611
- enableProxy?: boolean;
612
- byPassRules?: ByPassDomainRule[];
613
- }
614
-
615
- export interface ByPassModule {
616
- normalizeByPassDomains(domains: unknown): string[];
617
- normalizeHostname(value?: string): string;
618
- buildByPassDomainRule(rawPattern: string): ByPassDomainRule | null;
619
- buildByPassDomainRules(domains?: unknown): ByPassDomainRule[];
620
- findMatchedByPassRule(rules?: ByPassDomainRule[], requestUrl?: string): ByPassMatchResult | null;
621
- isDomainCoveredByByPass(domain?: string, rules?: ByPassDomainRule[]): boolean;
622
- resolveRouteByProxy(input?: ResolveRouteByProxyInput): ByPassRouteResult;
623
- }
624
-
625
- // =============================================================================
626
- // Toolkit Entry Point
627
- // =============================================================================
628
-
629
- /** Node.js version of the toolkit */
630
- export interface PlaywrightToolKit {
631
- ApifyKit: ApifyKitModule;
632
- AntiCheat: AntiDetectModule;
633
- Humanize: HumanizeModule;
634
- Launch: LaunchModule;
635
- LiveView: LiveViewModule;
636
- Constants: ConstantsModule;
637
- Utils: UtilsModule;
638
- RuntimeEnv: RuntimeEnvModule;
639
- Display: DisplayModule;
640
- Captcha: CaptchaModule;
641
- Errors: ErrorsModule;
642
- Mutation: MutationModule;
643
- ByPass: ByPassModule;
644
- Logger: LoggerModule;
645
- Share: ShareModule;
646
- $Internals: {
647
- LOG_TEMPLATES: LogTemplate[];
648
- stripAnsi(input: string): string;
649
- };
650
- }
651
-
652
- /** Browser/Extension version of the toolkit */
653
- export interface BrowserPlaywrightToolKit {
654
- Logger: LoggerModule;
655
- Display: DisplayModule;
656
- ByPass: ByPassModule;
657
- Constants: ConstantsModule;
658
- RuntimeEnv: RuntimeEnvModule;
659
- $Internals: {
660
- LOG_TEMPLATES: LogTemplate[];
661
- stripAnsi(input: string): string;
662
- };
663
- }
664
-
665
- export declare function usePlaywrightToolKit(): PlaywrightToolKit;
346
+ }
347
+
348
+ // =============================================================================
349
+ // Utils
350
+ // =============================================================================
351
+ export interface ParsedCookie {
352
+ name: string;
353
+ value: string;
354
+ domain: string;
355
+ path?: string;
356
+ }
357
+
358
+ export interface UtilsModule {
359
+ parseCookies(cookieString: string, domain: string): ParsedCookie[];
360
+ parseLinks(text: string, options?: { prefix?: string }): string[];
361
+ }
362
+
363
+ export interface RuntimeEnvState {
364
+ actor: string;
365
+ runtime: Record<string, any>;
366
+ envId: string;
367
+ auth: Record<string, string>;
368
+ cookies: ParsedCookie[];
369
+ cookieMap: Record<string, string>;
370
+ localStorage: Record<string, string>;
371
+ sessionStorage: Record<string, string>;
372
+ browserProfile: {
373
+ core?: Record<string, any>;
374
+ observed?: Record<string, any>;
375
+ };
376
+ browserProfileCore: Record<string, any>;
377
+ browserProfileObserved: Record<string, any>;
378
+ }
379
+
380
+ export interface RuntimeEnvApplyOptions {
381
+ actor?: string;
382
+ }
383
+
384
+ export interface RuntimeEnvSnapshot {
385
+ page_url?: string;
386
+ pageUrl?: string;
387
+ frame_urls?: string[];
388
+ frameUrls?: string[];
389
+ resource_urls?: string[];
390
+ resourceUrls?: string[];
391
+ cookies?: Array<Record<string, any>>;
392
+ local_storage?: Record<string, any>;
393
+ localStorage?: Record<string, any>;
394
+ session_storage?: Record<string, any>;
395
+ sessionStorage?: Record<string, any>;
396
+ browser_profile?: Record<string, any>;
397
+ browserProfile?: Record<string, any>;
398
+ browser_profile_observed?: Record<string, any>;
399
+ browserProfileObserved?: Record<string, any>;
400
+ auth?: Record<string, any>;
401
+ }
402
+
403
+ export interface RuntimeEnvModule {
404
+ parseInput(input?: Record<string, any>, actor?: string): RuntimeEnvState;
405
+ buildEnvPatch(source?: Record<string, any>, actor?: string): Record<string, any> | null;
406
+ normalizeSnapshot(snapshot?: RuntimeEnvSnapshot): RuntimeEnvSnapshot;
407
+ collectCookieUrls(snapshot?: RuntimeEnvSnapshot): string[];
408
+ buildRuntimeEnvFromSnapshot(snapshot?: RuntimeEnvSnapshot, options?: { browserProfileCore?: Record<string, any>; auth?: Record<string, any> }): Record<string, any> | null;
409
+ buildEnvPatchFromSnapshot(snapshot?: RuntimeEnvSnapshot, options?: { browserProfileCore?: Record<string, any>; auth?: Record<string, any> }): Record<string, any> | null;
410
+ mergeEnvPatches(...patches: Array<Record<string, any> | null | undefined>): Record<string, any> | null;
411
+ hasLoginState(source?: Record<string, any>, actor?: string): boolean;
412
+ getAuthValue(source?: Record<string, any>, key?: string, actor?: string): string;
413
+ rememberState(source?: Record<string, any>): RuntimeEnvState | null;
414
+ peekRememberedState(): RuntimeEnvState | null;
415
+ getBrowserProfileCore(source?: Record<string, any>, actor?: string): Record<string, any>;
416
+ setBrowserProfileCore(source?: Record<string, any>, core?: Record<string, any>, actor?: string): RuntimeEnvState;
417
+ applyToPage(page: Page, source?: Record<string, any>, options?: RuntimeEnvApplyOptions): Promise<void>;
418
+ captureEnvPatch(page: Page | null, source?: Record<string, any>, options?: RuntimeEnvApplyOptions): Promise<Record<string, any> | null>;
419
+ tryParseJSON(value: any): any;
420
+ normalizeCookies(value: any): ParsedCookie[];
421
+ normalizeLocalStorage(value: any): Record<string, string>;
422
+ normalizeSessionStorage(value: any): Record<string, string>;
423
+ normalizeAuth(value: any): Record<string, string>;
424
+ normalizeBrowserProfileCore(value: any): Record<string, any>;
425
+ normalizeObservedBrowserProfile(value: any): Record<string, any>;
426
+ }
427
+
428
+ // =============================================================================
429
+ // Share
430
+ // =============================================================================
431
+ export interface ShareLinkCaptureOptions {
432
+ share: {
433
+ mode?: 'dom' | 'response';
434
+ /** 允许空串 '',但不允许 undefined/null */
435
+ prefix: string;
436
+ xurl?: Array<string | string[]>;
437
+ };
438
+ timeoutMs?: number;
439
+ payloadSnapshotMaxLen?: number;
440
+ domSelectors?: string | string[];
441
+ domMode?: 'added' | 'changed' | 'all';
442
+ performActions?: () => Promise<void>;
443
+ }
444
+
445
+ export interface ShareLinkCaptureResult {
446
+ link: string | null;
447
+ payloadText: string;
448
+ payloadSnapshot: string;
449
+ source: 'response' | 'dom' | 'none';
450
+ }
451
+
452
+ export interface ShareScreenCaptureOptions {
453
+ /** 额外缓冲高度 (默认: 视口高度的一半) */
454
+ buffer?: number;
455
+ /** 截图后是否恢复页面高度和样式 (默认: false) */
456
+ restore?: boolean;
457
+ /** 最大截图高度 (默认: 8000px) */
458
+ maxHeight?: number;
459
+ }
460
+
461
+ export interface ShareModule {
462
+ captureLink(page: Page, options?: ShareLinkCaptureOptions): Promise<ShareLinkCaptureResult>;
463
+ captureScreen(page: Page, options?: ShareScreenCaptureOptions): Promise<string>;
464
+ }
465
+
466
+ // =============================================================================
467
+ // Display
468
+ // =============================================================================
469
+ export interface DisplayModule {
470
+ parseTokenDisplayName(value?: string): { owner: string; envType: string; note: string };
471
+ parseEnvDisplayName(value?: string): { env: string; owner: string; envType: string; note: string };
472
+ buildTokenDisplayName(input: { owner: string; envType: string; note?: string }): string;
473
+ shortId(value?: string, max?: number): string;
474
+ resolveTokenIdentity(
475
+ displayName?: string,
476
+ tokenId?: string
477
+ ): { primary: string; secondary: string; fullId: string; shortId: string };
478
+ resolveEnvIdentity(
479
+ displayName?: string,
480
+ envId?: string
481
+ ): { primary: string; secondary: string; fullId: string; shortId: string; parts: { env: string; owner: string; envType: string; note: string } };
482
+ }
483
+
484
+ // =============================================================================
485
+ // Mutation
486
+ // =============================================================================
487
+ export interface MutationNodeSnapshot {
488
+ /** 节点 HTML 快照(实际来源 outerHTML) */
489
+ html: string;
490
+ /** 节点文本快照(实际来源 innerText/textContent) */
491
+ text: string;
492
+ /** 变化类型 */
493
+ mutationType: string;
494
+ }
495
+
496
+ export interface OnMutationContext {
497
+ /** 当前累计变化次数 */
498
+ mutationCount: number;
499
+ /** 本次变化节点聚合 HTML(实际来源 outerHTML) */
500
+ html: string;
501
+ /** 本次变化节点聚合文本(实际来源 innerText) */
502
+ text: string;
503
+ /** 本次全部变化节点快照 */
504
+ mutationNodes: MutationNodeSnapshot[];
505
+ }
506
+
507
+ export interface WaitForStableOptions {
508
+ /** 等待元素出现的超时 (毫秒, 默认: 30000) */
509
+ initialTimeout?: number;
510
+ /** 无变化持续时间后 resolve (毫秒, 默认: 5000) */
511
+ stableTime?: number;
512
+ /** 整体超时时间 (毫秒, 默认: 120000) */
513
+ timeout?: number;
514
+ /** 变化时的回调钩子
515
+ * 返回 null/undefined: 正常重置稳定计时
516
+ * 返回其他值: 暂停稳定计时(timeout 仍然生效)
517
+ */
518
+ onMutation?: (context: OnMutationContext) => any;
519
+ }
520
+
521
+ export interface WaitForStableResult {
522
+ /** 总变化次数 */
523
+ mutationCount: number;
524
+ /** 稳定时长 */
525
+ stableTime: number;
526
+ /** 是否曾经暂停过计时 */
527
+ wasPaused: boolean;
528
+ }
529
+
530
+ export type MutationMonitorMode = 'added' | 'changed' | 'all';
531
+
532
+ export interface MutationModeConstants {
533
+ Added: 'added';
534
+ Changed: 'changed';
535
+ All: 'all';
536
+ }
537
+
538
+ export interface useMonitorOptions {
539
+ /** 变化时的回调 */
540
+ onMutation?: (context: OnMutationContext) => void;
541
+ /** 监控模式 (默认 'added') */
542
+ mode?: MutationMonitorMode;
543
+ }
544
+
545
+ export interface MutationMonitor {
546
+ /** 停止监控并返回统计 */
547
+ stop: () => Promise<{ totalMutations: number }>;
548
+ }
549
+
550
+ export interface MutationModule {
551
+ /** 监控模式常量 */
552
+ Mode: MutationModeConstants;
553
+ /** 等待 DOM 元素稳定(无变化) */
554
+ waitForStable(page: Page, selectors: string | string[], options?: WaitForStableOptions): Promise<WaitForStableResult>;
555
+ /** 等待跨 root DOM 元素稳定(主文档 + iframe 内容) */
556
+ waitForStableAcrossRoots(page: Page, selectors: string | string[], options?: WaitForStableOptions): Promise<WaitForStableResult>;
557
+ /** 创建持续监控 DOM 变化的监控器,selectors 支持 'document.documentElement' */
558
+ useMonitor(page: Page, selectors: string | string[], options?: useMonitorOptions): Promise<MutationMonitor>;
559
+ }
560
+
561
+ // =============================================================================
562
+ // ByPass Matcher
563
+ // =============================================================================
564
+ export interface ByPassDomainRule {
565
+ pattern: string;
566
+ test(hostname: string): boolean;
567
+ }
568
+
569
+ export interface ByPassMatchResult {
570
+ rule: ByPassDomainRule | null;
571
+ hostname: string;
572
+ }
573
+
574
+ export interface ByPassRouteResult {
575
+ route: 'direct' | 'proxy';
576
+ matchedRule: ByPassDomainRule | null;
577
+ hostname: string;
578
+ }
579
+
580
+ export interface ResolveRouteByProxyInput {
581
+ requestUrl?: string;
582
+ enableProxy?: boolean;
583
+ byPassRules?: ByPassDomainRule[];
584
+ }
585
+
586
+ export interface ByPassModule {
587
+ normalizeByPassDomains(domains: unknown): string[];
588
+ normalizeHostname(value?: string): string;
589
+ buildByPassDomainRule(rawPattern: string): ByPassDomainRule | null;
590
+ buildByPassDomainRules(domains?: unknown): ByPassDomainRule[];
591
+ findMatchedByPassRule(rules?: ByPassDomainRule[], requestUrl?: string): ByPassMatchResult | null;
592
+ isDomainCoveredByByPass(domain?: string, rules?: ByPassDomainRule[]): boolean;
593
+ resolveRouteByProxy(input?: ResolveRouteByProxyInput): ByPassRouteResult;
594
+ }
595
+
596
+ // =============================================================================
597
+ // Toolkit Entry Point
598
+ // =============================================================================
599
+
600
+ /** Node.js version of the toolkit */
601
+ export interface PlaywrightToolKit {
602
+ ApifyKit: ApifyKitModule;
603
+ AntiCheat: AntiDetectModule;
604
+ Humanize: HumanizeModule;
605
+ Launch: LaunchModule;
606
+ LiveView: LiveViewModule;
607
+ Constants: ConstantsModule;
608
+ Utils: UtilsModule;
609
+ RuntimeEnv: RuntimeEnvModule;
610
+ Display: DisplayModule;
611
+ Captcha: CaptchaModule;
612
+ Errors: ErrorsModule;
613
+ Mutation: MutationModule;
614
+ ByPass: ByPassModule;
615
+ Logger: LoggerModule;
616
+ Share: ShareModule;
617
+ $Internals: {
618
+ LOG_TEMPLATES: LogTemplate[];
619
+ stripAnsi(input: string): string;
620
+ };
621
+ }
622
+
623
+ /** Browser/Extension version of the toolkit */
624
+ export interface BrowserPlaywrightToolKit {
625
+ Logger: LoggerModule;
626
+ Display: DisplayModule;
627
+ ByPass: ByPassModule;
628
+ Constants: ConstantsModule;
629
+ RuntimeEnv: RuntimeEnvModule;
630
+ $Internals: {
631
+ LOG_TEMPLATES: LogTemplate[];
632
+ stripAnsi(input: string): string;
633
+ };
634
+ }
635
+
636
+ export declare function usePlaywrightToolKit(): PlaywrightToolKit;