channel-worker 1.0.26 → 1.0.27
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/lib/command-poller.js +10 -7
- package/package.json +1 -1
package/lib/command-poller.js
CHANGED
|
@@ -588,22 +588,25 @@ class CommandPoller {
|
|
|
588
588
|
try {
|
|
589
589
|
await send('DOM.enable');
|
|
590
590
|
// Focus target element via CDP
|
|
591
|
-
const
|
|
591
|
+
const rawSel = (focus_selector || '');
|
|
592
|
+
const isXpath = rawSel.startsWith('xpath:');
|
|
593
|
+
const sel = rawSel.replace('xpath:', '').replace(/'/g, "\\'").replace(/"/g, '\\"');
|
|
592
594
|
const focusResult = await send('Runtime.evaluate', {
|
|
593
595
|
expression: `
|
|
594
596
|
(function() {
|
|
595
|
-
|
|
596
|
-
if ('${sel}') {
|
|
597
|
-
|
|
598
|
-
|
|
597
|
+
let el = null;
|
|
598
|
+
if (${isXpath} && '${sel}') {
|
|
599
|
+
el = document.evaluate("${sel}", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
|
|
600
|
+
} else if ('${sel}') {
|
|
601
|
+
el = document.querySelector('${sel}');
|
|
599
602
|
}
|
|
600
|
-
|
|
603
|
+
if (el) { el.focus(); el.click(); return 'focused: ' + (el.tagName || '') + ' ' + (el.getAttribute('aria-label') || '').substring(0, 30); }
|
|
604
|
+
// Fallback: dialog editor
|
|
601
605
|
const dialog = document.querySelector('[role="dialog"]');
|
|
602
606
|
if (dialog) {
|
|
603
607
|
const editor = dialog.querySelector('[contenteditable="true"], [role="textbox"]');
|
|
604
608
|
if (editor) { editor.focus(); editor.click(); return 'focused_dialog'; }
|
|
605
609
|
}
|
|
606
|
-
// Fallback
|
|
607
610
|
const editors = document.querySelectorAll('[contenteditable="true"], [role="textbox"]');
|
|
608
611
|
for (const e of editors) {
|
|
609
612
|
if (e.offsetHeight >= 15) { e.focus(); e.click(); return 'focused_fallback'; }
|