Skip to content

Commit 87124dc

Browse files
Fix CSP for element hiding (#314)
1 parent 3773e56 commit 87124dc

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/features/element-hiding.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,9 @@ function extractTimeoutRules (rules) {
224224
* @param {string} rules[].type
225225
*/
226226
function injectStyleTag (rules) {
227-
const styleTag = document.createElement('style')
227+
const styleTag = document.createElement('link')
228+
styleTag.setAttribute('rel', 'stylesheet')
229+
styleTag.setAttribute('type', 'text/css')
228230
let styleTagContents = ''
229231

230232
rules.forEach((rule, i) => {
@@ -236,7 +238,7 @@ function injectStyleTag (rules) {
236238
})
237239

238240
styleTagContents = styleTagContents.concat('{display:none!important;min-height:0!important;height:0!important;}')
239-
styleTag.innerText = styleTagContents
241+
styleTag.href = 'data:text/css,' + encodeURIComponent(styleTagContents)
240242

241243
document.head.appendChild(styleTag)
242244
}

0 commit comments

Comments
 (0)