11import type { Event , EventHint } from '@sentry/types' ;
2+ import { GLOBAL_OBJ } from '@sentry/utils' ;
23import type { StackFrame } from 'stacktrace-parser' ;
34import * as stackTraceParser from 'stacktrace-parser' ;
45
@@ -8,6 +9,10 @@ type OriginalStackFrameResponse = {
89 sourcePackage ?: string ;
910} ;
1011
12+ const globalWithInjectedValues = GLOBAL_OBJ as typeof GLOBAL_OBJ & {
13+ __sentryBasePath ?: string ;
14+ } ;
15+
1116async function resolveStackFrame (
1217 frame : StackFrame ,
1318 error : Error ,
@@ -26,13 +31,20 @@ async function resolveStackFrame(
2631 params . append ( key , ( frame [ key as keyof typeof frame ] ?? '' ) . toString ( ) ) ;
2732 } ) ;
2833
34+ let basePath = globalWithInjectedValues . __sentryBasePath ?? '' ;
35+
36+ // Prefix the basepath with a slash if it doesn't have one
37+ if ( basePath !== '' && ! basePath . match ( / ^ \/ / ) ) {
38+ basePath = `/${ basePath } ` ;
39+ }
40+
2941 const controller = new AbortController ( ) ;
3042 const timer = setTimeout ( ( ) => controller . abort ( ) , 3000 ) ;
3143 const res = await fetch (
3244 `${
3345 // eslint-disable-next-line no-restricted-globals
3446 typeof window === 'undefined' ? 'http://localhost:3000' : '' // TODO: handle the case where users define a different port
35- } /__nextjs_original-stack-frame?${ params . toString ( ) } `,
47+ } ${ basePath } /__nextjs_original-stack-frame?${ params . toString ( ) } `,
3648 {
3749 signal : controller . signal ,
3850 } ,
0 commit comments