@@ -15,6 +15,9 @@ import * as UI from '../../ui/legacy/legacy.js';
1515
1616import nodeIconStyles from './nodeIcon.css.js' ;
1717
18+ const COOLDOWN_BETWEEN_PINGS = 3000 ;
19+ const LOW_PING_THRESHOLD = 200 ;
20+
1821const UIStrings = {
1922 /**
2023 * @description Text that refers to the main target. The main target is the primary webpage that
@@ -46,6 +49,8 @@ const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_);
4649let inspectorMainImplInstance : InspectorMainImpl ;
4750
4851export class InspectorMainImpl implements Common . Runnable . Runnable {
52+ #consecutiveLowPing = 0 ;
53+
4954 static instance ( opts : {
5055 forceNew : boolean | null ,
5156 } = { forceNew : null } ) : InspectorMainImpl {
@@ -57,6 +62,28 @@ export class InspectorMainImpl implements Common.Runnable.Runnable {
5762 return inspectorMainImplInstance ;
5863 }
5964
65+ async #measureMainConnectionPing( debuggerModel : SDK . DebuggerModel . DebuggerModel ) : Promise < void > {
66+ if ( ! debuggerModel . debuggerEnabled ( ) ) {
67+ return ;
68+ }
69+
70+ const startMs = Date . now ( ) ;
71+ await debuggerModel . syncDebuggerId ( ) ;
72+ const ping = Date . now ( ) - startMs ;
73+
74+ if ( ping > LOW_PING_THRESHOLD ) {
75+ this . #consecutiveLowPing = 0 ;
76+ } else {
77+ this . #consecutiveLowPing++ ;
78+ }
79+
80+ if ( this . #consecutiveLowPing > 1 ) {
81+ Host . rnPerfMetrics . firstSteadyPing ( ) ;
82+ } else {
83+ setTimeout ( ( ) => void this . #measureMainConnectionPing( debuggerModel ) , COOLDOWN_BETWEEN_PINGS ) ;
84+ }
85+ }
86+
6087 async run ( ) : Promise < void > {
6188 let firstCall = true ;
6289 await SDK . Connections . initMainConnection ( async ( ) => {
@@ -94,13 +121,14 @@ export class InspectorMainImpl implements Common.Runnable.Runnable {
94121 }
95122 firstCall = false ;
96123
97- if ( waitForDebuggerInPage ) {
98- const debuggerModel = target . model ( SDK . DebuggerModel . DebuggerModel ) ;
99- if ( debuggerModel ) {
100- if ( ! debuggerModel . isReadyToPause ( ) ) {
101- await debuggerModel . once ( SDK . DebuggerModel . Events . DebuggerIsReadyToPause ) ;
102- }
103- debuggerModel . pause ( ) ;
124+ const debuggerModel = target . model ( SDK . DebuggerModel . DebuggerModel ) ;
125+ if ( debuggerModel ) {
126+ void this . #measureMainConnectionPing( debuggerModel ) ;
127+ if ( waitForDebuggerInPage ) {
128+ if ( ! debuggerModel . isReadyToPause ( ) ) {
129+ await debuggerModel . once ( SDK . DebuggerModel . Events . DebuggerIsReadyToPause ) ;
130+ }
131+ debuggerModel . pause ( ) ;
104132 }
105133 }
106134
0 commit comments