@skrillex1224/playwright-toolkit 2.0.44 → 2.0.46
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 +174 -0
- package/package.json +4 -1
package/index.d.ts
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
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
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface StatusType {
|
|
14
|
+
Success: 'SUCCESS';
|
|
15
|
+
Failed: 'FAILED';
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface ConstantsModule {
|
|
19
|
+
Code: CodeType;
|
|
20
|
+
Status: StatusType;
|
|
21
|
+
FAILED_KEY_SEPARATOR: string;
|
|
22
|
+
PresetOfLiveViewKey: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// =============================================================================
|
|
26
|
+
// Errors
|
|
27
|
+
// =============================================================================
|
|
28
|
+
export interface CrawlerErrorInfo {
|
|
29
|
+
message: string;
|
|
30
|
+
code?: number;
|
|
31
|
+
context?: Record<string, any>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export declare class CrawlerError extends Error {
|
|
35
|
+
name: 'CrawlerError';
|
|
36
|
+
code: number;
|
|
37
|
+
context: Record<string, any>;
|
|
38
|
+
timestamp: string;
|
|
39
|
+
|
|
40
|
+
constructor(info: string | CrawlerErrorInfo);
|
|
41
|
+
toJSON(): Record<string, any>;
|
|
42
|
+
static isCrawlerError(error: any): error is CrawlerError;
|
|
43
|
+
static from(error: Error, options?: { code?: number; context?: Record<string, any> }): CrawlerError;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface ErrorsModule {
|
|
47
|
+
CrawlerError: typeof CrawlerError;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// =============================================================================
|
|
51
|
+
// ApifyKit
|
|
52
|
+
// =============================================================================
|
|
53
|
+
export interface RunStepOptions {
|
|
54
|
+
failActor?: boolean;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface ApifyKitInstance {
|
|
58
|
+
runStep<T>(step: string, page: Page | null, actionFn: () => Promise<T>, options?: RunStepOptions): Promise<T>;
|
|
59
|
+
runStepLoose<T>(step: string, page: Page | null, fn: () => Promise<T>): Promise<T>;
|
|
60
|
+
pushSuccess(data: Record<string, any>): Promise<void>;
|
|
61
|
+
pushFailed(error: Error | CrawlerError, meta?: Record<string, any>): Promise<void>;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface ApifyKitModule {
|
|
65
|
+
useApifyKit(): Promise<ApifyKitInstance>;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// =============================================================================
|
|
69
|
+
// Humanize
|
|
70
|
+
// =============================================================================
|
|
71
|
+
export interface HumanTypeOptions {
|
|
72
|
+
baseDelay?: number;
|
|
73
|
+
jitterPercent?: number;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface HumanClickOptions {
|
|
77
|
+
reactionDelay?: number;
|
|
78
|
+
jitterPercent?: number;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface HumanizeModule {
|
|
82
|
+
initializeCursor(page: Page): Promise<void>;
|
|
83
|
+
jitterMs(base: number, jitterPercent?: number): number;
|
|
84
|
+
humanType(page: Page, selector: string, text: string, options?: HumanTypeOptions): Promise<void>;
|
|
85
|
+
humanClick(page: Page, target: string | ElementHandle, options?: HumanClickOptions): Promise<void>;
|
|
86
|
+
warmUpBrowsing(page: Page, baseDuration?: number): Promise<void>;
|
|
87
|
+
naturalScroll(page: Page, direction?: 'up' | 'down', distance?: number, steps?: number): Promise<void>;
|
|
88
|
+
simulateGaze(page: Page, baseDurationMs?: number): Promise<void>;
|
|
89
|
+
randomSleep(baseMs: number, jitterPercent?: number): Promise<void>;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// =============================================================================
|
|
93
|
+
// Stealth
|
|
94
|
+
// =============================================================================
|
|
95
|
+
export interface StealthModule {
|
|
96
|
+
syncViewportWithScreen(page: Page): Promise<void>;
|
|
97
|
+
hideWebdriver(page: Page): Promise<void>;
|
|
98
|
+
setupBlockingResources(page: Page, types?: string[]): Promise<void>;
|
|
99
|
+
setChinaTimezone(context: BrowserContext): Promise<void>;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// =============================================================================
|
|
103
|
+
// Launch
|
|
104
|
+
// =============================================================================
|
|
105
|
+
export interface LaunchOptions {
|
|
106
|
+
headless?: boolean;
|
|
107
|
+
args?: string[];
|
|
108
|
+
ignoreDefaultArgs?: string[];
|
|
109
|
+
[key: string]: any;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export interface LaunchModule {
|
|
113
|
+
createStealthChromium(chromium: any, stealthPlugin: any): any;
|
|
114
|
+
getAdvancedLaunchOptions(): LaunchOptions;
|
|
115
|
+
getLaunchOptions(): LaunchOptions;
|
|
116
|
+
getFingerprintGeneratorOptions(): Record<string, any>;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// =============================================================================
|
|
120
|
+
// LiveView
|
|
121
|
+
// =============================================================================
|
|
122
|
+
export interface LiveViewInstance {
|
|
123
|
+
startLiveViewServer(): Promise<void>;
|
|
124
|
+
takeLiveScreenshot(page: Page, label?: string): Promise<void>;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export interface LiveViewModule {
|
|
128
|
+
useLiveView(): LiveViewInstance;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// =============================================================================
|
|
132
|
+
// Captcha
|
|
133
|
+
// =============================================================================
|
|
134
|
+
export interface CaptchaMonitorOptions {
|
|
135
|
+
domSelector?: string;
|
|
136
|
+
urlPattern?: string;
|
|
137
|
+
onDetected?: () => Promise<void>;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export interface CaptchaModule {
|
|
141
|
+
useCaptchaMonitor(page: Page, options: CaptchaMonitorOptions): void;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// =============================================================================
|
|
145
|
+
// Utils
|
|
146
|
+
// =============================================================================
|
|
147
|
+
export interface ParsedCookie {
|
|
148
|
+
name: string;
|
|
149
|
+
value: string;
|
|
150
|
+
domain: string;
|
|
151
|
+
path?: string;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export interface UtilsModule {
|
|
155
|
+
parseSseStream(sseText: string): any[];
|
|
156
|
+
parseCookies(cookieString: string, domain: string): ParsedCookie[];
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// =============================================================================
|
|
160
|
+
// Toolkit Entry Point
|
|
161
|
+
// =============================================================================
|
|
162
|
+
export interface PlaywrightToolKit {
|
|
163
|
+
ApifyKit: ApifyKitModule;
|
|
164
|
+
Stealth: StealthModule;
|
|
165
|
+
Humanize: HumanizeModule;
|
|
166
|
+
Launch: LaunchModule;
|
|
167
|
+
LiveView: LiveViewModule;
|
|
168
|
+
Constants: ConstantsModule;
|
|
169
|
+
Utils: UtilsModule;
|
|
170
|
+
Captcha: CaptchaModule;
|
|
171
|
+
Errors: ErrorsModule;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export declare function usePlaywrightToolKit(): PlaywrightToolKit;
|
package/package.json
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skrillex1224/playwright-toolkit",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.46",
|
|
4
4
|
"description": "一个在 Apify/Crawlee Actor 中启用实时截图视图的实用工具库。",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.js",
|
|
7
|
+
"types": "index.d.ts",
|
|
7
8
|
"type": "module",
|
|
8
9
|
"exports": {
|
|
9
10
|
".": {
|
|
11
|
+
"types": "./index.d.ts",
|
|
10
12
|
"import": "./dist/index.js",
|
|
11
13
|
"require": "./dist/index.cjs"
|
|
12
14
|
}
|
|
@@ -19,6 +21,7 @@
|
|
|
19
21
|
},
|
|
20
22
|
"files": [
|
|
21
23
|
"dist/",
|
|
24
|
+
"index.d.ts",
|
|
22
25
|
"README.md"
|
|
23
26
|
],
|
|
24
27
|
"keywords": [
|