From a76e4a8a768e730719b2e84f92cea610f5af6b6e Mon Sep 17 00:00:00 2001 From: Thomas Walpole Date: Sat, 10 Oct 2020 22:29:07 -0700 Subject: [PATCH] Fix emoji sending in headless chrome --- lib/capybara/selenium/nodes/chrome_node.rb | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/capybara/selenium/nodes/chrome_node.rb b/lib/capybara/selenium/nodes/chrome_node.rb index 23d464496..e631aa740 100644 --- a/lib/capybara/selenium/nodes/chrome_node.rb +++ b/lib/capybara/selenium/nodes/chrome_node.rb @@ -78,12 +78,18 @@ def send_keys(*args) .each do |contains_emoji, inputs| if contains_emoji inputs.join.grapheme_clusters.chunk { |gc| gc.match?(/\p{Emoji Presentation}/) } - .each do |emoji, clusters| - if emoji - driver.send(:execute_cdp, 'Input.insertText', text: clusters.join) - else - super(clusters.join) - end + .each do |_emoji, clusters| + # For non-headless we can send non-emoji normally and then send emoji via CDP + # thereby getting key events and emoji. Unfortunately that doesn't work for + # headless chrome currently so just send via cdp + driver.send(:execute_cdp, 'Input.insertText', text: clusters.join) + + # .each do |emoji, clusters| + # if emoji + # driver.send(:execute_cdp, 'Input.insertText', text: clusters.join) + # else + # super(clusters.join) + # end end else super(*inputs)