@@ -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