chrome-cdp-cli 2.0.4 → 2.1.0

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.
@@ -114,35 +114,99 @@ class ClickHandler {
114
114
  error: `Element with selector "${selector}" not found`
115
115
  };
116
116
  }
117
- await client.send('Input.dispatchMouseEvent', {
118
- type: 'mousePressed',
119
- x: coords.x,
120
- y: coords.y,
121
- button: 'left',
122
- clickCount: 1
123
- });
124
- await new Promise(resolve => setTimeout(resolve, 10));
125
- await client.send('Input.dispatchMouseEvent', {
126
- type: 'mouseReleased',
127
- x: coords.x,
128
- y: coords.y,
129
- button: 'left',
130
- clickCount: 1
131
- });
132
- return {
117
+ try {
118
+ await client.send('Input.dispatchMouseEvent', {
119
+ type: 'mousePressed',
120
+ x: coords.x,
121
+ y: coords.y,
122
+ button: 'left',
123
+ clickCount: 1
124
+ });
125
+ await new Promise(resolve => setTimeout(resolve, 10));
126
+ await client.send('Input.dispatchMouseEvent', {
127
+ type: 'mouseReleased',
128
+ x: coords.x,
129
+ y: coords.y,
130
+ button: 'left',
131
+ clickCount: 1
132
+ });
133
+ return {
134
+ success: true,
135
+ data: {
136
+ selector: selector,
137
+ element: {
138
+ success: true,
139
+ tagName: coords.tagName,
140
+ id: coords.id,
141
+ className: coords.className
142
+ },
143
+ method: 'Input.dispatchMouseEvent',
144
+ coordinates: { x: coords.x, y: coords.y }
145
+ }
146
+ };
147
+ }
148
+ catch (inputError) {
149
+ const fallbackExpression = `
150
+ (function() {
151
+ const e = document.querySelector('${escapedSelector}');
152
+ if (!e) return { success: false, error: 'Element not found' };
153
+ const r = e.getBoundingClientRect();
154
+ const p = { x: r.left + r.width / 2, y: r.top + r.height / 2 };
155
+ const topEl = document.elementFromPoint(p.x, p.y);
156
+ if (topEl) {
157
+ topEl.dispatchEvent(new MouseEvent('click', {
158
+ bubbles: true,
159
+ cancelable: true,
160
+ view: window,
161
+ clientX: p.x,
162
+ clientY: p.y,
163
+ button: 0
164
+ }));
165
+ return {
133
166
  success: true,
134
- data: {
135
- selector: selector,
136
- element: {
137
- success: true,
138
- tagName: coords.tagName,
139
- id: coords.id,
140
- className: coords.className
141
- },
142
- method: 'Input.dispatchMouseEvent',
143
- coordinates: { x: coords.x, y: coords.y }
167
+ tagName: e.tagName,
168
+ id: e.id,
169
+ className: e.className,
170
+ topElementTag: topEl.tagName
171
+ };
172
+ }
173
+ return { success: false, error: 'No element at point' };
174
+ })()
175
+ `;
176
+ const fallbackResponse = await client.send('Runtime.evaluate', {
177
+ expression: fallbackExpression,
178
+ returnByValue: true,
179
+ userGesture: true
180
+ });
181
+ if (fallbackResponse.exceptionDetails) {
182
+ return {
183
+ success: false,
184
+ error: `Input click failed and fallback also failed: ${fallbackResponse.exceptionDetails.exception?.description || fallbackResponse.exceptionDetails.text}`
185
+ };
144
186
  }
145
- };
187
+ const fallbackResult = fallbackResponse.result.value;
188
+ if (!fallbackResult.success) {
189
+ return {
190
+ success: false,
191
+ error: `Input click failed and fallback failed: ${fallbackResult.error || 'Unknown error'}`
192
+ };
193
+ }
194
+ return {
195
+ success: true,
196
+ data: {
197
+ selector: selector,
198
+ element: {
199
+ success: true,
200
+ tagName: fallbackResult.tagName || coords.tagName,
201
+ id: fallbackResult.id || coords.id,
202
+ className: fallbackResult.className || coords.className
203
+ },
204
+ method: 'dispatchEvent (fallback)',
205
+ coordinates: { x: coords.x, y: coords.y },
206
+ topElementTag: fallbackResult.topElementTag
207
+ }
208
+ };
209
+ }
146
210
  }
147
211
  catch (error) {
148
212
  return {