cdp-skill 1.0.7 → 1.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +80 -35
- package/SKILL.md +198 -1344
- package/install.js +1 -0
- package/package.json +1 -1
- package/src/aria/index.js +8 -0
- package/src/aria/output-processor.js +173 -0
- package/src/aria/role-query.js +1229 -0
- package/src/aria/snapshot.js +459 -0
- package/src/aria.js +237 -43
- package/src/cdp/browser.js +22 -4
- package/src/cdp-skill.js +268 -68
- package/src/dom/click-executor.js +240 -76
- package/src/dom/element-locator.js +34 -25
- package/src/dom/fill-executor.js +55 -27
- package/src/page/dialog-handler.js +119 -0
- package/src/page/page-controller.js +190 -3
- package/src/runner/context-helpers.js +33 -55
- package/src/runner/execute-dynamic.js +34 -143
- package/src/runner/execute-form.js +11 -11
- package/src/runner/execute-input.js +2 -2
- package/src/runner/execute-interaction.js +99 -120
- package/src/runner/execute-navigation.js +11 -26
- package/src/runner/execute-query.js +8 -5
- package/src/runner/step-executors.js +256 -95
- package/src/runner/step-registry.js +1064 -0
- package/src/runner/step-validator.js +16 -740
- package/src/tests/Aria.test.js +1025 -0
- package/src/tests/ContextHelpers.test.js +39 -28
- package/src/tests/ExecuteBrowser.test.js +572 -0
- package/src/tests/ExecuteDynamic.test.js +34 -736
- package/src/tests/ExecuteForm.test.js +700 -0
- package/src/tests/ExecuteInput.test.js +540 -0
- package/src/tests/ExecuteInteraction.test.js +319 -0
- package/src/tests/ExecuteQuery.test.js +820 -0
- package/src/tests/FillExecutor.test.js +2 -2
- package/src/tests/StepValidator.test.js +222 -76
- package/src/tests/TestRunner.test.js +36 -25
- package/src/tests/integration.test.js +2 -1
- package/src/types.js +9 -9
- package/src/utils/backoff.js +118 -0
- package/src/utils/cdp-helpers.js +130 -0
- package/src/utils/devices.js +140 -0
- package/src/utils/errors.js +242 -0
- package/src/utils/index.js +65 -0
- package/src/utils/temp.js +75 -0
- package/src/utils/validators.js +433 -0
- package/src/utils.js +14 -1142
|
@@ -70,8 +70,9 @@ export async function clickWithVerification(elementLocator, inputEmulator, x, y,
|
|
|
70
70
|
* Feature 13: Supports captureResult to detect new visible elements after hover
|
|
71
71
|
*/
|
|
72
72
|
export async function executeHover(elementLocator, inputEmulator, ariaSnapshot, params) {
|
|
73
|
-
const selector = typeof params === 'string' ? params : params.selector;
|
|
73
|
+
const selector = typeof params === 'string' ? params : (params.selector || null);
|
|
74
74
|
let ref = typeof params === 'object' ? params.ref : null;
|
|
75
|
+
const text = typeof params === 'object' ? params.text : null;
|
|
75
76
|
const duration = typeof params === 'object' ? (params.duration || 0) : 0;
|
|
76
77
|
|
|
77
78
|
// Detect if string selector looks like a ref (e.g., "s1e1", "s2e12")
|
|
@@ -80,9 +81,35 @@ export async function executeHover(elementLocator, inputEmulator, ariaSnapshot,
|
|
|
80
81
|
ref = selector;
|
|
81
82
|
}
|
|
82
83
|
const force = typeof params === 'object' && params.force === true;
|
|
83
|
-
const timeout = typeof params === 'object' ? (params.timeout || 10000) : 10000;
|
|
84
|
+
const timeout = typeof params === 'object' ? (params.timeout || 10000) : 10000;
|
|
84
85
|
const captureResult = typeof params === 'object' && params.captureResult === true;
|
|
85
86
|
|
|
87
|
+
// Handle coordinate-based hover
|
|
88
|
+
if (typeof params === 'object' && typeof params.x === 'number' && typeof params.y === 'number' && !ref && !selector && !text) {
|
|
89
|
+
await inputEmulator.hover(params.x, params.y, { duration });
|
|
90
|
+
if (captureResult) {
|
|
91
|
+
await sleep(100);
|
|
92
|
+
return await captureHoverResult(elementLocator.session, []);
|
|
93
|
+
}
|
|
94
|
+
return { hovered: true };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Handle text-based hover
|
|
98
|
+
if (text && ariaSnapshot) {
|
|
99
|
+
const refInfo = await ariaSnapshot.findByText(text);
|
|
100
|
+
if (!refInfo) {
|
|
101
|
+
throw elementNotFoundError(`text:${text}`, 0);
|
|
102
|
+
}
|
|
103
|
+
const x = refInfo.box.x + refInfo.box.width / 2;
|
|
104
|
+
const y = refInfo.box.y + refInfo.box.height / 2;
|
|
105
|
+
await inputEmulator.hover(x, y, { duration });
|
|
106
|
+
if (captureResult) {
|
|
107
|
+
await sleep(100);
|
|
108
|
+
return await captureHoverResult(elementLocator.session, []);
|
|
109
|
+
}
|
|
110
|
+
return { hovered: true };
|
|
111
|
+
}
|
|
112
|
+
|
|
86
113
|
const session = elementLocator.session;
|
|
87
114
|
let visibleElementsBefore = [];
|
|
88
115
|
|
|
@@ -285,7 +312,7 @@ export async function captureHoverResult(session, visibleBefore) {
|
|
|
285
312
|
* @returns {Promise<Object>} Drag result
|
|
286
313
|
*/
|
|
287
314
|
export async function executeDrag(elementLocator, inputEmulator, pageController, ariaSnapshot, params) {
|
|
288
|
-
const { source, target, steps = 10, delay = 0 } = params;
|
|
315
|
+
const { source, target, steps = 10, delay = 0, method = 'auto' } = params;
|
|
289
316
|
const session = elementLocator.session;
|
|
290
317
|
|
|
291
318
|
// Helper to get element bounding box by ref
|
|
@@ -305,8 +332,6 @@ export async function executeDrag(elementLocator, inputEmulator, pageController,
|
|
|
305
332
|
|
|
306
333
|
// Helper to get element bounding box in current frame context
|
|
307
334
|
async function getElementBox(selector) {
|
|
308
|
-
// Use page controller's frame context if available
|
|
309
|
-
const contextId = pageController.currentExecutionContextId;
|
|
310
335
|
const evalParams = {
|
|
311
336
|
expression: `
|
|
312
337
|
(function() {
|
|
@@ -319,10 +344,8 @@ export async function executeDrag(elementLocator, inputEmulator, pageController,
|
|
|
319
344
|
returnByValue: true
|
|
320
345
|
};
|
|
321
346
|
|
|
322
|
-
|
|
323
|
-
if (contextId
|
|
324
|
-
evalParams.contextId = contextId;
|
|
325
|
-
}
|
|
347
|
+
const contextId = pageController.getFrameContext();
|
|
348
|
+
if (contextId) evalParams.contextId = contextId;
|
|
326
349
|
|
|
327
350
|
const result = await session.send('Runtime.evaluate', evalParams);
|
|
328
351
|
if (result.exceptionDetails) {
|
|
@@ -415,10 +438,10 @@ export async function executeDrag(elementLocator, inputEmulator, pageController,
|
|
|
415
438
|
const targetX = ${targetX};
|
|
416
439
|
const targetY = ${targetY};
|
|
417
440
|
const steps = ${steps};
|
|
441
|
+
const method = ${JSON.stringify(method)};
|
|
418
442
|
|
|
419
443
|
// Check if source is an input[type=range] (slider)
|
|
420
444
|
if (sourceEl && sourceEl.tagName === 'INPUT' && sourceEl.type === 'range') {
|
|
421
|
-
// For range inputs, calculate the value based on target position
|
|
422
445
|
const rect = sourceEl.getBoundingClientRect();
|
|
423
446
|
const percent = Math.max(0, Math.min(1, (targetX - rect.left) / rect.width));
|
|
424
447
|
const min = parseFloat(sourceEl.min) || 0;
|
|
@@ -430,130 +453,86 @@ export async function executeDrag(elementLocator, inputEmulator, pageController,
|
|
|
430
453
|
return { success: true, method: 'range-input', value: newValue };
|
|
431
454
|
}
|
|
432
455
|
|
|
433
|
-
|
|
434
|
-
|
|
456
|
+
function doMouseDrag() {
|
|
457
|
+
const sourceElAtPoint = sourceEl || document.elementFromPoint(sourceX, sourceY);
|
|
458
|
+
if (!sourceElAtPoint) {
|
|
459
|
+
return { success: false, error: 'No element at source coordinates' };
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
sourceElAtPoint.dispatchEvent(new MouseEvent('mousedown', {
|
|
463
|
+
bubbles: true, cancelable: true,
|
|
464
|
+
clientX: sourceX, clientY: sourceY, button: 0, buttons: 1
|
|
465
|
+
}));
|
|
466
|
+
|
|
467
|
+
const deltaX = (targetX - sourceX) / steps;
|
|
468
|
+
const deltaY = (targetY - sourceY) / steps;
|
|
469
|
+
|
|
470
|
+
for (let i = 1; i <= steps; i++) {
|
|
471
|
+
const currentX = sourceX + deltaX * i;
|
|
472
|
+
const currentY = sourceY + deltaY * i;
|
|
473
|
+
const elAtPoint = document.elementFromPoint(currentX, currentY) || sourceElAtPoint;
|
|
474
|
+
elAtPoint.dispatchEvent(new MouseEvent('mousemove', {
|
|
475
|
+
bubbles: true, cancelable: true,
|
|
476
|
+
clientX: currentX, clientY: currentY, button: 0, buttons: 1
|
|
477
|
+
}));
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
const targetElAtPoint = document.elementFromPoint(targetX, targetY) || sourceElAtPoint;
|
|
481
|
+
targetElAtPoint.dispatchEvent(new MouseEvent('mouseup', {
|
|
482
|
+
bubbles: true, cancelable: true,
|
|
483
|
+
clientX: targetX, clientY: targetY, button: 0, buttons: 0
|
|
484
|
+
}));
|
|
485
|
+
|
|
486
|
+
return { success: true, method: 'mouse-events' };
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
function doHtml5Drag() {
|
|
490
|
+
if (!sourceEl || !targetEl) {
|
|
491
|
+
return { success: false, error: 'HTML5 DnD requires both source and target elements' };
|
|
492
|
+
}
|
|
435
493
|
try {
|
|
436
|
-
// Create DataTransfer object
|
|
437
494
|
const dataTransfer = new DataTransfer();
|
|
438
495
|
dataTransfer.effectAllowed = 'all';
|
|
439
496
|
dataTransfer.dropEffect = 'move';
|
|
440
497
|
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
cancelable: true,
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
clientY:
|
|
458
|
-
});
|
|
459
|
-
sourceEl.dispatchEvent(dragEvent);
|
|
460
|
-
|
|
461
|
-
// Dispatch dragenter on target
|
|
462
|
-
const dragEnterEvent = new DragEvent('dragenter', {
|
|
463
|
-
bubbles: true,
|
|
464
|
-
cancelable: true,
|
|
465
|
-
dataTransfer: dataTransfer,
|
|
466
|
-
clientX: targetX,
|
|
467
|
-
clientY: targetY
|
|
468
|
-
});
|
|
469
|
-
targetEl.dispatchEvent(dragEnterEvent);
|
|
470
|
-
|
|
471
|
-
// Dispatch dragover on target
|
|
472
|
-
const dragOverEvent = new DragEvent('dragover', {
|
|
473
|
-
bubbles: true,
|
|
474
|
-
cancelable: true,
|
|
475
|
-
dataTransfer: dataTransfer,
|
|
476
|
-
clientX: targetX,
|
|
477
|
-
clientY: targetY
|
|
478
|
-
});
|
|
479
|
-
targetEl.dispatchEvent(dragOverEvent);
|
|
480
|
-
|
|
481
|
-
// Dispatch drop on target
|
|
482
|
-
const dropEvent = new DragEvent('drop', {
|
|
483
|
-
bubbles: true,
|
|
484
|
-
cancelable: true,
|
|
485
|
-
dataTransfer: dataTransfer,
|
|
486
|
-
clientX: targetX,
|
|
487
|
-
clientY: targetY
|
|
488
|
-
});
|
|
489
|
-
targetEl.dispatchEvent(dropEvent);
|
|
490
|
-
|
|
491
|
-
// Dispatch dragend on source
|
|
492
|
-
const dragEndEvent = new DragEvent('dragend', {
|
|
493
|
-
bubbles: true,
|
|
494
|
-
cancelable: true,
|
|
495
|
-
dataTransfer: dataTransfer,
|
|
496
|
-
clientX: targetX,
|
|
497
|
-
clientY: targetY
|
|
498
|
-
});
|
|
499
|
-
sourceEl.dispatchEvent(dragEndEvent);
|
|
498
|
+
sourceEl.dispatchEvent(new DragEvent('dragstart', {
|
|
499
|
+
bubbles: true, cancelable: true, dataTransfer, clientX: sourceX, clientY: sourceY
|
|
500
|
+
}));
|
|
501
|
+
sourceEl.dispatchEvent(new DragEvent('drag', {
|
|
502
|
+
bubbles: true, cancelable: true, dataTransfer, clientX: sourceX, clientY: sourceY
|
|
503
|
+
}));
|
|
504
|
+
targetEl.dispatchEvent(new DragEvent('dragenter', {
|
|
505
|
+
bubbles: true, cancelable: true, dataTransfer, clientX: targetX, clientY: targetY
|
|
506
|
+
}));
|
|
507
|
+
targetEl.dispatchEvent(new DragEvent('dragover', {
|
|
508
|
+
bubbles: true, cancelable: true, dataTransfer, clientX: targetX, clientY: targetY
|
|
509
|
+
}));
|
|
510
|
+
targetEl.dispatchEvent(new DragEvent('drop', {
|
|
511
|
+
bubbles: true, cancelable: true, dataTransfer, clientX: targetX, clientY: targetY
|
|
512
|
+
}));
|
|
513
|
+
sourceEl.dispatchEvent(new DragEvent('dragend', {
|
|
514
|
+
bubbles: true, cancelable: true, dataTransfer, clientX: targetX, clientY: targetY
|
|
515
|
+
}));
|
|
500
516
|
|
|
501
517
|
return { success: true, method: 'html5-dnd' };
|
|
502
518
|
} catch (e) {
|
|
503
|
-
|
|
519
|
+
return { success: false, error: e.message };
|
|
504
520
|
}
|
|
505
521
|
}
|
|
506
522
|
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
523
|
+
if (method === 'mouse') return doMouseDrag();
|
|
524
|
+
if (method === 'html5') return doHtml5Drag();
|
|
525
|
+
|
|
526
|
+
// auto: try mouse first (works for jQuery UI, sortable lists), then HTML5 DnD
|
|
527
|
+
const mouseResult = doMouseDrag();
|
|
528
|
+
if (mouseResult.success) return mouseResult;
|
|
512
529
|
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
cancelable: true,
|
|
517
|
-
clientX: sourceX,
|
|
518
|
-
clientY: sourceY,
|
|
519
|
-
button: 0,
|
|
520
|
-
buttons: 1
|
|
521
|
-
});
|
|
522
|
-
sourceElAtPoint.dispatchEvent(mouseDown);
|
|
523
|
-
|
|
524
|
-
// Move in steps
|
|
525
|
-
const deltaX = (targetX - sourceX) / steps;
|
|
526
|
-
const deltaY = (targetY - sourceY) / steps;
|
|
527
|
-
|
|
528
|
-
for (let i = 1; i <= steps; i++) {
|
|
529
|
-
const currentX = sourceX + deltaX * i;
|
|
530
|
-
const currentY = sourceY + deltaY * i;
|
|
531
|
-
const elAtPoint = document.elementFromPoint(currentX, currentY) || sourceElAtPoint;
|
|
532
|
-
|
|
533
|
-
const mouseMove = new MouseEvent('mousemove', {
|
|
534
|
-
bubbles: true,
|
|
535
|
-
cancelable: true,
|
|
536
|
-
clientX: currentX,
|
|
537
|
-
clientY: currentY,
|
|
538
|
-
button: 0,
|
|
539
|
-
buttons: 1
|
|
540
|
-
});
|
|
541
|
-
elAtPoint.dispatchEvent(mouseMove);
|
|
530
|
+
if (sourceEl && targetEl) {
|
|
531
|
+
const html5Result = doHtml5Drag();
|
|
532
|
+
if (html5Result.success) return html5Result;
|
|
542
533
|
}
|
|
543
534
|
|
|
544
|
-
|
|
545
|
-
const targetElAtPoint = document.elementFromPoint(targetX, targetY) || sourceElAtPoint;
|
|
546
|
-
const mouseUp = new MouseEvent('mouseup', {
|
|
547
|
-
bubbles: true,
|
|
548
|
-
cancelable: true,
|
|
549
|
-
clientX: targetX,
|
|
550
|
-
clientY: targetY,
|
|
551
|
-
button: 0,
|
|
552
|
-
buttons: 0
|
|
553
|
-
});
|
|
554
|
-
targetElAtPoint.dispatchEvent(mouseUp);
|
|
555
|
-
|
|
556
|
-
return { success: true, method: 'mouse-events' };
|
|
535
|
+
return mouseResult;
|
|
557
536
|
})()
|
|
558
537
|
`,
|
|
559
538
|
returnByValue: true,
|
|
@@ -95,40 +95,30 @@ export async function executeScroll(elementLocator, inputEmulator, pageControlle
|
|
|
95
95
|
throw new Error(`Element ref:${ref} is no longer attached to the DOM. Run 'snapshot' again to get fresh refs.`);
|
|
96
96
|
}
|
|
97
97
|
// Scroll to element using its coordinates
|
|
98
|
-
await pageController.
|
|
99
|
-
expression: `
|
|
98
|
+
await pageController.evaluateInFrame(`
|
|
100
99
|
(function() {
|
|
101
100
|
const el = window.__ariaRefs && window.__ariaRefs.get(${JSON.stringify(ref)});
|
|
102
101
|
if (el && el.scrollIntoView) {
|
|
103
102
|
el.scrollIntoView({ block: 'center', behavior: 'smooth' });
|
|
104
103
|
}
|
|
105
104
|
})()
|
|
106
|
-
`
|
|
107
|
-
});
|
|
105
|
+
`);
|
|
108
106
|
}
|
|
109
107
|
|
|
110
108
|
if (typeof params === 'string') {
|
|
111
109
|
// Direction-based scroll
|
|
112
110
|
switch (params) {
|
|
113
111
|
case 'top':
|
|
114
|
-
await pageController.
|
|
115
|
-
expression: 'window.scrollTo(0, 0)'
|
|
116
|
-
});
|
|
112
|
+
await pageController.evaluateInFrame('window.scrollTo(0, 0)');
|
|
117
113
|
break;
|
|
118
114
|
case 'bottom':
|
|
119
|
-
await pageController.
|
|
120
|
-
expression: 'window.scrollTo(0, document.body.scrollHeight)'
|
|
121
|
-
});
|
|
115
|
+
await pageController.evaluateInFrame('window.scrollTo(0, document.body.scrollHeight)');
|
|
122
116
|
break;
|
|
123
117
|
case 'up':
|
|
124
|
-
await pageController.
|
|
125
|
-
expression: 'window.scrollBy(0, -300)'
|
|
126
|
-
});
|
|
118
|
+
await pageController.evaluateInFrame('window.scrollBy(0, -300)');
|
|
127
119
|
break;
|
|
128
120
|
case 'down':
|
|
129
|
-
await pageController.
|
|
130
|
-
expression: 'window.scrollBy(0, 300)'
|
|
131
|
-
});
|
|
121
|
+
await pageController.evaluateInFrame('window.scrollBy(0, 300)');
|
|
132
122
|
break;
|
|
133
123
|
default:
|
|
134
124
|
// Check if it looks like a ref (e.g., "s1e1", "s2e12")
|
|
@@ -159,22 +149,17 @@ export async function executeScroll(elementLocator, inputEmulator, pageControlle
|
|
|
159
149
|
await el.dispose();
|
|
160
150
|
} else if (params.deltaY !== undefined || params.deltaX !== undefined) {
|
|
161
151
|
// Scroll by delta using JavaScript (more reliable than CDP mouse wheel events)
|
|
162
|
-
await pageController.
|
|
163
|
-
expression: `window.scrollBy(${params.deltaX || 0}, ${params.deltaY || 0})`
|
|
164
|
-
});
|
|
152
|
+
await pageController.evaluateInFrame(`window.scrollBy(${params.deltaX || 0}, ${params.deltaY || 0})`);
|
|
165
153
|
} else if (params.y !== undefined) {
|
|
166
154
|
// Scroll to position
|
|
167
|
-
await pageController.
|
|
168
|
-
expression: `window.scrollTo(${params.x || 0}, ${params.y})`
|
|
169
|
-
});
|
|
155
|
+
await pageController.evaluateInFrame(`window.scrollTo(${params.x || 0}, ${params.y})`);
|
|
170
156
|
}
|
|
171
157
|
}
|
|
172
158
|
|
|
173
159
|
// Return current scroll position
|
|
174
|
-
const posResult = await pageController.
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
});
|
|
160
|
+
const posResult = await pageController.evaluateInFrame(
|
|
161
|
+
'({ scrollX: window.scrollX, scrollY: window.scrollY })'
|
|
162
|
+
);
|
|
178
163
|
|
|
179
164
|
return posResult.result.value;
|
|
180
165
|
}
|
|
@@ -133,10 +133,11 @@ export async function executeGetDom(pageController, params) {
|
|
|
133
133
|
};
|
|
134
134
|
})()`;
|
|
135
135
|
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
136
|
+
const evalArgs = { expression, returnByValue: true };
|
|
137
|
+
const contextId = pageController.getFrameContext();
|
|
138
|
+
if (contextId) evalArgs.contextId = contextId;
|
|
139
|
+
|
|
140
|
+
const result = await session.send('Runtime.evaluate', evalArgs);
|
|
140
141
|
|
|
141
142
|
if (result.exceptionDetails) {
|
|
142
143
|
throw new Error(`getDom error: ${result.exceptionDetails.text}`);
|
|
@@ -746,7 +747,9 @@ export async function executeQuery(elementLocator, params) {
|
|
|
746
747
|
*/
|
|
747
748
|
|
|
748
749
|
export async function executeRoleQuery(elementLocator, params) {
|
|
749
|
-
const roleQueryExecutor = createRoleQueryExecutor(elementLocator.session, elementLocator
|
|
750
|
+
const roleQueryExecutor = createRoleQueryExecutor(elementLocator.session, elementLocator, {
|
|
751
|
+
getFrameContext: elementLocator.getFrameContext
|
|
752
|
+
});
|
|
750
753
|
return roleQueryExecutor.execute(params);
|
|
751
754
|
}
|
|
752
755
|
|