@@ -2425,25 +2425,44 @@ export class TimelinePanel extends UI.Panel.Panel implements Client, TimelineMod
24252425 return ;
24262426 }
24272427
2428- const target = SDK . TargetManager . TargetManager . instance ( ) . primaryPageTarget ( ) ;
2429- const debuggerModel = target ?. model ( SDK . DebuggerModel . DebuggerModel ) ;
2430- const resourceModel = target ?. model ( SDK . ResourceTreeModel . ResourceTreeModel ) ;
2431- const activeFrameIds = ( resourceModel ?. frames ( ) ?? [ ] ) . map ( frame => frame . id ) ;
2428+ const debuggerModelForFrameId = new Map < string , SDK . DebuggerModel . DebuggerModel > ( ) ;
2429+ for ( const target of SDK . TargetManager . TargetManager . instance ( ) . targets ( ) ) {
2430+ const debuggerModel = target . model ( SDK . DebuggerModel . DebuggerModel ) ;
2431+ if ( ! debuggerModel ) {
2432+ continue ;
2433+ }
2434+
2435+ const resourceModel = target . model ( SDK . ResourceTreeModel . ResourceTreeModel ) ;
2436+ const activeFrameIds = ( resourceModel ?. frames ( ) ?? [ ] ) . map ( frame => frame . id ) ;
2437+ for ( const frameId of activeFrameIds ) {
2438+ debuggerModelForFrameId . set ( frameId , debuggerModel ) ;
2439+ }
2440+ }
2441+
2442+ async function getExistingSourceMap ( frame : string , scriptId : string , scriptUrl : Platform . DevToolsPath . UrlString ) :
2443+ Promise < SDK . SourceMap . SourceMap | undefined > {
2444+ const debuggerModel = debuggerModelForFrameId . get ( frame ) ;
2445+ if ( ! debuggerModel ) {
2446+ return ;
2447+ }
2448+
2449+ const script = debuggerModel . scriptForId ( scriptId ) ;
2450+ if ( ! script || ( scriptUrl && scriptUrl !== script . sourceURL ) ) {
2451+ return ;
2452+ }
2453+
2454+ return await debuggerModel . sourceMapManager ( ) . sourceMapForClientPromise ( script ) ;
2455+ }
24322456
24332457 return async function resolveSourceMap ( params : Trace . Types . Configuration . ResolveSourceMapParams ) {
24342458 const { scriptId, scriptUrl, sourceMapUrl, frame} = params ;
24352459
2436- // For the still-active frame, the source map is likely already fetched.
2437- // TODO(cjamcl): hook into in-flight requests for source maps (await on active SourceMapManager resolution, if present).
2438- if ( isFreshRecording && activeFrameIds . includes ( frame ) ) {
2439- const map = debuggerModel ?. scriptForId ( scriptId ) ?. sourceMap ( ) ;
2440- if ( map && ( ! scriptUrl || map . compiledURL ( ) === scriptUrl ) ) {
2460+ // For still-active frames, the source map is likely already fetched or at least in-flight.
2461+ if ( isFreshRecording ) {
2462+ const map = await getExistingSourceMap ( frame , scriptId , scriptUrl ) ;
2463+ if ( map ) {
24412464 return map ;
24422465 }
2443-
2444- // Even for the still-active frame, it could be that the source map has not been fetched yet.
2445- // There is no mechanism for waiting for an in-flight source map, so instead we fallback to
2446- // fetching it again here.
24472466 }
24482467
24492468 // Else... fetch it!
0 commit comments