When using replace with optional capture groups findAndReplaceDOMText seems to replace empty capture group values with undefined in HTML (instead of empty string). Example:
findAndReplaceDOMText(context, {
find: /(This)(\s+)?(document),
replace: "$1$2$3",
});
ran against Thisdocument (in HTML) will result in Thisundefineddocument