Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"[javascript]": {
"editor.defaultFormatter": "biomejs.biome"
}
}
8 changes: 8 additions & 0 deletions src/oc-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export function createOc(oc) {
let renderedComponents = oc.renderedComponents;
let dataRenderedAttribute = "data-rendered";
let dataRenderingAttribute = "data-rendering";
let nonce = $document.currentScript?.nonce;

let logError = (msg) => console.log(msg);
let logInfo = (msg) => ocConf.debug && console.log(msg);
let handleFetchResponse = (response) => {
Expand Down Expand Up @@ -124,6 +126,9 @@ export function createOc(oc) {
for (let attribute of Array.from(script.attributes)) {
newScript.setAttribute(attribute.name, attribute.value);
}
if (nonce) {
newScript.setAttribute("nonce", nonce);
}
script.parentNode?.replaceChild(newScript, script);
}
};
Expand All @@ -140,6 +145,9 @@ export function createOc(oc) {
oc.addStylesToHead = (styles) => {
let style = $document.createElement("style");
style.textContent = styles;
if (nonce) {
style.setAttribute("nonce", nonce);
}
$document.head.appendChild(style);
};

Expand Down