From 8b2757b495a08a6d14cc7065738deec87edaa12e Mon Sep 17 00:00:00 2001 From: Avad3 <65318266+Avad3@users.noreply.github.com> Date: Mon, 6 May 2024 20:05:29 -0400 Subject: [PATCH] add meta rewriting and bundle preloading --- src/bundle/rewriters/html.ts | 12 ++++++++++-- static/index.html | 2 ++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/bundle/rewriters/html.ts b/src/bundle/rewriters/html.ts index 64cf834..e25a5ee 100644 --- a/src/bundle/rewriters/html.ts +++ b/src/bundle/rewriters/html.ts @@ -40,7 +40,9 @@ function traverseParsedHtml(node, origin?: string) { delete node.attribs.csp; } } else if (node.name === "link") { - delete node.attribs.integrity; + if (hasAttrib(node, "integrity")) { + delete node.attribs.integrity; + } node.attribs.href = encodeUrl(node.attribs.href, origin); @@ -52,7 +54,9 @@ function traverseParsedHtml(node, origin?: string) { } else if (node.name === "style") { node.children[0].data = rewriteCss(node.children[0].data, origin); } else if (node.name === "script") { - delete node.attribs.integrity; + if (hasAttrib(node, "integrity")) { + delete node.attribs.integrity; + } if (hasAttrib(node, "type") && /(application|text)\/javascript|importmap/.test(getAttributeValue(node, "type"))) { if (hasAttrib(node, "src")) { @@ -102,6 +106,10 @@ function traverseParsedHtml(node, origin?: string) { node.attribs.src = encodeUrl(node.attribs.src, origin); } else if (node.name === "video") { node.attribs.src = encodeUrl(node.attribs.src, origin); + } else if (node.name === "meta") { + if (hasAttrib(node, "http-equiv") && node.attribs["http-equiv"] === "content-security-policy") { + delete node.attribs["http-equiv"]; + } } if (node.childNodes) { diff --git a/static/index.html b/static/index.html index 7ce5310..f152779 100644 --- a/static/index.html +++ b/static/index.html @@ -4,6 +4,8 @@ Document + +