Stripping HTML from within edge function

I have some data that I fetch externally. One of the properties contains encoded HTML as a string.
I need to parse and retrieve only the text from this html.

I was trying to use the deno-dom package like so:

import { DOMParser } from "https://deno.land/x/deno_dom@v0.1.43/deno-dom-wasm.ts"
...
stripHTML(encoded: string) {
  const html = new DOMParser().parseFromString(encoded, 'text/html');
  return html?.textContent || '';
}


But I'm getting 546 error CPU time limit reached with this approach.
Is there any way I can achieve the same result without hitting the cpu limit?
Was this page helpful?