Skip to content

Commit 62c51dc

Browse files
sherwinskisherwinski
authored andcommitted
refactor: favor directly modifying DOM attributes over setAttribute
According to https://stackoverflow.com/a/57633533 setAttribute() invokes the HTML parser, which can trigger a CSP violation. This change refactors style element construction/manipulation to not leverage setAttribute().
1 parent 0ceb096 commit 62c51dc

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/js/ZoomPane.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ export default class ZoomPane {
242242
removeClasses(this.el, this.closingClasses);
243243
removeClasses(this.el, this.inlineClasses);
244244

245-
this.el.setAttribute("style", "");
245+
this.el.style = "";
246246

247247
// The window could have been resized above or below `inline`
248248
// limits since the ZoomPane was shown. Because of this, we

src/js/injectBaseStylesheet.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,11 @@ export default function injectBaseStylesheet() {
5757

5858
const styleEl = document.createElement("style");
5959
styleEl.type = "text/css";
60-
styleEl.classList.add("drift-base-styles");
61-
62-
styleEl.appendChild(document.createTextNode(RULES));
60+
styleEl.classList = "drift-base-styles";
6361

62+
styleEl.textContent = RULES;
6463
const head = document.head;
65-
head.insertBefore(styleEl, head.firstChild);
64+
65+
const allHeadElements = head.getElementsByTagName("*");
66+
allHeadElements.innerHTML = styleEl + allHeadElements.innerHTML;
6667
}

0 commit comments

Comments
 (0)