@@ -700,6 +700,19 @@ export class TimelinePanel extends UI.Panel.Panel implements Client, TimelineMod
700700 this . #showLandingPage( ) ;
701701 this . updateTimelineControls ( ) ;
702702
703+ if ( isReactNative ) {
704+ SDK . TargetManager . TargetManager . instance ( ) . observeModels (
705+ SDK . ReactNativeApplicationModel . ReactNativeApplicationModel ,
706+ {
707+ modelAdded : ( model : SDK . ReactNativeApplicationModel . ReactNativeApplicationModel ) => {
708+ model . addEventListener (
709+ SDK . ReactNativeApplicationModel . Events . TRACE_REQUESTED , ( ) => this . rnPrepareForTraceCapturedInBackground ( ) ) ;
710+ } ,
711+ modelRemoved : ( _model : SDK . ReactNativeApplicationModel . ReactNativeApplicationModel ) => { } ,
712+ } ,
713+ ) ;
714+ }
715+
703716 SDK . TargetManager . TargetManager . instance ( ) . addEventListener (
704717 SDK . TargetManager . Events . SUSPEND_STATE_CHANGED , this . onSuspendStateChanged , this ) ;
705718 const profilerModels = SDK . TargetManager . TargetManager . instance ( ) . models ( SDK . CPUProfilerModel . CPUProfilerModel ) ;
@@ -731,6 +744,31 @@ export class TimelinePanel extends UI.Panel.Panel implements Client, TimelineMod
731744 } ) ;
732745 }
733746
747+ private async rnPrepareForTraceCapturedInBackground ( ) : Promise < void > {
748+ this . setUIControlsEnabled ( false ) ;
749+
750+ if ( this . statusPane ) {
751+ this . statusPane . finish ( ) ;
752+ this . statusPane . updateStatus ( i18nString ( UIStrings . stoppingTimeline ) ) ;
753+ this . statusPane . updateProgressBar ( i18nString ( UIStrings . received ) , 0 ) ;
754+ }
755+ this . setState ( State . STOP_PENDING ) ;
756+
757+ const rootTarget = SDK . TargetManager . TargetManager . instance ( ) . rootTarget ( ) ;
758+ const primaryPageTarget = SDK . TargetManager . TargetManager . instance ( ) . primaryPageTarget ( ) ;
759+ if ( ! primaryPageTarget ) {
760+ throw new Error ( 'Could not load primary page target.' ) ;
761+ }
762+ if ( ! rootTarget ) {
763+ throw new Error ( 'Could not load root target.' ) ;
764+ }
765+
766+ this . controller = new TimelineController ( rootTarget , primaryPageTarget , this ) ;
767+ await this . controller . rnPrepareForTraceCapturedInBackground ( ) ;
768+
769+ this . setUIControlsEnabled ( true ) ;
770+ }
771+
734772 #setActiveInsight( insight : TimelineComponents . Sidebar . ActiveInsight | null ) : void {
735773 // When an insight is selected, ensure that the 3P checkbox is disabled
736774 // to avoid dimming interference.
0 commit comments