channel-worker 1.0.24 → 1.0.26
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 +24 -9
- package/package.json +1 -1
package/lib/command-poller.js
CHANGED
|
@@ -550,7 +550,7 @@ class CommandPoller {
|
|
|
550
550
|
}
|
|
551
551
|
|
|
552
552
|
async handleTypeText(command) {
|
|
553
|
-
const { text, profile_id, url_match } = command.payload || {};
|
|
553
|
+
const { text, profile_id, url_match, focus_selector } = command.payload || {};
|
|
554
554
|
console.log(`[commands] Typing text (${text?.length} chars) for profile: ${profile_id}`);
|
|
555
555
|
try {
|
|
556
556
|
const WebSocket = require('ws');
|
|
@@ -587,17 +587,32 @@ class CommandPoller {
|
|
|
587
587
|
ws.on('open', async () => {
|
|
588
588
|
try {
|
|
589
589
|
await send('DOM.enable');
|
|
590
|
-
// Focus
|
|
591
|
-
|
|
590
|
+
// Focus target element via CDP
|
|
591
|
+
const sel = (focus_selector || '').replace(/'/g, "\\'");
|
|
592
|
+
const focusResult = await send('Runtime.evaluate', {
|
|
592
593
|
expression: `
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
594
|
+
(function() {
|
|
595
|
+
// Use specific selector if provided
|
|
596
|
+
if ('${sel}') {
|
|
597
|
+
const el = document.querySelector('${sel}');
|
|
598
|
+
if (el) { el.focus(); el.click(); return 'focused_selector: ${sel}'; }
|
|
599
|
+
}
|
|
600
|
+
// Try dialog editor
|
|
601
|
+
const dialog = document.querySelector('[role="dialog"]');
|
|
602
|
+
if (dialog) {
|
|
603
|
+
const editor = dialog.querySelector('[contenteditable="true"], [role="textbox"]');
|
|
604
|
+
if (editor) { editor.focus(); editor.click(); return 'focused_dialog'; }
|
|
605
|
+
}
|
|
606
|
+
// Fallback
|
|
607
|
+
const editors = document.querySelectorAll('[contenteditable="true"], [role="textbox"]');
|
|
608
|
+
for (const e of editors) {
|
|
609
|
+
if (e.offsetHeight >= 15) { e.focus(); e.click(); return 'focused_fallback'; }
|
|
610
|
+
}
|
|
611
|
+
return 'no_editor';
|
|
612
|
+
})()
|
|
599
613
|
`,
|
|
600
614
|
});
|
|
615
|
+
console.log('[commands] Focus result:', focusResult?.result?.value);
|
|
601
616
|
// Small delay for focus to take effect
|
|
602
617
|
await new Promise(r => setTimeout(r, 300));
|
|
603
618
|
// Type text
|