#DOMParser is not defined

1 messages · Page 1 of 1 (latest)

alpine schooner
#

When fetching data, the description is in HTML5 as a string.

I want to parse that as text/html.

So, I did something like this:

---
const video = await fetch(DEFAULT_DATA_PROXY + "/api/v1/videos/" + SWV).then((response) => response.json())
const parser = new DOMParser()

const Description = video.description

const DescriptionFormat = parser.parseFromString(Description, 'text/html')
---

Then, once I add {DescriptionFormat} to the page, the following error is shown:

01:03:00 [ERROR] DOMParser is not defined
  Stack trace:
    at /run/media/korbs/Framework/Development/MinPluto/MinPluto/src/pages/watch.astro:18:16
    [...] See full stack trace in the browser, or rerun with --verbose.
true steeple
#

The frontmatter runs on the server, as such you cannot access DOMParser

#

If this is supposed to run on the client, it should be in a script tag

alpine schooner
#

This will run on the server, as stated the by the post's tag (SSR).

true steeple
#

Sure, but you can't access DOMParser on the server, that's the thing

alpine schooner
#

Sure, so an alternative will be put in place.