Reading HTML content within meta tags in HTML

Anyone here have an implementation on how to use HTMLwriter to read meta tags within an html?

Meta tags can be retrieved with a “head > meta” element selector like so:

new HTMLRewriter()
    .on('head > meta', {
        element(e) {
            // get attributes to read tags
            // not all meta tags have a name and value
            let name = e.getAttribute("name")
            let value = e.getAttribute("value")
            console.log("name:", name, "value:", value)
        }
    });

HTMLRewriter docs with more info: https://developers.cloudflare.com/workers/runtime-apis/html-rewriter

1 Like