From 4b270ba07871d1bd23b14d6bd1800a549d5937c1 Mon Sep 17 00:00:00 2001 From: Chris Taylor Date: Mon, 21 Sep 2026 23:17:00 +0100 Subject: [PATCH 1/2] Count and replace from one set of instances (#135) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Counting measured an element's innerHTML as a string; replacing drove a TreeWalker. They disagreed, and the disagreement was visible: a page with a match in a script and one in a style reported 2 matches and replaced 4, so Replace Next went 2 -> 1 -> 1 -> 1 -> 0, appearing to stall on the matches the count had never admitted to. The two cannot be reconciled by patching either side. Making the count read the unfiltered original — so it stops missing the script and the style — takes the invariant suite from 4 failures to 13, because the count then disagrees about hidden text and input values instead. An innerHTML string cannot express scope: the text of a hidden element, of a script and of an input are all in it, whether or not any of them is in scope for this search. So collect the matches once, from nodes rather than strings, and have both operations read the list: text a text node, which covers prose and script and style contents attribute an attribute value, in scope only when replacing HTML markup a match that exists only in the tags, e.g. searching for "