So I am upgrading a Chrome extension to MV3 and the background page now becomes a Service Worker
. From this question apparently there is no access to any DOM element. I need to upgrade this function that basically get an HTML snippet and get its text content:
const htmlStripper = document.createElement("template")
const striphtml = html => {
htmlStripper.innerHTML = html
return htmlStripper.content.textContent
}
I tried using DocumentFragment
as well but it's also not available to Service Worker. Unlike the other question, I do not have access to any foreground HTML page so message passing is not possible as well.
What is a solution for this? Beside this specific problem (nice if I can solve this one), is there a generic solution for all kind of HTML processing we could have done as if we had access to a document
?
For my specific case, this solution is good enough, stealing from a C# solution:
const striphtml = html => {
return html.replace(/<.*?>/g, "").trim();
}
Be warned that this is not perfect.