From e2e44b40e2a520cedc1cea7140bab2dbf11a7622 Mon Sep 17 00:00:00 2001 From: Josh at WLTechBlog Date: Tue, 19 Aug 2025 08:03:06 -0500 Subject: [PATCH] bump --- daemon/daemon.go | 81 ++++-------------------------------------------- 1 file changed, 6 insertions(+), 75 deletions(-) diff --git a/daemon/daemon.go b/daemon/daemon.go index e7d27df..f10bc2f 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -1965,31 +1965,8 @@ func (d *Daemon) selectElement(tabID, selector, value string, selectionTimeout, err = element.Select([]string{value}, true, rod.SelectorTypeText) if err != nil { // If text selection failed, use JavaScript as fallback - // This handles both option value and option text selection - script := fmt.Sprintf(` - var select = document.querySelector("%s"); - var result = null; - if (select) { - // First try to select by value - select.value = "%s"; - if (select.value === "%s") { - select.dispatchEvent(new Event('change', { bubbles: true })); - result = select.value; - } else { - // If value selection failed, try to find by text content - var options = select.options; - for (var i = 0; i < options.length; i++) { - if (options[i].text === "%s") { - select.selectedIndex = i; - select.dispatchEvent(new Event('change', { bubbles: true })); - result = select.value; - break; - } - } - } - } - result; - `, selector, value, value, value) + // Use a single-line approach that works with rod's evaluation + script := fmt.Sprintf(`(() => { const select = document.querySelector("%s"); if (!select) return null; select.value = "%s"; if (select.value === "%s") { select.dispatchEvent(new Event('change', { bubbles: true })); return select.value; } for (let i = 0; i < select.options.length; i++) { if (select.options[i].text === "%s") { select.selectedIndex = i; select.dispatchEvent(new Event('change', { bubbles: true })); return select.value; } } return null; })()`, selector, value, value, value) // Execute JavaScript and get the result result, err := page.Eval(script) @@ -3599,31 +3576,8 @@ func (d *Daemon) interactMultiple(tabID, interactionsJSON string, timeout int) ( err = element.Select([]string{interaction.Value}, true, rod.SelectorTypeText) if err != nil { // If text selection failed, use JavaScript as fallback - // This handles both option value and option text selection - script := fmt.Sprintf(` - var select = document.querySelector("%s"); - var result = null; - if (select) { - // First try to select by value - select.value = "%s"; - if (select.value === "%s") { - select.dispatchEvent(new Event('change', { bubbles: true })); - result = select.value; - } else { - // If value selection failed, try to find by text content - var options = select.options; - for (var i = 0; i < options.length; i++) { - if (options[i].text === "%s") { - select.selectedIndex = i; - select.dispatchEvent(new Event('change', { bubbles: true })); - result = select.value; - break; - } - } - } - } - result; - `, interaction.Selector, interaction.Value, interaction.Value, interaction.Value) + // Use a single-line approach that works with rod's evaluation + script := fmt.Sprintf(`(() => { const select = document.querySelector("%s"); if (!select) return null; select.value = "%s"; if (select.value === "%s") { select.dispatchEvent(new Event('change', { bubbles: true })); return select.value; } for (let i = 0; i < select.options.length; i++) { if (select.options[i].text === "%s") { select.selectedIndex = i; select.dispatchEvent(new Event('change', { bubbles: true })); return select.value; } } return null; })()`, interaction.Selector, interaction.Value, interaction.Value, interaction.Value) // Execute JavaScript and get the result result, err := page.Eval(script) @@ -3820,31 +3774,8 @@ func (d *Daemon) fillFormBulk(tabID, formSelector, fieldsJSON string, timeout in err = element.Select([]string{fieldValue}, true, rod.SelectorTypeText) if err != nil { // If text selection failed, use JavaScript as fallback - // This handles both option value and option text selection - script := fmt.Sprintf(` - var select = document.querySelector("%s"); - var result = null; - if (select) { - // First try to select by value - select.value = "%s"; - if (select.value === "%s") { - select.dispatchEvent(new Event('change', { bubbles: true })); - result = select.value; - } else { - // If value selection failed, try to find by text content - var options = select.options; - for (var i = 0; i < options.length; i++) { - if (options[i].text === "%s") { - select.selectedIndex = i; - select.dispatchEvent(new Event('change', { bubbles: true })); - result = select.value; - break; - } - } - } - } - result; - `, fieldResult.Selector, fieldValue, fieldValue, fieldValue) + // Use a single-line approach that works with rod's evaluation + script := fmt.Sprintf(`(() => { const select = document.querySelector("%s"); if (!select) return null; select.value = "%s"; if (select.value === "%s") { select.dispatchEvent(new Event('change', { bubbles: true })); return select.value; } for (let i = 0; i < select.options.length; i++) { if (select.options[i].text === "%s") { select.selectedIndex = i; select.dispatchEvent(new Event('change', { bubbles: true })); return select.value; } } return null; })()`, fieldResult.Selector, fieldValue, fieldValue, fieldValue) // Execute JavaScript and get the result jsResult, err := page.Eval(script)