Skip to content

Commit

Permalink
fix: replace innerHTML with trustedTypes (#808)
Browse files Browse the repository at this point in the history
Signed-off-by: anuoua <[email protected]>
Co-authored-by: L <[email protected]>
  • Loading branch information
anuoua and louisgv authored Nov 10, 2023
1 parent 99c0c61 commit f5e880b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion core/parcel-runtime/src/utils/loading-indicator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@

const LOADING_ID = "__plasmo-loading__"

const trustedPolicy = typeof trustedTypes !== "undefined"
? trustedTypes
.createPolicy(`trusted-html-${LOADING_ID}`, { createHTML: str => str })
: undefined

function getLoader() {
return document.getElementById(LOADING_ID)
}
Expand All @@ -22,7 +27,7 @@ function createLoader() {
const loadingEl = document.createElement("div")
loadingEl.id = LOADING_ID

loadingEl.innerHTML = `
const htmlText = `
<style>
#${LOADING_ID} {
background: #f3f3f3;
Expand Down Expand Up @@ -72,6 +77,8 @@ function createLoader() {
<span class="hidden">Context Invalidated, Press to Reload</span>
`

loadingEl.innerHTML = trustedPolicy ? trustedPolicy.createHTML(htmlText) : htmlText

loadingEl.style.pointerEvents = "none"

loadingEl.style.position = "fixed"
Expand Down

0 comments on commit f5e880b

Please sign in to comment.