browser-debugger-cli 0.6.11 → 0.7.1
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 +2 -0
- package/dist/commands/cdp.d.ts.map +1 -1
- package/dist/commands/cdp.js +90 -15
- package/dist/commands/cdp.js.map +1 -1
- package/dist/commands/dom/DomElementResolver.d.ts.map +1 -1
- package/dist/commands/dom/DomElementResolver.js +28 -7
- package/dist/commands/dom/DomElementResolver.js.map +1 -1
- package/dist/commands/dom/a11y.d.ts.map +1 -1
- package/dist/commands/dom/a11y.js +5 -1
- package/dist/commands/dom/a11y.js.map +1 -1
- package/dist/commands/dom/evalHelpers.js +1 -1
- package/dist/commands/dom/evalHelpers.js.map +1 -1
- package/dist/commands/dom/form.d.ts +14 -0
- package/dist/commands/dom/form.d.ts.map +1 -0
- package/dist/commands/dom/form.js +441 -0
- package/dist/commands/dom/form.js.map +1 -0
- package/dist/commands/dom/formDiscovery.d.ts +26 -0
- package/dist/commands/dom/formDiscovery.d.ts.map +1 -0
- package/dist/commands/dom/formDiscovery.js +476 -0
- package/dist/commands/dom/formDiscovery.js.map +1 -0
- package/dist/commands/dom/formFillHelpers.d.ts +72 -0
- package/dist/commands/dom/formFillHelpers.d.ts.map +1 -1
- package/dist/commands/dom/formFillHelpers.js +241 -5
- package/dist/commands/dom/formFillHelpers.js.map +1 -1
- package/dist/commands/dom/formInteraction.d.ts.map +1 -1
- package/dist/commands/dom/formInteraction.js +119 -3
- package/dist/commands/dom/formInteraction.js.map +1 -1
- package/dist/commands/dom/formTypes.d.ts +75 -0
- package/dist/commands/dom/formTypes.d.ts.map +1 -0
- package/dist/commands/dom/formTypes.js +7 -0
- package/dist/commands/dom/formTypes.js.map +1 -0
- package/dist/commands/dom/helpers.d.ts +1 -1
- package/dist/commands/dom/helpers.js +1 -1
- package/dist/commands/dom/index.d.ts.map +1 -1
- package/dist/commands/dom/index.js +7 -2
- package/dist/commands/dom/index.js.map +1 -1
- package/dist/commands/dom/screenshotResize.d.ts +1 -1
- package/dist/commands/dom/screenshotResize.js +1 -1
- package/dist/commands/optionBehaviors.d.ts.map +1 -1
- package/dist/commands/optionBehaviors.js +37 -0
- package/dist/commands/optionBehaviors.js.map +1 -1
- package/dist/commands/shared/optionTypes.d.ts +22 -0
- package/dist/commands/shared/optionTypes.d.ts.map +1 -1
- package/dist/commands/shared/startHelpers.d.ts.map +1 -1
- package/dist/commands/shared/startHelpers.js +1 -0
- package/dist/commands/shared/startHelpers.js.map +1 -1
- package/dist/commands/start.d.ts.map +1 -1
- package/dist/commands/start.js +25 -6
- package/dist/commands/start.js.map +1 -1
- package/dist/connection/__tests__/flagsBuilder.unit.test.d.ts +9 -0
- package/dist/connection/__tests__/flagsBuilder.unit.test.d.ts.map +1 -0
- package/dist/connection/__tests__/flagsBuilder.unit.test.js +94 -0
- package/dist/connection/__tests__/flagsBuilder.unit.test.js.map +1 -0
- package/dist/connection/cdp.js.map +1 -1
- package/dist/connection/launcher/flagsBuilder.d.ts +26 -0
- package/dist/connection/launcher/flagsBuilder.d.ts.map +1 -1
- package/dist/connection/launcher/flagsBuilder.js +36 -8
- package/dist/connection/launcher/flagsBuilder.js.map +1 -1
- package/dist/connection/launcher.d.ts.map +1 -1
- package/dist/connection/launcher.js +20 -9
- package/dist/connection/launcher.js.map +1 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +1 -0
- package/dist/constants.js.map +1 -1
- package/dist/daemon/handlers/SessionHandlers.d.ts.map +1 -1
- package/dist/daemon/handlers/SessionHandlers.js +1 -0
- package/dist/daemon/handlers/SessionHandlers.js.map +1 -1
- package/dist/daemon/launcher.d.ts.map +1 -1
- package/dist/daemon/launcher.js +8 -2
- package/dist/daemon/launcher.js.map +1 -1
- package/dist/daemon/lifecycle/chromeConnection.js +1 -1
- package/dist/daemon/lifecycle/chromeConnection.js.map +1 -1
- package/dist/daemon/lifecycle/workerCleanup.d.ts.map +1 -1
- package/dist/daemon/lifecycle/workerCleanup.js +3 -1
- package/dist/daemon/lifecycle/workerCleanup.js.map +1 -1
- package/dist/daemon/lifecycle/workerConfig.d.ts.map +1 -1
- package/dist/daemon/lifecycle/workerConfig.js +3 -0
- package/dist/daemon/lifecycle/workerConfig.js.map +1 -1
- package/dist/daemon/startSession.d.ts +2 -0
- package/dist/daemon/startSession.d.ts.map +1 -1
- package/dist/daemon/startSession.js +7 -1
- package/dist/daemon/startSession.js.map +1 -1
- package/dist/daemon/worker/types.d.ts +2 -0
- package/dist/daemon/worker/types.d.ts.map +1 -1
- package/dist/ipc/client.d.ts.map +1 -1
- package/dist/ipc/client.js +1 -0
- package/dist/ipc/client.js.map +1 -1
- package/dist/ipc/protocol/messages.d.ts +2 -2
- package/dist/ipc/protocol/messages.d.ts.map +1 -1
- package/dist/ipc/session/lifecycle.d.ts +4 -0
- package/dist/ipc/session/lifecycle.d.ts.map +1 -1
- package/dist/session/cleanup.d.ts.map +1 -1
- package/dist/session/cleanup.js +50 -4
- package/dist/session/cleanup.js.map +1 -1
- package/dist/session/paths.d.ts +1 -0
- package/dist/session/paths.d.ts.map +1 -1
- package/dist/session/paths.js +1 -0
- package/dist/session/paths.js.map +1 -1
- package/dist/session/port.d.ts +41 -0
- package/dist/session/port.d.ts.map +1 -0
- package/dist/session/port.js +134 -0
- package/dist/session/port.js.map +1 -0
- package/dist/types.d.ts +120 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/ui/formatters/form.d.ts +15 -0
- package/dist/ui/formatters/form.d.ts.map +1 -0
- package/dist/ui/formatters/form.js +314 -0
- package/dist/ui/formatters/form.js.map +1 -0
- package/dist/ui/messages/errors.d.ts +41 -12
- package/dist/ui/messages/errors.d.ts.map +1 -1
- package/dist/ui/messages/errors.js +113 -15
- package/dist/ui/messages/errors.js.map +1 -1
- package/dist/utils/__tests__/shellDetection.unit.test.d.ts +12 -0
- package/dist/utils/__tests__/shellDetection.unit.test.d.ts.map +1 -0
- package/dist/utils/__tests__/shellDetection.unit.test.js +220 -0
- package/dist/utils/__tests__/shellDetection.unit.test.js.map +1 -0
- package/dist/utils/decisionTrees.d.ts.map +1 -1
- package/dist/utils/decisionTrees.js +5 -0
- package/dist/utils/decisionTrees.js.map +1 -1
- package/dist/utils/exitCodes.d.ts +2 -0
- package/dist/utils/exitCodes.d.ts.map +1 -1
- package/dist/utils/exitCodes.js +12 -0
- package/dist/utils/exitCodes.js.map +1 -1
- package/dist/utils/shellDetection.d.ts +34 -0
- package/dist/utils/shellDetection.d.ts.map +1 -0
- package/dist/utils/shellDetection.js +94 -0
- package/dist/utils/shellDetection.js.map +1 -0
- package/dist/utils/taskMappings.d.ts.map +1 -1
- package/dist/utils/taskMappings.js +5 -0
- package/dist/utils/taskMappings.js.map +1 -1
- package/dist/utils/url.d.ts.map +1 -1
- package/dist/utils/url.js +14 -0
- package/dist/utils/url.js.map +1 -1
- package/package.json +5 -5
|
@@ -0,0 +1,476 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Form discovery script executed in page context.
|
|
3
|
+
*
|
|
4
|
+
* Discovers forms, extracts semantic labels, detects state and validation,
|
|
5
|
+
* and returns structured data for agent consumption.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Page-context script for form discovery.
|
|
9
|
+
*
|
|
10
|
+
* This script runs in the browser via Runtime.evaluate and discovers:
|
|
11
|
+
* - Native form elements and inputs
|
|
12
|
+
* - Custom components with ARIA roles
|
|
13
|
+
* - Labels via priority chain (label[for], aria-label, placeholder, etc.)
|
|
14
|
+
* - Current values and validation state
|
|
15
|
+
* - Form relevance scoring for multi-form pages
|
|
16
|
+
*/
|
|
17
|
+
export const FORM_DISCOVERY_SCRIPT = `
|
|
18
|
+
(function() {
|
|
19
|
+
const result = { forms: [] };
|
|
20
|
+
|
|
21
|
+
function generateSelector(element) {
|
|
22
|
+
if (element.id) {
|
|
23
|
+
return '#' + CSS.escape(element.id);
|
|
24
|
+
}
|
|
25
|
+
if (element.name) {
|
|
26
|
+
const tag = element.tagName.toLowerCase();
|
|
27
|
+
return tag + '[name="' + CSS.escape(element.name) + '"]';
|
|
28
|
+
}
|
|
29
|
+
const tag = element.tagName.toLowerCase();
|
|
30
|
+
const parent = element.parentElement;
|
|
31
|
+
if (!parent) return tag;
|
|
32
|
+
const siblings = Array.from(parent.children).filter(c => c.tagName === element.tagName);
|
|
33
|
+
if (siblings.length === 1) {
|
|
34
|
+
const parentSelector = generateSelector(parent);
|
|
35
|
+
return parentSelector + ' > ' + tag;
|
|
36
|
+
}
|
|
37
|
+
const index = siblings.indexOf(element);
|
|
38
|
+
const parentSelector = generateSelector(parent);
|
|
39
|
+
return parentSelector + ' > ' + tag + ':nth-of-type(' + (index + 1) + ')';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function cleanLabelText(text) {
|
|
43
|
+
if (!text) return text;
|
|
44
|
+
const patterns = [
|
|
45
|
+
/Previous\\s*arrow/gi,
|
|
46
|
+
/Next\\s*arrow/gi,
|
|
47
|
+
/\\barrow\\b/gi,
|
|
48
|
+
/\\bchevron\\b/gi,
|
|
49
|
+
/←|→|↑|↓|▲|▼|◀|▶/g,
|
|
50
|
+
/\\u25C0|\\u25B6|\\u25B2|\\u25BC/g,
|
|
51
|
+
/Previous|Next|Back|Forward/gi,
|
|
52
|
+
/^\\s*[<>]\\s*/,
|
|
53
|
+
/\\s*[<>]\\s*$/,
|
|
54
|
+
];
|
|
55
|
+
let cleaned = text;
|
|
56
|
+
for (const pattern of patterns) {
|
|
57
|
+
cleaned = cleaned.replace(pattern, '');
|
|
58
|
+
}
|
|
59
|
+
cleaned = cleaned.replace(/\\s{2,}/g, ' ').trim();
|
|
60
|
+
return cleaned || text.trim();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function extractLabel(element) {
|
|
64
|
+
if (element.id) {
|
|
65
|
+
const labelFor = document.querySelector('label[for="' + CSS.escape(element.id) + '"]');
|
|
66
|
+
if (labelFor) return cleanLabelText(labelFor.textContent);
|
|
67
|
+
}
|
|
68
|
+
const ariaLabel = element.getAttribute('aria-label');
|
|
69
|
+
if (ariaLabel) return cleanLabelText(ariaLabel);
|
|
70
|
+
const ariaLabelledBy = element.getAttribute('aria-labelledby');
|
|
71
|
+
if (ariaLabelledBy) {
|
|
72
|
+
const labelEl = document.getElementById(ariaLabelledBy);
|
|
73
|
+
if (labelEl) return cleanLabelText(labelEl.textContent);
|
|
74
|
+
}
|
|
75
|
+
const wrappingLabel = element.closest('label');
|
|
76
|
+
if (wrappingLabel) {
|
|
77
|
+
const clone = wrappingLabel.cloneNode(true);
|
|
78
|
+
const inputs = clone.querySelectorAll('input, select, textarea, button');
|
|
79
|
+
inputs.forEach(i => i.remove());
|
|
80
|
+
const text = clone.textContent.trim();
|
|
81
|
+
if (text) return cleanLabelText(text);
|
|
82
|
+
}
|
|
83
|
+
if (element.placeholder) return cleanLabelText(element.placeholder);
|
|
84
|
+
const title = element.getAttribute('title');
|
|
85
|
+
if (title) return cleanLabelText(title);
|
|
86
|
+
if (element.name) {
|
|
87
|
+
return element.name
|
|
88
|
+
.replace(/[_-]/g, ' ')
|
|
89
|
+
.replace(/([a-z])([A-Z])/g, '$1 $2')
|
|
90
|
+
.replace(/^./, s => s.toUpperCase());
|
|
91
|
+
}
|
|
92
|
+
return 'Unlabeled field';
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function extractButtonLabel(element) {
|
|
96
|
+
const ariaLabel = element.getAttribute('aria-label');
|
|
97
|
+
if (ariaLabel) return ariaLabel.trim();
|
|
98
|
+
if (element.value && element.type !== 'submit') return element.value;
|
|
99
|
+
const text = element.textContent.trim();
|
|
100
|
+
if (text) return text;
|
|
101
|
+
if (element.value) return element.value;
|
|
102
|
+
const title = element.getAttribute('title');
|
|
103
|
+
if (title) return title;
|
|
104
|
+
return 'Button';
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function getFieldValue(element) {
|
|
108
|
+
const tag = element.tagName.toLowerCase();
|
|
109
|
+
const type = element.type?.toLowerCase() || 'text';
|
|
110
|
+
if (tag === 'select') {
|
|
111
|
+
if (element.multiple) {
|
|
112
|
+
return Array.from(element.selectedOptions).map(o => o.value);
|
|
113
|
+
}
|
|
114
|
+
return element.value;
|
|
115
|
+
}
|
|
116
|
+
if (type === 'checkbox' || type === 'radio') {
|
|
117
|
+
return element.checked;
|
|
118
|
+
}
|
|
119
|
+
if (element.getAttribute('role') === 'checkbox' || element.getAttribute('role') === 'switch') {
|
|
120
|
+
return element.getAttribute('aria-checked') === 'true';
|
|
121
|
+
}
|
|
122
|
+
if (element.isContentEditable) {
|
|
123
|
+
return element.textContent || '';
|
|
124
|
+
}
|
|
125
|
+
return element.value || '';
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function getFieldState(element, value) {
|
|
129
|
+
const type = element.type?.toLowerCase() || 'text';
|
|
130
|
+
if (type === 'checkbox' || element.getAttribute('role') === 'checkbox' || element.getAttribute('role') === 'switch') {
|
|
131
|
+
return value ? 'checked' : 'unchecked';
|
|
132
|
+
}
|
|
133
|
+
if (type === 'radio') {
|
|
134
|
+
return value ? 'checked' : 'unchecked';
|
|
135
|
+
}
|
|
136
|
+
if (Array.isArray(value)) {
|
|
137
|
+
return value.length > 0 ? 'filled' : 'empty';
|
|
138
|
+
}
|
|
139
|
+
if (typeof value === 'string') {
|
|
140
|
+
return value.length > 0 ? 'filled' : 'empty';
|
|
141
|
+
}
|
|
142
|
+
return 'empty';
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function getFieldType(element) {
|
|
146
|
+
const tag = element.tagName.toLowerCase();
|
|
147
|
+
const role = element.getAttribute('role');
|
|
148
|
+
if (role === 'textbox') return 'textbox';
|
|
149
|
+
if (role === 'checkbox') return 'checkbox';
|
|
150
|
+
if (role === 'radio') return 'radio';
|
|
151
|
+
if (role === 'combobox') return 'combobox';
|
|
152
|
+
if (role === 'listbox') return 'listbox';
|
|
153
|
+
if (role === 'switch') return 'switch';
|
|
154
|
+
if (element.isContentEditable) return 'contenteditable';
|
|
155
|
+
if (tag === 'textarea') return 'textarea';
|
|
156
|
+
if (tag === 'select') return 'select';
|
|
157
|
+
if (tag === 'input') {
|
|
158
|
+
const type = element.type?.toLowerCase() || 'text';
|
|
159
|
+
return type;
|
|
160
|
+
}
|
|
161
|
+
return 'unknown';
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function isNativeInput(element) {
|
|
165
|
+
const tag = element.tagName.toLowerCase();
|
|
166
|
+
return tag === 'input' || tag === 'textarea' || tag === 'select';
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function getSelectOptions(element) {
|
|
170
|
+
if (element.tagName.toLowerCase() !== 'select') return undefined;
|
|
171
|
+
return Array.from(element.options).map(opt => ({
|
|
172
|
+
value: opt.value,
|
|
173
|
+
label: opt.textContent.trim(),
|
|
174
|
+
selected: opt.selected
|
|
175
|
+
}));
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function findSiblingError(element) {
|
|
179
|
+
const next = element.nextElementSibling;
|
|
180
|
+
if (next) {
|
|
181
|
+
const isError = next.classList.contains('error') ||
|
|
182
|
+
next.classList.contains('invalid') ||
|
|
183
|
+
next.classList.contains('field-error') ||
|
|
184
|
+
next.classList.contains('error-message') ||
|
|
185
|
+
next.getAttribute('role') === 'alert';
|
|
186
|
+
if (isError) return next.textContent.trim();
|
|
187
|
+
}
|
|
188
|
+
const parent = element.parentElement;
|
|
189
|
+
if (parent) {
|
|
190
|
+
const errorEl = parent.querySelector('.error-message, .field-error, [role="alert"]');
|
|
191
|
+
if (errorEl && errorEl !== element) return errorEl.textContent.trim();
|
|
192
|
+
}
|
|
193
|
+
return undefined;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function calculateRelevance(formEl, fields, buttons) {
|
|
197
|
+
let score = 0;
|
|
198
|
+
const rect = formEl.getBoundingClientRect();
|
|
199
|
+
const viewportHeight = window.innerHeight;
|
|
200
|
+
const viewportWidth = window.innerWidth;
|
|
201
|
+
const centerX = rect.left + rect.width / 2;
|
|
202
|
+
const centerY = rect.top + rect.height / 2;
|
|
203
|
+
if (centerX > viewportWidth * 0.2 && centerX < viewportWidth * 0.8) score += 10;
|
|
204
|
+
if (centerY > 0 && centerY < viewportHeight) score += 5;
|
|
205
|
+
const isInMain = formEl.closest('main, [role="main"], article, .main-content, #main');
|
|
206
|
+
if (isInMain) score += 15;
|
|
207
|
+
const isInHeader = formEl.closest('header, [role="banner"], nav, [role="navigation"]');
|
|
208
|
+
if (isInHeader) score -= 10;
|
|
209
|
+
const isInAside = formEl.closest('aside, [role="complementary"], footer, [role="contentinfo"]');
|
|
210
|
+
if (isInAside) score -= 5;
|
|
211
|
+
score += Math.min(fields.length * 3, 30);
|
|
212
|
+
const hasSubmit = buttons.some(b => b.type === 'submit' || b.isPrimary);
|
|
213
|
+
if (hasSubmit) score += 10;
|
|
214
|
+
const style = window.getComputedStyle(formEl);
|
|
215
|
+
if (style.display === 'none' || style.visibility === 'hidden') score -= 100;
|
|
216
|
+
return score;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function detectFormStep(formEl) {
|
|
220
|
+
const stepIndicators = formEl.querySelectorAll('[aria-current="step"], .step.active, .wizard-step.current');
|
|
221
|
+
if (stepIndicators.length === 0) {
|
|
222
|
+
const pageSteps = document.querySelectorAll('.step, .wizard-step, [role="tablist"] [role="tab"]');
|
|
223
|
+
if (pageSteps.length > 1) {
|
|
224
|
+
const activeIndex = Array.from(pageSteps).findIndex(s =>
|
|
225
|
+
s.classList.contains('active') ||
|
|
226
|
+
s.classList.contains('current') ||
|
|
227
|
+
s.getAttribute('aria-selected') === 'true'
|
|
228
|
+
);
|
|
229
|
+
if (activeIndex >= 0) {
|
|
230
|
+
return { current: activeIndex + 1, total: pageSteps.length };
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
const ariaStep = formEl.querySelector('[aria-current="step"]');
|
|
235
|
+
if (ariaStep) {
|
|
236
|
+
const allSteps = formEl.querySelectorAll('[role="listitem"], .step');
|
|
237
|
+
const currentIdx = Array.from(allSteps).indexOf(ariaStep);
|
|
238
|
+
if (currentIdx >= 0) {
|
|
239
|
+
return { current: currentIdx + 1, total: allSteps.length };
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return null;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function findNearbyHeading(formEl) {
|
|
246
|
+
let sibling = formEl.previousElementSibling;
|
|
247
|
+
let distance = 0;
|
|
248
|
+
while (sibling && distance < 3) {
|
|
249
|
+
if (sibling.matches('h1, h2, h3, h4, h5, h6, [role="heading"]')) {
|
|
250
|
+
return sibling.textContent.trim();
|
|
251
|
+
}
|
|
252
|
+
const heading = sibling.querySelector('h1, h2, h3, h4, h5, h6, [role="heading"]');
|
|
253
|
+
if (heading) return heading.textContent.trim();
|
|
254
|
+
sibling = sibling.previousElementSibling;
|
|
255
|
+
distance++;
|
|
256
|
+
}
|
|
257
|
+
const parent = formEl.parentElement;
|
|
258
|
+
if (parent) {
|
|
259
|
+
const heading = parent.querySelector(':scope > h1, :scope > h2, :scope > h3');
|
|
260
|
+
if (heading && heading.compareDocumentPosition(formEl) & Node.DOCUMENT_POSITION_FOLLOWING) {
|
|
261
|
+
return heading.textContent.trim();
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return null;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function matchesWord(text, word) {
|
|
268
|
+
const pattern = new RegExp('\\\\b' + word + '\\\\b', 'i');
|
|
269
|
+
return pattern.test(text);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function inferFormType(formEl) {
|
|
273
|
+
const inputs = formEl.querySelectorAll('input, textarea, select');
|
|
274
|
+
const types = Array.from(inputs).map(i => i.type?.toLowerCase() || i.tagName.toLowerCase());
|
|
275
|
+
const names = Array.from(inputs).map(i => (i.name || '').toLowerCase());
|
|
276
|
+
const allText = (Array.from(inputs).map(i => i.name + ' ' + i.placeholder + ' ' + i.id).join(' ')).toLowerCase();
|
|
277
|
+
if (types.includes('password')) {
|
|
278
|
+
if (types.filter(t => t === 'password').length >= 2) return 'Change Password';
|
|
279
|
+
if (matchesWord(allText, 'register') || matchesWord(allText, 'signup') || matchesWord(allText, 'create')) return 'Registration';
|
|
280
|
+
return 'Login';
|
|
281
|
+
}
|
|
282
|
+
const hasSearchRole = formEl.closest('[role="search"]') || formEl.getAttribute('role') === 'search';
|
|
283
|
+
const hasSearchInput = formEl.querySelector('[type="search"], [aria-label*="search" i]');
|
|
284
|
+
if (hasSearchRole || hasSearchInput) return 'Search';
|
|
285
|
+
const interactiveTypes = types.filter(t => !['hidden', 'submit', 'button', 'reset', 'image'].includes(t));
|
|
286
|
+
if (interactiveTypes.length <= 2 && matchesWord(allText, 'search')) return 'Search';
|
|
287
|
+
if (matchesWord(allText, 'address') || matchesWord(allText, 'street') || matchesWord(allText, 'postcode') ||
|
|
288
|
+
matchesWord(allText, 'zipcode') || matchesWord(allText, 'city') || matchesWord(allText, 'county')) {
|
|
289
|
+
return 'Address';
|
|
290
|
+
}
|
|
291
|
+
if (matchesWord(allText, 'email') && (matchesWord(allText, 'message') || matchesWord(allText, 'subject'))) {
|
|
292
|
+
return 'Contact';
|
|
293
|
+
}
|
|
294
|
+
if (matchesWord(allText, 'card') || matchesWord(allText, 'cvv') || matchesWord(allText, 'expiry')) {
|
|
295
|
+
return 'Payment';
|
|
296
|
+
}
|
|
297
|
+
if (names.some(n => matchesWord(n, 'subscribe') || matchesWord(n, 'newsletter'))) {
|
|
298
|
+
return 'Newsletter';
|
|
299
|
+
}
|
|
300
|
+
return null;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function extractFormName(formEl) {
|
|
304
|
+
const ariaLabel = formEl.getAttribute('aria-label');
|
|
305
|
+
if (ariaLabel) return ariaLabel;
|
|
306
|
+
const ariaLabelledBy = formEl.getAttribute('aria-labelledby');
|
|
307
|
+
if (ariaLabelledBy) {
|
|
308
|
+
const labelEl = document.getElementById(ariaLabelledBy);
|
|
309
|
+
if (labelEl) return labelEl.textContent.trim();
|
|
310
|
+
}
|
|
311
|
+
const headings = formEl.querySelectorAll('h1, h2, h3, h4, h5, h6, [role="heading"]');
|
|
312
|
+
for (const h of headings) {
|
|
313
|
+
if (!h.closest('[role="dialog"], [role="alertdialog"], [aria-modal="true"]')) {
|
|
314
|
+
return h.textContent.trim();
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
const legend = formEl.querySelector('legend');
|
|
318
|
+
if (legend) return legend.textContent.trim();
|
|
319
|
+
const title = formEl.getAttribute('title');
|
|
320
|
+
if (title) return title;
|
|
321
|
+
const name = formEl.getAttribute('name');
|
|
322
|
+
if (name) {
|
|
323
|
+
return name
|
|
324
|
+
.replace(/[_-]/g, ' ')
|
|
325
|
+
.replace(/([a-z])([A-Z])/g, '$1 $2')
|
|
326
|
+
.replace(/^./, s => s.toUpperCase());
|
|
327
|
+
}
|
|
328
|
+
const nearbyHeading = findNearbyHeading(formEl);
|
|
329
|
+
if (nearbyHeading) return nearbyHeading;
|
|
330
|
+
const inferredType = inferFormType(formEl);
|
|
331
|
+
if (inferredType) return inferredType;
|
|
332
|
+
return null;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
function discoverFields(container, formIndex, startIndex) {
|
|
336
|
+
const fields = [];
|
|
337
|
+
const nativeInputs = container.querySelectorAll(
|
|
338
|
+
'input:not([type="hidden"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not([type="image"]), ' +
|
|
339
|
+
'textarea, ' +
|
|
340
|
+
'select'
|
|
341
|
+
);
|
|
342
|
+
const customInputs = container.querySelectorAll(
|
|
343
|
+
'[role="textbox"], ' +
|
|
344
|
+
'[role="checkbox"]:not(input), ' +
|
|
345
|
+
'[role="radio"]:not(input), ' +
|
|
346
|
+
'[role="combobox"], ' +
|
|
347
|
+
'[role="listbox"], ' +
|
|
348
|
+
'[role="switch"], ' +
|
|
349
|
+
'[contenteditable="true"]'
|
|
350
|
+
);
|
|
351
|
+
const allInputs = new Set([...nativeInputs, ...customInputs]);
|
|
352
|
+
let idx = startIndex;
|
|
353
|
+
for (const el of allInputs) {
|
|
354
|
+
const style = window.getComputedStyle(el);
|
|
355
|
+
const isHidden = style.display === 'none' || style.visibility === 'hidden' || el.type === 'hidden';
|
|
356
|
+
const value = getFieldValue(el);
|
|
357
|
+
fields.push({
|
|
358
|
+
index: idx,
|
|
359
|
+
formIndex: formIndex,
|
|
360
|
+
selector: generateSelector(el),
|
|
361
|
+
type: getFieldType(el),
|
|
362
|
+
inputType: el.type?.toLowerCase(),
|
|
363
|
+
label: extractLabel(el),
|
|
364
|
+
name: el.name || null,
|
|
365
|
+
placeholder: el.placeholder || undefined,
|
|
366
|
+
required: el.required || el.getAttribute('aria-required') === 'true',
|
|
367
|
+
disabled: el.disabled || el.getAttribute('aria-disabled') === 'true',
|
|
368
|
+
readOnly: el.readOnly || false,
|
|
369
|
+
hidden: isHidden,
|
|
370
|
+
native: isNativeInput(el),
|
|
371
|
+
value: value,
|
|
372
|
+
checked: el.checked,
|
|
373
|
+
validationMessage: el.validationMessage || undefined,
|
|
374
|
+
isValid: el.checkValidity ? el.checkValidity() : true,
|
|
375
|
+
ariaInvalid: el.getAttribute('aria-invalid') === 'true',
|
|
376
|
+
hasErrorClass: el.classList.contains('error') || el.classList.contains('invalid'),
|
|
377
|
+
siblingErrorText: findSiblingError(el),
|
|
378
|
+
options: getSelectOptions(el)
|
|
379
|
+
});
|
|
380
|
+
idx++;
|
|
381
|
+
}
|
|
382
|
+
return fields;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
function discoverButtons(container, startIndex) {
|
|
386
|
+
const buttons = [];
|
|
387
|
+
const buttonEls = container.querySelectorAll(
|
|
388
|
+
'button, ' +
|
|
389
|
+
'input[type="submit"], ' +
|
|
390
|
+
'input[type="button"], ' +
|
|
391
|
+
'input[type="reset"], ' +
|
|
392
|
+
'[role="button"]'
|
|
393
|
+
);
|
|
394
|
+
let idx = startIndex;
|
|
395
|
+
for (const el of buttonEls) {
|
|
396
|
+
const style = window.getComputedStyle(el);
|
|
397
|
+
if (style.display === 'none' || style.visibility === 'hidden') continue;
|
|
398
|
+
const type = el.type?.toLowerCase() || 'button';
|
|
399
|
+
const btnType = type === 'submit' ? 'submit' : type === 'reset' ? 'reset' : 'button';
|
|
400
|
+
const isPrimary = btnType === 'submit' ||
|
|
401
|
+
el.classList.contains('primary') ||
|
|
402
|
+
el.classList.contains('btn-primary') ||
|
|
403
|
+
el.classList.contains('submit');
|
|
404
|
+
buttons.push({
|
|
405
|
+
index: idx,
|
|
406
|
+
selector: generateSelector(el),
|
|
407
|
+
label: extractButtonLabel(el),
|
|
408
|
+
type: btnType,
|
|
409
|
+
disabled: el.disabled || el.getAttribute('aria-disabled') === 'true',
|
|
410
|
+
isPrimary: isPrimary
|
|
411
|
+
});
|
|
412
|
+
idx++;
|
|
413
|
+
}
|
|
414
|
+
return buttons;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
const forms = document.querySelectorAll('form');
|
|
418
|
+
let globalIndex = 0;
|
|
419
|
+
|
|
420
|
+
if (forms.length === 0) {
|
|
421
|
+
const bodyFields = discoverFields(document.body, 0, 0);
|
|
422
|
+
const bodyButtons = discoverButtons(document.body, bodyFields.length);
|
|
423
|
+
if (bodyFields.length > 0) {
|
|
424
|
+
result.forms.push({
|
|
425
|
+
index: 0,
|
|
426
|
+
name: document.title || 'Page',
|
|
427
|
+
action: null,
|
|
428
|
+
method: 'GET',
|
|
429
|
+
step: null,
|
|
430
|
+
relevanceScore: bodyFields.length * 3,
|
|
431
|
+
inIframe: false,
|
|
432
|
+
fields: bodyFields,
|
|
433
|
+
buttons: bodyButtons
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
} else {
|
|
437
|
+
for (let i = 0; i < forms.length; i++) {
|
|
438
|
+
const formEl = forms[i];
|
|
439
|
+
const fields = discoverFields(formEl, i, globalIndex);
|
|
440
|
+
globalIndex += fields.length;
|
|
441
|
+
const buttons = discoverButtons(formEl, globalIndex);
|
|
442
|
+
globalIndex += buttons.length;
|
|
443
|
+
const inIframe = formEl.ownerDocument !== document;
|
|
444
|
+
result.forms.push({
|
|
445
|
+
index: i,
|
|
446
|
+
name: extractFormName(formEl),
|
|
447
|
+
action: formEl.action || null,
|
|
448
|
+
method: (formEl.method || 'GET').toUpperCase(),
|
|
449
|
+
step: detectFormStep(formEl),
|
|
450
|
+
relevanceScore: calculateRelevance(formEl, fields, buttons),
|
|
451
|
+
inIframe: inIframe,
|
|
452
|
+
fields: fields,
|
|
453
|
+
buttons: buttons
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
result.forms.sort((a, b) => b.relevanceScore - a.relevanceScore);
|
|
459
|
+
|
|
460
|
+
return result;
|
|
461
|
+
})()
|
|
462
|
+
`;
|
|
463
|
+
/**
|
|
464
|
+
* Type guard for raw form data.
|
|
465
|
+
*
|
|
466
|
+
* @param value - Unknown value to check
|
|
467
|
+
* @returns True if value matches RawFormData structure
|
|
468
|
+
*/
|
|
469
|
+
export function isRawFormData(value) {
|
|
470
|
+
if (typeof value !== 'object' || value === null) {
|
|
471
|
+
return false;
|
|
472
|
+
}
|
|
473
|
+
const obj = value;
|
|
474
|
+
return Array.isArray(obj['forms']);
|
|
475
|
+
}
|
|
476
|
+
//# sourceMappingURL=formDiscovery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formDiscovery.js","sourceRoot":"","sources":["../../../src/commands/dom/formDiscovery.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6bpC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QAChD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,GAAG,GAAG,KAAgC,CAAC;IAC7C,OAAO,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC;AACrC,CAAC"}
|
|
@@ -111,4 +111,76 @@ export interface PressKeyResult {
|
|
|
111
111
|
* ```
|
|
112
112
|
*/
|
|
113
113
|
export declare function pressKeyElement(cdp: CDPConnection, selector: string, keyName: string, options?: PressKeyOptions): Promise<PressKeyResult>;
|
|
114
|
+
/**
|
|
115
|
+
* Options for scrolling the page.
|
|
116
|
+
*/
|
|
117
|
+
export interface ScrollOptions {
|
|
118
|
+
/** Scroll down by pixels */
|
|
119
|
+
down?: number;
|
|
120
|
+
/** Scroll up by pixels */
|
|
121
|
+
up?: number;
|
|
122
|
+
/** Scroll left by pixels */
|
|
123
|
+
left?: number;
|
|
124
|
+
/** Scroll right by pixels */
|
|
125
|
+
right?: number;
|
|
126
|
+
/** Scroll to page top */
|
|
127
|
+
top?: boolean;
|
|
128
|
+
/** Scroll to page bottom */
|
|
129
|
+
bottom?: boolean;
|
|
130
|
+
/** Element index if selector matches multiple (0-based) */
|
|
131
|
+
index?: number;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Result of a scroll operation.
|
|
135
|
+
*/
|
|
136
|
+
export interface ScrollResult {
|
|
137
|
+
success: boolean;
|
|
138
|
+
error?: string;
|
|
139
|
+
suggestion?: string;
|
|
140
|
+
exitCode?: number;
|
|
141
|
+
scrollType: 'element' | 'position' | 'offset';
|
|
142
|
+
selector?: string;
|
|
143
|
+
scrolledTo?: {
|
|
144
|
+
x: number;
|
|
145
|
+
y: number;
|
|
146
|
+
};
|
|
147
|
+
scrolledBy?: {
|
|
148
|
+
x: number;
|
|
149
|
+
y: number;
|
|
150
|
+
};
|
|
151
|
+
viewportSize?: {
|
|
152
|
+
width: number;
|
|
153
|
+
height: number;
|
|
154
|
+
};
|
|
155
|
+
pageSize?: {
|
|
156
|
+
width: number;
|
|
157
|
+
height: number;
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Scroll the page to an element, by offset, or to a position.
|
|
162
|
+
*
|
|
163
|
+
* Supports three scroll modes:
|
|
164
|
+
* 1. Element scroll: Pass a selector to scroll element into view
|
|
165
|
+
* 2. Offset scroll: Pass up/down/left/right pixels
|
|
166
|
+
* 3. Position scroll: Pass top/bottom to scroll to page boundaries
|
|
167
|
+
*
|
|
168
|
+
* @param cdp - CDP connection
|
|
169
|
+
* @param selector - CSS selector (optional, for element scroll)
|
|
170
|
+
* @param options - Scroll options
|
|
171
|
+
* @returns Promise resolving to scroll result
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```typescript
|
|
175
|
+
* // Scroll element into view
|
|
176
|
+
* await scrollPage(cdp, 'footer');
|
|
177
|
+
*
|
|
178
|
+
* // Scroll down 500px
|
|
179
|
+
* await scrollPage(cdp, undefined, { down: 500 });
|
|
180
|
+
*
|
|
181
|
+
* // Scroll to bottom of page
|
|
182
|
+
* await scrollPage(cdp, undefined, { bottom: true });
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
185
|
+
export declare function scrollPage(cdp: CDPConnection, selector: string | undefined, options?: ScrollOptions): Promise<ScrollResult>;
|
|
114
186
|
//# sourceMappingURL=formFillHelpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formFillHelpers.d.ts","sourceRoot":"","sources":["../../../src/commands/dom/formFillHelpers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"formFillHelpers.d.ts","sourceRoot":"","sources":["../../../src/commands/dom/formFillHelpers.ts"],"names":[],"mappings":"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"}
|