@@ -43,15 +43,6 @@ export type SentryHandleOptions = {
4343 * @default true
4444 */
4545 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 ;
5546} ;
5647
5748/**
@@ -68,21 +59,17 @@ export const FETCH_PROXY_SCRIPT = `
6859/**
6960 * Adds Sentry tracing <meta> tags to the returned html page.
7061 * 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.
7262 *
7363 * Exported only for testing
7464 */
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+ > {
8168 return ( { html } ) => {
8269 const metaTags = getTraceMetaTags ( ) ;
8370 const headWithMetaTags = metaTags ? `<head>\n${ metaTags } ` : '<head>' ;
8471
85- const headWithFetchScript = shouldInjectScript ? `\n<script ${ nonce } >${ FETCH_PROXY_SCRIPT } </script>` : '' ;
72+ const headWithFetchScript = options . injectFetchProxyScript ? `\n<script>${ FETCH_PROXY_SCRIPT } </script>` : '' ;
8673
8774 const modifiedHead = `${ headWithMetaTags } ${ headWithFetchScript } ` ;
8875
@@ -106,7 +93,7 @@ export function addSentryCodeToPage(options: SentryHandleOptions): NonNullable<R
10693 * ```
10794 */
10895export function sentryHandle ( handlerOptions ?: SentryHandleOptions ) : Handle {
109- const options = {
96+ const options : Required < SentryHandleOptions > = {
11097 handleUnknownRoutes : false ,
11198 injectFetchProxyScript : true ,
11299 ...handlerOptions ,
@@ -144,7 +131,7 @@ export function sentryHandle(handlerOptions?: SentryHandleOptions): Handle {
144131
145132async function instrumentHandle (
146133 { event, resolve } : Parameters < Handle > [ 0 ] ,
147- options : SentryHandleOptions ,
134+ options : Required < SentryHandleOptions > ,
148135) : Promise < Response > {
149136 if ( ! event . route ?. id && ! options . handleUnknownRoutes ) {
150137 return resolve ( event ) ;
@@ -174,7 +161,7 @@ async function instrumentHandle(
174161 normalizedRequest : winterCGRequestToRequestData ( event . request . clone ( ) ) ,
175162 } ) ;
176163 const res = await resolve ( event , {
177- transformPageChunk : addSentryCodeToPage ( options ) ,
164+ transformPageChunk : addSentryCodeToPage ( { injectFetchProxyScript : options . injectFetchProxyScript } ) ,
178165 } ) ;
179166 if ( span ) {
180167 setHttpStatus ( span , res . status ) ;
0 commit comments