11'use strict' ;
22const fs = require ( 'fs' ) ;
3+ const crypto = require ( 'crypto' ) ;
34
45function readSnippet ( fileName ) {
5- return `<script> ${ fs . readFileSync ( `${ __dirname } /vendor/${ fileName } ` , 'utf8' ) } </script>` ;
6+ return fs . readFileSync ( `${ __dirname } /vendor/${ fileName } ` , 'utf8' ) ;
67}
78
9+ function hashSha256base64 ( string ) {
10+ return crypto . createHash ( 'sha256' ) . update ( string ) . digest ( 'base64' ) ;
11+ }
12+
13+ const initialLoadHeadSnippet = readSnippet ( 'initial-load-head.js' ) ;
14+ const initialLoadBodySnippet = readSnippet ( 'initial-load-body.js' ) ;
15+
16+ const initialLoadHeadSnippetHash = hashSha256base64 ( initialLoadHeadSnippet ) ;
17+ const initialLoadBodySnippetHash = hashSha256base64 ( initialLoadBodySnippet ) ;
18+
819module . exports = {
920 name : require ( './package' ) . name ,
1021 options : {
@@ -24,16 +35,18 @@ module.exports = {
2435
2536 contentFor ( type , config ) {
2637 const addonConfig = config [ '@sentry/ember' ] || { } ;
27-
2838 const { disablePerformance, disableInitialLoadInstrumentation } = addonConfig ;
39+
2940 if ( disablePerformance || disableInitialLoadInstrumentation ) {
3041 return ;
3142 }
43+
3244 if ( type === 'head' ) {
33- return readSnippet ( 'initial-load-head.js' ) ;
34- }
35- if ( type === 'body-footer' ) {
36- return readSnippet ( 'initial-load-body.js' ) ;
45+ return `<script type="text/javascript">${ initialLoadHeadSnippet } </script>` ;
46+ } else if ( type === 'body-footer' ) {
47+ return `<script type="text/javascript">${ initialLoadBodySnippet } </script>` ;
3748 }
3849 } ,
50+
51+ injectedScriptHashes : [ initialLoadHeadSnippetHash , initialLoadBodySnippetHash ] ,
3952} ;
0 commit comments