@@ -43,15 +43,6 @@ export type SentryHandleOptions = {
43
43
* @default true
44
44
*/
45
45
injectFetchProxyScript ?: boolean ;
46
-
47
- /**
48
- * If this option is set, the `sentryHandle` handler will add a nonce attribute to the script
49
- * tag it injects into the page. This script is used to enable instrumentation of `fetch` calls
50
- * in `load` functions.
51
- *
52
- * Use this if your CSP policy blocks the fetch proxy script injected by `sentryHandle`.
53
- */
54
- fetchProxyScriptNonce ?: string ;
55
46
} ;
56
47
57
48
/**
@@ -68,21 +59,17 @@ export const FETCH_PROXY_SCRIPT = `
68
59
/**
69
60
* Adds Sentry tracing <meta> tags to the returned html page.
70
61
* Adds Sentry fetch proxy script to the returned html page if enabled in options.
71
- * Also adds a nonce attribute to the script tag if users specified one for CSP.
72
62
*
73
63
* Exported only for testing
74
64
*/
75
- export function addSentryCodeToPage ( options : SentryHandleOptions ) : NonNullable < ResolveOptions [ 'transformPageChunk' ] > {
76
- const { fetchProxyScriptNonce, injectFetchProxyScript } = options ;
77
- // if injectFetchProxyScript is not set, we default to true
78
- const shouldInjectScript = injectFetchProxyScript !== false ;
79
- const nonce = fetchProxyScriptNonce ? `nonce="${ fetchProxyScriptNonce } "` : '' ;
80
-
65
+ export function addSentryCodeToPage ( options : { injectFetchProxyScript : boolean } ) : NonNullable <
66
+ ResolveOptions [ 'transformPageChunk' ]
67
+ > {
81
68
return ( { html } ) => {
82
69
const metaTags = getTraceMetaTags ( ) ;
83
70
const headWithMetaTags = metaTags ? `<head>\n${ metaTags } ` : '<head>' ;
84
71
85
- const headWithFetchScript = shouldInjectScript ? `\n<script ${ nonce } >${ FETCH_PROXY_SCRIPT } </script>` : '' ;
72
+ const headWithFetchScript = options . injectFetchProxyScript ? `\n<script>${ FETCH_PROXY_SCRIPT } </script>` : '' ;
86
73
87
74
const modifiedHead = `${ headWithMetaTags } ${ headWithFetchScript } ` ;
88
75
@@ -106,7 +93,7 @@ export function addSentryCodeToPage(options: SentryHandleOptions): NonNullable<R
106
93
* ```
107
94
*/
108
95
export function sentryHandle ( handlerOptions ?: SentryHandleOptions ) : Handle {
109
- const options = {
96
+ const options : Required < SentryHandleOptions > = {
110
97
handleUnknownRoutes : false ,
111
98
injectFetchProxyScript : true ,
112
99
...handlerOptions ,
@@ -144,7 +131,7 @@ export function sentryHandle(handlerOptions?: SentryHandleOptions): Handle {
144
131
145
132
async function instrumentHandle (
146
133
{ event, resolve } : Parameters < Handle > [ 0 ] ,
147
- options : SentryHandleOptions ,
134
+ options : Required < SentryHandleOptions > ,
148
135
) : Promise < Response > {
149
136
if ( ! event . route ?. id && ! options . handleUnknownRoutes ) {
150
137
return resolve ( event ) ;
@@ -174,7 +161,7 @@ async function instrumentHandle(
174
161
normalizedRequest : winterCGRequestToRequestData ( event . request . clone ( ) ) ,
175
162
} ) ;
176
163
const res = await resolve ( event , {
177
- transformPageChunk : addSentryCodeToPage ( options ) ,
164
+ transformPageChunk : addSentryCodeToPage ( { injectFetchProxyScript : options . injectFetchProxyScript } ) ,
178
165
} ) ;
179
166
if ( span ) {
180
167
setHttpStatus ( span , res . status ) ;
0 commit comments