cdp-mcp-server 5.0.1 → 5.0.3

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.
@@ -141,38 +141,38 @@ async function fillText(ctx, sess, uid, value, tabId) {
141
141
  const axInfo = await getAXNodeInfo(ctx, sess, uid, tabId);
142
142
  // Focus, clear, and set value using React-compatible approach
143
143
  await ctx.sendCommand('Runtime.callFunctionOn', {
144
- functionDeclaration: `function() {
145
- this.scrollIntoView({ block: "center" });
146
- this.focus();
147
- // Clear existing value
148
- if ('value' in this) {
149
- const nativeSetter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')?.set
150
- || Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype, 'value')?.set;
151
- if (nativeSetter) nativeSetter.call(this, '');
152
- else this.value = '';
153
- this.dispatchEvent(new Event('input', { bubbles: true }));
154
- } else if (this.isContentEditable) {
155
- this.textContent = '';
156
- }
144
+ functionDeclaration: `function() {
145
+ this.scrollIntoView({ block: "center" });
146
+ this.focus();
147
+ // Clear existing value
148
+ if ('value' in this) {
149
+ const nativeSetter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')?.set
150
+ || Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype, 'value')?.set;
151
+ if (nativeSetter) nativeSetter.call(this, '');
152
+ else this.value = '';
153
+ this.dispatchEvent(new Event('input', { bubbles: true }));
154
+ } else if (this.isContentEditable) {
155
+ this.textContent = '';
156
+ }
157
157
  }`,
158
158
  objectId,
159
159
  returnByValue: true,
160
160
  }, sess);
161
161
  // Set the value using native setter for React/Angular compatibility
162
162
  const result = await ctx.sendCommand('Runtime.callFunctionOn', {
163
- functionDeclaration: `function() {
164
- const val = ${JSON.stringify(value)};
165
- if ('value' in this) {
166
- const nativeSetter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')?.set
167
- || Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype, 'value')?.set;
168
- if (nativeSetter) nativeSetter.call(this, val);
169
- else this.value = val;
170
- } else if (this.isContentEditable) {
171
- this.textContent = val;
172
- }
173
- this.dispatchEvent(new Event('input', { bubbles: true }));
174
- this.dispatchEvent(new Event('change', { bubbles: true }));
175
- return { ok: true };
163
+ functionDeclaration: `function() {
164
+ const val = ${JSON.stringify(value)};
165
+ if ('value' in this) {
166
+ const nativeSetter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')?.set
167
+ || Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype, 'value')?.set;
168
+ if (nativeSetter) nativeSetter.call(this, val);
169
+ else this.value = val;
170
+ } else if (this.isContentEditable) {
171
+ this.textContent = val;
172
+ }
173
+ this.dispatchEvent(new Event('input', { bubbles: true }));
174
+ this.dispatchEvent(new Event('change', { bubbles: true }));
175
+ return { ok: true };
176
176
  }`,
177
177
  objectId,
178
178
  returnByValue: true,
@@ -200,16 +200,16 @@ async function fillCombobox(ctx, sess, uid, value, tabId) {
200
200
  const axInfo = await getAXNodeInfo(ctx, sess, uid, tabId);
201
201
  // 1. Focus and clear the combobox
202
202
  await ctx.sendCommand('Runtime.callFunctionOn', {
203
- functionDeclaration: `function() {
204
- this.scrollIntoView({ block: "center" });
205
- this.focus();
206
- if ('value' in this) {
207
- const nativeSetter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')?.set
208
- || Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype, 'value')?.set;
209
- if (nativeSetter) nativeSetter.call(this, '');
210
- else this.value = '';
211
- this.dispatchEvent(new Event('input', { bubbles: true }));
212
- }
203
+ functionDeclaration: `function() {
204
+ this.scrollIntoView({ block: "center" });
205
+ this.focus();
206
+ if ('value' in this) {
207
+ const nativeSetter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')?.set
208
+ || Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype, 'value')?.set;
209
+ if (nativeSetter) nativeSetter.call(this, '');
210
+ else this.value = '';
211
+ this.dispatchEvent(new Event('input', { bubbles: true }));
212
+ }
213
213
  }`,
214
214
  objectId,
215
215
  returnByValue: true,
@@ -228,8 +228,8 @@ async function fillCombobox(ctx, sess, uid, value, tabId) {
228
228
  let controlledListboxId = null;
229
229
  try {
230
230
  const controlsResult = await ctx.sendCommand('Runtime.callFunctionOn', {
231
- functionDeclaration: `function() {
232
- return this.getAttribute('aria-controls') || this.getAttribute('aria-owns') || '';
231
+ functionDeclaration: `function() {
232
+ return this.getAttribute('aria-controls') || this.getAttribute('aria-owns') || '';
233
233
  }`,
234
234
  objectId,
235
235
  returnByValue: true,
@@ -363,14 +363,14 @@ async function fillCombobox(ctx, sess, uid, value, tabId) {
363
363
  const shortValue = value.substring(0, 3);
364
364
  // Clear and retype with shorter prefix
365
365
  await ctx.sendCommand('Runtime.callFunctionOn', {
366
- functionDeclaration: `function() {
367
- if ('value' in this) {
368
- const nativeSetter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')?.set
369
- || Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype, 'value')?.set;
370
- if (nativeSetter) nativeSetter.call(this, '');
371
- else this.value = '';
372
- this.dispatchEvent(new Event('input', { bubbles: true }));
373
- }
366
+ functionDeclaration: `function() {
367
+ if ('value' in this) {
368
+ const nativeSetter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')?.set
369
+ || Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype, 'value')?.set;
370
+ if (nativeSetter) nativeSetter.call(this, '');
371
+ else this.value = '';
372
+ this.dispatchEvent(new Event('input', { bubbles: true }));
373
+ }
374
374
  }`,
375
375
  objectId,
376
376
  returnByValue: true,
@@ -413,9 +413,9 @@ async function fillCombobox(ctx, sess, uid, value, tabId) {
413
413
  }, sess);
414
414
  if (resolved?.object?.objectId) {
415
415
  await ctx.sendCommand('Runtime.callFunctionOn', {
416
- functionDeclaration: `function() {
417
- this.scrollIntoView({ block: "center" });
418
- this.click();
416
+ functionDeclaration: `function() {
417
+ this.scrollIntoView({ block: "center" });
418
+ this.click();
419
419
  }`,
420
420
  objectId: resolved.object.objectId,
421
421
  returnByValue: true,
@@ -489,15 +489,15 @@ async function fillCheckbox(ctx, sess, uid, value, tabId) {
489
489
  const axInfo = await getAXNodeInfo(ctx, sess, uid, tabId);
490
490
  const desired = value === 'true' || value === '1' || value === 'yes';
491
491
  const result = await ctx.sendCommand('Runtime.callFunctionOn', {
492
- functionDeclaration: `function() {
493
- this.scrollIntoView({ block: "center" });
494
- const desired = ${desired};
495
- const current = this.checked || this.getAttribute('aria-checked') === 'true';
496
- if (current !== desired) {
497
- this.click();
498
- this.dispatchEvent(new Event('change', { bubbles: true }));
499
- }
500
- return { checked: desired };
492
+ functionDeclaration: `function() {
493
+ this.scrollIntoView({ block: "center" });
494
+ const desired = ${desired};
495
+ const current = this.checked || this.getAttribute('aria-checked') === 'true';
496
+ if (current !== desired) {
497
+ this.click();
498
+ this.dispatchEvent(new Event('change', { bubbles: true }));
499
+ }
500
+ return { checked: desired };
501
501
  }`,
502
502
  objectId,
503
503
  returnByValue: true,
@@ -516,10 +516,10 @@ async function fillRadio(ctx, sess, uid, value, tabId) {
516
516
  const { objectId } = await resolveUidToObjectId(ctx, sess, uid, tabId);
517
517
  const axInfo = await getAXNodeInfo(ctx, sess, uid, tabId);
518
518
  await ctx.sendCommand('Runtime.callFunctionOn', {
519
- functionDeclaration: `function() {
520
- this.scrollIntoView({ block: "center" });
521
- this.click();
522
- this.dispatchEvent(new Event('change', { bubbles: true }));
519
+ functionDeclaration: `function() {
520
+ this.scrollIntoView({ block: "center" });
521
+ this.click();
522
+ this.dispatchEvent(new Event('change', { bubbles: true }));
523
523
  }`,
524
524
  objectId,
525
525
  returnByValue: true,
@@ -538,36 +538,36 @@ async function fillSelect(ctx, sess, uid, value, tabId) {
538
538
  const { objectId } = await resolveUidToObjectId(ctx, sess, uid, tabId);
539
539
  const axInfo = await getAXNodeInfo(ctx, sess, uid, tabId);
540
540
  const result = await ctx.sendCommand('Runtime.callFunctionOn', {
541
- functionDeclaration: `function() {
542
- this.scrollIntoView({ block: "center" });
543
- const val = ${JSON.stringify(value)};
544
-
545
- if (this.tagName === 'SELECT') {
546
- let opt = Array.from(this.options).find(o => o.value === val || o.textContent.trim() === val);
547
- if (!opt) {
548
- // Case-insensitive match
549
- opt = Array.from(this.options).find(o =>
550
- o.value.toLowerCase() === val.toLowerCase() ||
551
- o.textContent.trim().toLowerCase() === val.toLowerCase()
552
- );
553
- }
554
- if (!opt) {
555
- const available = Array.from(this.options).map(o => o.textContent.trim()).filter(Boolean);
556
- return { error: "Option not found: " + val, available };
557
- }
558
-
559
- const nativeSetter = Object.getOwnPropertyDescriptor(HTMLSelectElement.prototype, 'value')?.set;
560
- if (nativeSetter) nativeSetter.call(this, opt.value);
561
- else this.value = opt.value;
562
-
563
- this.dispatchEvent(new Event('input', { bubbles: true }));
564
- this.dispatchEvent(new Event('change', { bubbles: true }));
565
- return { selected: opt.textContent.trim() };
566
- }
567
-
568
- // Custom dropdown — click to open, then look for matching option
569
- this.click();
570
- return { customDropdown: true };
541
+ functionDeclaration: `function() {
542
+ this.scrollIntoView({ block: "center" });
543
+ const val = ${JSON.stringify(value)};
544
+
545
+ if (this.tagName === 'SELECT') {
546
+ let opt = Array.from(this.options).find(o => o.value === val || o.textContent.trim() === val);
547
+ if (!opt) {
548
+ // Case-insensitive match
549
+ opt = Array.from(this.options).find(o =>
550
+ o.value.toLowerCase() === val.toLowerCase() ||
551
+ o.textContent.trim().toLowerCase() === val.toLowerCase()
552
+ );
553
+ }
554
+ if (!opt) {
555
+ const available = Array.from(this.options).map(o => o.textContent.trim()).filter(Boolean);
556
+ return { error: "Option not found: " + val, available };
557
+ }
558
+
559
+ const nativeSetter = Object.getOwnPropertyDescriptor(HTMLSelectElement.prototype, 'value')?.set;
560
+ if (nativeSetter) nativeSetter.call(this, opt.value);
561
+ else this.value = opt.value;
562
+
563
+ this.dispatchEvent(new Event('input', { bubbles: true }));
564
+ this.dispatchEvent(new Event('change', { bubbles: true }));
565
+ return { selected: opt.textContent.trim() };
566
+ }
567
+
568
+ // Custom dropdown — click to open, then look for matching option
569
+ this.click();
570
+ return { customDropdown: true };
571
571
  }`,
572
572
  objectId,
573
573
  returnByValue: true,
@@ -586,21 +586,21 @@ async function fillSelect(ctx, sess, uid, value, tabId) {
586
586
  // Wait for dropdown to open, then find and click the option
587
587
  await sleep(300);
588
588
  const clickResult = await ctx.sendCommand('Runtime.evaluate', {
589
- expression: `(() => {
590
- const val = ${JSON.stringify(value)};
591
- const valLower = val.toLowerCase();
592
- const options = document.querySelectorAll('[role="option"], [role="listitem"], li[data-value], .MuiMenuItem-root, .ant-select-item, [class*="option"]');
593
- for (const opt of options) {
594
- const text = opt.textContent.trim();
595
- const optValue = opt.getAttribute("data-value") || opt.getAttribute("value") || "";
596
- if (text === val || optValue === val || text.toLowerCase() === valLower) {
597
- opt.scrollIntoView({ block: "center" });
598
- opt.click();
599
- return { selected: text };
600
- }
601
- }
602
- const available = Array.from(options).slice(0, 10).map(o => o.textContent.trim());
603
- return { error: "Option not found in custom dropdown", available };
589
+ expression: `(() => {
590
+ const val = ${JSON.stringify(value)};
591
+ const valLower = val.toLowerCase();
592
+ const options = document.querySelectorAll('[role="option"], [role="listitem"], li[data-value], .MuiMenuItem-root, .ant-select-item, [class*="option"]');
593
+ for (const opt of options) {
594
+ const text = opt.textContent.trim();
595
+ const optValue = opt.getAttribute("data-value") || opt.getAttribute("value") || "";
596
+ if (text === val || optValue === val || text.toLowerCase() === valLower) {
597
+ opt.scrollIntoView({ block: "center" });
598
+ opt.click();
599
+ return { selected: text };
600
+ }
601
+ }
602
+ const available = Array.from(options).slice(0, 10).map(o => o.textContent.trim());
603
+ return { error: "Option not found in custom dropdown", available };
604
604
  })()`,
605
605
  returnByValue: true,
606
606
  }, sess);
@@ -620,19 +620,19 @@ async function fillDate(ctx, sess, uid, value, tabId) {
620
620
  const { objectId } = await resolveUidToObjectId(ctx, sess, uid, tabId);
621
621
  const axInfo = await getAXNodeInfo(ctx, sess, uid, tabId);
622
622
  const result = await ctx.sendCommand('Runtime.callFunctionOn', {
623
- functionDeclaration: `function() {
624
- this.scrollIntoView({ block: "center" });
625
- this.focus();
626
- const val = ${JSON.stringify(value)};
627
-
628
- // Native date input
629
- const nativeSetter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')?.set;
630
- if (nativeSetter) nativeSetter.call(this, val);
631
- else this.value = val;
632
-
633
- this.dispatchEvent(new Event('input', { bubbles: true }));
634
- this.dispatchEvent(new Event('change', { bubbles: true }));
635
- return { ok: true };
623
+ functionDeclaration: `function() {
624
+ this.scrollIntoView({ block: "center" });
625
+ this.focus();
626
+ const val = ${JSON.stringify(value)};
627
+
628
+ // Native date input
629
+ const nativeSetter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')?.set;
630
+ if (nativeSetter) nativeSetter.call(this, val);
631
+ else this.value = val;
632
+
633
+ this.dispatchEvent(new Event('input', { bubbles: true }));
634
+ this.dispatchEvent(new Event('change', { bubbles: true }));
635
+ return { ok: true };
636
636
  }`,
637
637
  objectId,
638
638
  returnByValue: true,
@@ -705,16 +705,16 @@ async function fillLocation(ctx, sess, uid, value, tabId) {
705
705
  const axInfo = await getAXNodeInfo(ctx, sess, uid, tabId);
706
706
  // Focus and clear
707
707
  await ctx.sendCommand('Runtime.callFunctionOn', {
708
- functionDeclaration: `function() {
709
- this.scrollIntoView({ block: "center" });
710
- this.focus();
711
- if ('value' in this) {
712
- const nativeSetter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')?.set
713
- || Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype, 'value')?.set;
714
- if (nativeSetter) nativeSetter.call(this, '');
715
- else this.value = '';
716
- this.dispatchEvent(new Event('input', { bubbles: true }));
717
- }
708
+ functionDeclaration: `function() {
709
+ this.scrollIntoView({ block: "center" });
710
+ this.focus();
711
+ if ('value' in this) {
712
+ const nativeSetter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')?.set
713
+ || Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype, 'value')?.set;
714
+ if (nativeSetter) nativeSetter.call(this, '');
715
+ else this.value = '';
716
+ this.dispatchEvent(new Event('input', { bubbles: true }));
717
+ }
718
718
  }`,
719
719
  objectId,
720
720
  returnByValue: true,
@@ -753,9 +753,9 @@ async function fillLocation(ctx, sess, uid, value, tabId) {
753
753
  }, sess);
754
754
  if (resolved?.object?.objectId) {
755
755
  await ctx.sendCommand('Runtime.callFunctionOn', {
756
- functionDeclaration: `function() {
757
- this.scrollIntoView({ block: "center" });
758
- this.click();
756
+ functionDeclaration: `function() {
757
+ this.scrollIntoView({ block: "center" });
758
+ this.click();
759
759
  }`,
760
760
  objectId: resolved.object.objectId,
761
761
  returnByValue: true,
@@ -849,11 +849,11 @@ async function clearFields(ctx, sess, fields, tabId) {
849
849
  if (type === 'checkbox') {
850
850
  // Uncheck if checked
851
851
  await ctx.sendCommand('Runtime.callFunctionOn', {
852
- functionDeclaration: `function() {
853
- if (this.checked || this.getAttribute('aria-checked') === 'true') {
854
- this.click();
855
- this.dispatchEvent(new Event('change', { bubbles: true }));
856
- }
852
+ functionDeclaration: `function() {
853
+ if (this.checked || this.getAttribute('aria-checked') === 'true') {
854
+ this.click();
855
+ this.dispatchEvent(new Event('change', { bubbles: true }));
856
+ }
857
857
  }`,
858
858
  objectId,
859
859
  returnByValue: true,
@@ -863,18 +863,18 @@ async function clearFields(ctx, sess, fields, tabId) {
863
863
  else {
864
864
  // Clear text-like fields
865
865
  await ctx.sendCommand('Runtime.callFunctionOn', {
866
- functionDeclaration: `function() {
867
- this.focus();
868
- if ('value' in this) {
869
- const nativeSetter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')?.set
870
- || Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype, 'value')?.set;
871
- if (nativeSetter) nativeSetter.call(this, '');
872
- else this.value = '';
873
- } else if (this.isContentEditable) {
874
- this.textContent = '';
875
- }
876
- this.dispatchEvent(new Event('input', { bubbles: true }));
877
- this.dispatchEvent(new Event('change', { bubbles: true }));
866
+ functionDeclaration: `function() {
867
+ this.focus();
868
+ if ('value' in this) {
869
+ const nativeSetter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')?.set
870
+ || Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype, 'value')?.set;
871
+ if (nativeSetter) nativeSetter.call(this, '');
872
+ else this.value = '';
873
+ } else if (this.isContentEditable) {
874
+ this.textContent = '';
875
+ }
876
+ this.dispatchEvent(new Event('input', { bubbles: true }));
877
+ this.dispatchEvent(new Event('change', { bubbles: true }));
878
878
  }`,
879
879
  objectId,
880
880
  returnByValue: true,