From be571337653d62b7fdac104d8dd1b44e6c67e706 Mon Sep 17 00:00:00 2001 From: Micah Geisel Date: Fri, 24 Feb 2023 12:03:16 -0600 Subject: [PATCH] Remember parentNode in case onChange callback mutates DOM There's no guarantee that the onChange callback won't mutate the DOM in some way that removes the selected option node, thus creating a runtime error when null.dispatchEvent is called when trying to trigger the "blur" event on the parent. By saving the parentNode in a variable, we avoid this edge-case scenario. --- lib/capybara/cuprite/javascripts/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/capybara/cuprite/javascripts/index.js b/lib/capybara/cuprite/javascripts/index.js index 3657add2..2bab9460 100644 --- a/lib/capybara/cuprite/javascripts/index.js +++ b/lib/capybara/cuprite/javascripts/index.js @@ -356,12 +356,13 @@ class Cuprite { } else if (value == false && !node.parentNode.multiple) { return false; } else { - this.trigger(node.parentNode, "focus"); + let parentNode = node.parentNode; + this.trigger(parentNode, "focus"); node.selected = value; this.changed(node); - this.trigger(node.parentNode, "blur"); + this.trigger(parentNode, "blur"); return true; } }