Skip to content
Discussion options

You must be logged in to vote

You could parse pageData.content with the DOMParser API, remove nodes from the resulting document, and serialize it into HTML just before calling new Blob([pageData.content]). See below.

// ...

const doc = new DOMParser().parseFromString(pageData.content, "text/html");
doc.querySelectorAll("div.ads").forEach(element => element.remove()); // remove some elements
pageData.content = getDoctypeString(doc) + doc.documentElement.outerHTML;

linkElement.href = URL.createObjectURL(new Blob([pageData.content], { type: "text/html" }));
// ...


function getDoctypeString(doc) {
  const docType = doc.doctype;
  let docTypeString = "";
  if (docType) {
    docTypeString = "<!DOCTYPE " + docType.nodeName

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@tangxiaoqi-tangxiao
Comment options

Answer selected by tangxiaoqi-tangxiao
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants