From 5d5be7e1a991bd4caec52494faa179f19d477ad8 Mon Sep 17 00:00:00 2001 From: Josh at WLTechBlog Date: Tue, 19 Aug 2025 09:46:37 -0500 Subject: [PATCH] bump --- daemon/daemon.go | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/daemon/daemon.go b/daemon/daemon.go index 636e9cf..dfed477 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -1965,17 +1965,31 @@ 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 double quotes for the JavaScript string so single quotes in selectors work - 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) + // Use a simple single statement that works with rod's evaluation + script := fmt.Sprintf("document.querySelector(\"%s\").value = \"%s\"", selector, value) - // Execute JavaScript and get the result - result, err := page.Eval(script) + // Execute the value assignment + _, err = page.Eval(script) if err != nil { return fmt.Errorf("failed to execute JavaScript selection: %w", err) } + // Dispatch the change event separately + changeScript := fmt.Sprintf("document.querySelector(\"%s\").dispatchEvent(new Event(\"change\", { bubbles: true }))", selector) + _, err = page.Eval(changeScript) + if err != nil { + return fmt.Errorf("failed to dispatch change event: %w", err) + } + + // Verify the selection worked + verifyScript := fmt.Sprintf("document.querySelector(\"%s\").value", selector) + result, err := page.Eval(verifyScript) + if err != nil { + return fmt.Errorf("failed to verify selection: %w", err) + } + // Verify the selection worked by checking the returned value - if result.Value.Nil() || result.Value.String() == "" { + if result.Value.Nil() || result.Value.String() != value { return fmt.Errorf("failed to select option '%s' in element", value) } }