File tree Expand file tree Collapse file tree 2 files changed +11
-3
lines changed
Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,12 @@ export default class HeadHtmlSupport {
3131 const update = ( obj , keys ) => {
3232 keys . sort ( ) ;
3333 for ( const k of keys ) {
34+ if ( k === 'nonce' ) {
35+ // ignore nonce attribute, because it can change on every request
36+ // eslint-disable-next-line no-continue
37+ continue ;
38+ }
39+
3440 let v = obj [ k ] ;
3541 if ( v !== undefined ) {
3642 if ( Array . isArray ( v ) ) {
Original file line number Diff line number Diff line change @@ -89,19 +89,21 @@ const utils = {
8989 if ( match ) {
9090 const { index } = match ;
9191 // eslint-disable-next-line no-param-reassign
92+ const nonceMatch = body . match ( / n o n c e = " ( [ a - z A - Z 0 - 9 + / = ] + ) " / ) ;
93+ const nonce = nonceMatch ? ` nonce="${ nonceMatch [ 1 ] } "` : '' ;
9294 let newbody = body . substring ( 0 , index ) ;
9395 if ( process . env . CODESPACES === 'true' ) {
94- newbody += `<script>
96+ newbody += `<script${ nonce } >
9597window.LiveReloadOptions = {
9698 host: new URL(location.href).hostname.replace(/-[0-9]+\\.preview\\.app\\.github\\.dev/, '-35729.preview.app.github.dev'),
9799 port: 443,
98100 https: true,
99101};
100102</script>` ;
101103 } else {
102- newbody += `<script>window.LiveReloadOptions={port:${ server . port } ,host:location.hostname,https:${ server . scheme === 'https' } };</script>` ;
104+ newbody += `<script${ nonce } >window.LiveReloadOptions={port:${ server . port } ,host:location.hostname,https:${ server . scheme === 'https' } };</script>` ;
103105 }
104- newbody += ' <script src="/__internal__/livereload.js"></script>' ;
106+ newbody += ` <script${ nonce } src="/__internal__/livereload.js"></script>` ;
105107 newbody += body . substring ( index ) ;
106108 return newbody ;
107109 }
You can’t perform that action at this time.
0 commit comments