UPDATE: this was solved, thanks to the Cloudflare Community Discord. See comments for the solution.
I've been wanting to kick the tires with Cloudflare's HTMLRewriter to see if it could be used as an HTML parser. As a simple example, can Cloudflare Workers + HTMLRewriter be used to build an API to parse OpenGraph metadata and return the properties as a JSON document? Based on a cursory review of the documentation, it appears as if this should be quite simple.
However, I have observed a race condition where HTMLRewriter will always find fewer than the present number of matching elements unless a simulate a 1 millisecond "sleep":
await new Promise( function(resolve) { setTimeout(resolve, 1); })