From 35a2ed62c766fdf92bf4e36ee24a66f1baf4ed5e Mon Sep 17 00:00:00 2001 From: Josh at WLTechBlog Date: Tue, 19 Aug 2025 07:57:25 -0500 Subject: [PATCH] bump --- daemon/daemon.go | 99 +++++++++++++++++++++++------------------------- 1 file changed, 48 insertions(+), 51 deletions(-) diff --git a/daemon/daemon.go b/daemon/daemon.go index 65e10b3..e7d27df 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -1967,29 +1967,28 @@ func (d *Daemon) selectElement(tabID, selector, value string, selectionTimeout, // If text selection failed, use JavaScript as fallback // This handles both option value and option text selection script := fmt.Sprintf(` - (function() { - var select = document.querySelector("%s"); - if (!select) return null; - + 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 })); - return select.value; - } - - // 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 })); - return select.value; + 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; + } } } - - return null; - })() + } + result; `, selector, value, value, value) // Execute JavaScript and get the result @@ -3602,29 +3601,28 @@ func (d *Daemon) interactMultiple(tabID, interactionsJSON string, timeout int) ( // If text selection failed, use JavaScript as fallback // This handles both option value and option text selection script := fmt.Sprintf(` - (function() { - var select = document.querySelector("%s"); - if (!select) return null; - + 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 })); - return select.value; - } - - // 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 })); - return select.value; + 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; + } } } - - return null; - })() + } + result; `, interaction.Selector, interaction.Value, interaction.Value, interaction.Value) // Execute JavaScript and get the result @@ -3824,29 +3822,28 @@ func (d *Daemon) fillFormBulk(tabID, formSelector, fieldsJSON string, timeout in // If text selection failed, use JavaScript as fallback // This handles both option value and option text selection script := fmt.Sprintf(` - (function() { - var select = document.querySelector("%s"); - if (!select) return null; - + 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 })); - return select.value; - } - - // 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 })); - return select.value; + 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; + } } } - - return null; - })() + } + result; `, fieldResult.Selector, fieldValue, fieldValue, fieldValue) // Execute JavaScript and get the result