arn-browser 0.0.5 → 0.0.6
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/package.json
CHANGED
|
@@ -67,12 +67,22 @@ function createHumanLocator(cursor, locator) {
|
|
|
67
67
|
},
|
|
68
68
|
|
|
69
69
|
async fill(value, options = {}) {
|
|
70
|
+
if (!cursor.config.humanize) {
|
|
71
|
+
return await locator.fill(value, options);
|
|
72
|
+
}
|
|
73
|
+
// Humanize: Move to element, click, then fill instantly
|
|
74
|
+
await this.click(options);
|
|
75
|
+
return await locator.fill(value, options);
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
async fillSequentially(value, options = {}) {
|
|
70
79
|
if (!cursor.config.humanize) {
|
|
71
80
|
return await locator.fill(value, options);
|
|
72
81
|
}
|
|
73
82
|
await this.click(options);
|
|
74
83
|
await cursor._page.keyboard.press('Control+A');
|
|
75
84
|
await sleep(randInt(50, 100));
|
|
85
|
+
// Human type with delays
|
|
76
86
|
await cursor._type(value, options);
|
|
77
87
|
},
|
|
78
88
|
|
|
@@ -99,6 +109,43 @@ function createHumanLocator(cursor, locator) {
|
|
|
99
109
|
await cursor._page.keyboard.press(key);
|
|
100
110
|
},
|
|
101
111
|
|
|
112
|
+
async check(options = {}) {
|
|
113
|
+
if (!cursor.config.humanize) {
|
|
114
|
+
return await locator.check(options);
|
|
115
|
+
}
|
|
116
|
+
if (!(await locator.isChecked())) {
|
|
117
|
+
await this.click(options);
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
|
|
121
|
+
async uncheck(options = {}) {
|
|
122
|
+
if (!cursor.config.humanize) {
|
|
123
|
+
return await locator.uncheck(options);
|
|
124
|
+
}
|
|
125
|
+
if (await locator.isChecked()) {
|
|
126
|
+
await this.click(options);
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
|
|
130
|
+
async setChecked(checked, options = {}) {
|
|
131
|
+
if (!cursor.config.humanize) {
|
|
132
|
+
return await locator.setChecked(checked, options);
|
|
133
|
+
}
|
|
134
|
+
if (checked) {
|
|
135
|
+
await this.check(options);
|
|
136
|
+
} else {
|
|
137
|
+
await this.uncheck(options);
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
|
|
141
|
+
async pressSequentially(text, options = {}) {
|
|
142
|
+
if (!cursor.config.humanize) {
|
|
143
|
+
return await locator.pressSequentially(text, options);
|
|
144
|
+
}
|
|
145
|
+
await this.click(options);
|
|
146
|
+
await cursor._type(text, options);
|
|
147
|
+
},
|
|
148
|
+
|
|
102
149
|
// Chainable methods that return new HumanLocators
|
|
103
150
|
filter(options) {
|
|
104
151
|
return createHumanLocator(cursor, locator.filter(options));
|
|
@@ -151,7 +198,7 @@ function createHumanLocator(cursor, locator) {
|
|
|
151
198
|
|
|
152
199
|
/**
|
|
153
200
|
* Create a HumanCursor that acts as a drop-in replacement for Page
|
|
154
|
-
* All page methods work, but click/fill/type/hover use human cursor
|
|
201
|
+
* All page methods work, but click/fill/type/check/hover use human cursor
|
|
155
202
|
*
|
|
156
203
|
* @param {import('playwright').Page} page - Playwright Page object
|
|
157
204
|
* @param {Object} options - Configuration options
|
|
@@ -411,6 +458,27 @@ export function createCursor(page, options = {}) {
|
|
|
411
458
|
if (prop in locatorMethods) {
|
|
412
459
|
return locatorMethods[prop];
|
|
413
460
|
}
|
|
461
|
+
|
|
462
|
+
// Override Page methods to use HumanLocator
|
|
463
|
+
if (['click', 'dblclick', 'fill', 'hover', 'type', 'press', 'check', 'uncheck'].includes(prop)) {
|
|
464
|
+
return async (selector, ...args) => {
|
|
465
|
+
const humanLocator = createHumanLocator(cursor, page.locator(selector));
|
|
466
|
+
return await humanLocator[prop](...args);
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
if (prop === 'fillSequentially') {
|
|
470
|
+
return async (selector, ...args) => {
|
|
471
|
+
const humanLocator = createHumanLocator(cursor, page.locator(selector));
|
|
472
|
+
return await humanLocator.fillSequentially(...args);
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
if (prop === 'pressSequentially') {
|
|
476
|
+
return async (selector, ...args) => {
|
|
477
|
+
const humanLocator = createHumanLocator(cursor, page.locator(selector));
|
|
478
|
+
return await humanLocator.pressSequentially(...args);
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
|
|
414
482
|
// Expose cursor utilities
|
|
415
483
|
if (prop === 'showCursor') {
|
|
416
484
|
return cursor.showCursor.bind(cursor);
|
|
@@ -66,7 +66,9 @@ export interface HumanClickOptions {
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
export interface HumanFillOptions extends HumanClickOptions {
|
|
69
|
+
/** Minimum delay between keystrokes in ms (default: 50) */
|
|
69
70
|
minDelay?: number;
|
|
71
|
+
/** Maximum delay between keystrokes in ms (default: 150) */
|
|
70
72
|
maxDelay?: number;
|
|
71
73
|
}
|
|
72
74
|
|
|
@@ -77,8 +79,13 @@ export interface HumanFillOptions extends HumanClickOptions {
|
|
|
77
79
|
export interface HumanLocator extends Locator {
|
|
78
80
|
click(options?: HumanClickOptions): Promise<void>;
|
|
79
81
|
dblclick(options?: HumanClickOptions): Promise<void>;
|
|
80
|
-
fill(value: string, options?:
|
|
82
|
+
fill(value: string, options?: HumanClickOptions): Promise<void>;
|
|
83
|
+
fillSequentially(value: string, options?: HumanFillOptions): Promise<void>;
|
|
81
84
|
type(text: string, options?: HumanFillOptions): Promise<void>;
|
|
85
|
+
pressSequentially(text: string, options?: HumanFillOptions): Promise<void>;
|
|
86
|
+
check(options?: HumanClickOptions): Promise<void>;
|
|
87
|
+
uncheck(options?: HumanClickOptions): Promise<void>;
|
|
88
|
+
setChecked(checked: boolean, options?: HumanClickOptions): Promise<void>;
|
|
82
89
|
hover(options?: HumanClickOptions): Promise<void>;
|
|
83
90
|
press(key: string, options?: HumanClickOptions): Promise<void>;
|
|
84
91
|
|