This commit is contained in:
Josh at WLTechBlog 2025-08-19 09:27:49 -05:00
parent 9a8200de41
commit 7974fdcfa3
1 changed files with 6 additions and 15 deletions

View File

@ -1965,11 +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 the simplest approach that works with rod - just set the value and dispatch event
// Escape quotes in selector and value to avoid JavaScript syntax errors
escapedSelector := strings.ReplaceAll(selector, "'", "\\'")
escapedValue := strings.ReplaceAll(value, "'", "\\'")
script := fmt.Sprintf(`document.querySelector('%s').value = '%s'; document.querySelector('%s').dispatchEvent(new Event('change', { bubbles: true })); document.querySelector('%s').value`, escapedSelector, escapedValue, escapedSelector, escapedSelector)
// 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)
// Execute JavaScript and get the result
result, err := page.Eval(script)
@ -3579,11 +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
// Use the simplest approach that works with rod - just set the value and dispatch event
// Escape quotes in selector and value to avoid JavaScript syntax errors
escapedSelector := strings.ReplaceAll(interaction.Selector, "'", "\\'")
escapedValue := strings.ReplaceAll(interaction.Value, "'", "\\'")
script := fmt.Sprintf(`document.querySelector('%s').value = '%s'; document.querySelector('%s').dispatchEvent(new Event('change', { bubbles: true })); document.querySelector('%s').value`, escapedSelector, escapedValue, escapedSelector, escapedSelector)
// 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`, interaction.Selector, interaction.Value, interaction.Selector, interaction.Selector)
// Execute JavaScript and get the result
result, err := page.Eval(script)
@ -3780,11 +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
// Use the simplest approach that works with rod - just set the value and dispatch event
// Escape quotes in selector and value to avoid JavaScript syntax errors
escapedSelector := strings.ReplaceAll(fieldResult.Selector, "'", "\\'")
escapedValue := strings.ReplaceAll(fieldValue, "'", "\\'")
script := fmt.Sprintf(`document.querySelector('%s').value = '%s'; document.querySelector('%s').dispatchEvent(new Event('change', { bubbles: true })); document.querySelector('%s').value`, escapedSelector, escapedValue, escapedSelector, escapedSelector)
// 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`, fieldResult.Selector, fieldValue, fieldResult.Selector, fieldResult.Selector)
// Execute JavaScript and get the result
jsResult, err := page.Eval(script)