HTMLRewriter dynamic text replacement on all elements

Hi @user6964, try using text.replace(content, { html: true }).

The { html: true } option tells HTMLRewriter not to escape any of the new content, but instead to insert it raw. Most of the various .before(), .after(), .prepend(), .append(), and .replace() functions accept the option.

See: HTMLRewriter · Cloudflare Workers docs

2 Likes