From 942c1ee9874e01a4bf469f46320e6f362835e8d7 Mon Sep 17 00:00:00 2001 From: Josh at WLTechBlog Date: Tue, 19 Aug 2025 08:41:15 -0500 Subject: [PATCH] bump --- daemon/daemon.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/daemon/daemon.go b/daemon/daemon.go index f10bc2f..26c7354 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -1965,8 +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 - // 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) + // Use the simplest approach that works with rod - just set the value and dispatch event + script := fmt.Sprintf(`document.querySelector("%s").value = "%s"; document.querySelector("%s").dispatchEvent(new Event('change', { bubbles: true })); document.querySelector("%s").value`, selector, value, selector, selector) // Execute JavaScript and get the result result, err := page.Eval(script) @@ -1974,9 +1974,9 @@ func (d *Daemon) selectElement(tabID, selector, value string, selectionTimeout, return fmt.Errorf("failed to execute JavaScript selection: %w", err) } - // Check if JavaScript selection worked - if result.Value.Nil() { - return fmt.Errorf("failed to select option '%s' in element (no matching option found)", value) + // Verify the selection worked by checking the returned value + if result.Value.Nil() || result.Value.String() == "" { + return fmt.Errorf("failed to select option '%s' in element", value) } } @@ -3576,15 +3576,15 @@ 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 - // 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) + // Use the simplest approach that works with rod - just set the value and dispatch event + script := fmt.Sprintf(`document.querySelector("%s").value = "%s"; document.querySelector("%s").dispatchEvent(new Event('change', { bubbles: true })); document.querySelector("%s").value`, interaction.Selector, interaction.Value, interaction.Selector, interaction.Selector) // Execute JavaScript and get the result result, err := page.Eval(script) if err != nil { interactionResult.Error = fmt.Sprintf("failed to execute JavaScript selection: %v", err) - } else if result.Value.Nil() { - interactionResult.Error = fmt.Sprintf("failed to select option '%s' (no matching option found)", interaction.Value) + } else if result.Value.Nil() || result.Value.String() == "" { + interactionResult.Error = fmt.Sprintf("failed to select option '%s'", interaction.Value) } else { interactionResult.Success = true } @@ -3774,16 +3774,16 @@ 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 - // 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) + // Use the simplest approach that works with rod - just set the value and dispatch event + script := fmt.Sprintf(`document.querySelector("%s").value = "%s"; document.querySelector("%s").dispatchEvent(new Event('change', { bubbles: true })); document.querySelector("%s").value`, fieldResult.Selector, fieldValue, fieldResult.Selector, fieldResult.Selector) // Execute JavaScript and get the result jsResult, err := page.Eval(script) if err != nil { fieldResult.Error = fmt.Sprintf("failed to execute JavaScript selection: %v", err) result.ErrorCount++ - } else if jsResult.Value.Nil() { - fieldResult.Error = fmt.Sprintf("failed to select option '%s' (no matching option found)", fieldValue) + } else if jsResult.Value.Nil() || jsResult.Value.String() == "" { + fieldResult.Error = fmt.Sprintf("failed to select option '%s'", fieldValue) result.ErrorCount++ } else { fieldResult.Success = true