Skip to content

Commit cc01ca4

Browse files
add nonce from current
1 parent 45829f1 commit cc01ca4

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"[javascript]": {
3+
"editor.defaultFormatter": "biomejs.biome"
4+
}
5+
}

src/oc-client.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ export function createOc(oc) {
3838
let renderedComponents = oc.renderedComponents;
3939
let dataRenderedAttribute = "data-rendered";
4040
let dataRenderingAttribute = "data-rendering";
41+
let nonce = $document.currentScript?.nonce;
42+
4143
let logError = (msg) => console.log(msg);
4244
let logInfo = (msg) => ocConf.debug && console.log(msg);
4345
let handleFetchResponse = (response) => {
@@ -124,8 +126,8 @@ export function createOc(oc) {
124126
for (let attribute of Array.from(script.attributes)) {
125127
newScript.setAttribute(attribute.name, attribute.value);
126128
}
127-
if (ocConf.cspNonce) {
128-
newScript.setAttribute("nonce", ocConf.cspNonce);
129+
if (nonce) {
130+
newScript.setAttribute("nonce", nonce);
129131
}
130132
script.parentNode?.replaceChild(newScript, script);
131133
}
@@ -143,8 +145,8 @@ export function createOc(oc) {
143145
oc.addStylesToHead = (styles) => {
144146
let style = $document.createElement("style");
145147
style.textContent = styles;
146-
if (ocConf.cspNonce) {
147-
style.setAttribute("nonce", ocConf.cspNonce);
148+
if (nonce) {
149+
style.setAttribute("nonce", nonce);
148150
}
149151
$document.head.appendChild(style);
150152
};

0 commit comments

Comments
 (0)