@@ -46,17 +46,23 @@ const _lostConnectionMsg = 'Lost connection.';
4646const _connectionTimeoutMsg = 'Connection timed out.' ;
4747const _failedToConnectMsg = 'Failed to connect, please try again.' ;
4848const _pleaseAuthenticateMsg = 'Please re-authenticate and try again.' ;
49+ const _multipleAppsMsg = 'Cannot debug multiple apps in a page.' ;
4950
5051int get _tabId => chrome.devtools.inspectedWindow.tabId;
5152
52- void main () {
53+ Future < void > main () async {
5354 unawaited (
5455 _registerListeners ().catchError ((error) {
5556 debugWarn ('Error registering listeners in panel: $error ' );
5657 }),
5758 );
5859 _setColorThemeToMatchChromeDevTools ();
59- _maybeUpdateFileABugLink ();
60+ await _maybeUpdateFileABugLink ();
61+ final multipleApps = await fetchStorageObject <String >(
62+ type: StorageObject .multipleAppsDetected,
63+ tabId: _tabId,
64+ );
65+ _maybeShowMultipleAppsWarning (multipleApps);
6066}
6167
6268Future <void > _registerListeners () async {
@@ -70,7 +76,7 @@ Future<void> _registerListeners() async {
7076}
7177
7278void _handleRuntimeMessages (
73- dynamic jsRequest, MessageSender sender, Function sendResponse) async {
79+ dynamic jsRequest, MessageSender sender, Function sendResponse) {
7480 if (jsRequest is ! String ) return ;
7581
7682 interceptMessage <DebugStateChange >(
@@ -120,9 +126,15 @@ void _handleStorageChanges(Object storageObj, String storageArea) {
120126 tabId: _tabId,
121127 changeHandler: _handleDevToolsUriChanges,
122128 );
129+ interceptStorageChange <String >(
130+ storageObj: storageObj,
131+ expectedType: StorageObject .multipleAppsDetected,
132+ tabId: _tabId,
133+ changeHandler: _maybeShowMultipleAppsWarning,
134+ );
123135}
124136
125- void _handleDebugInfoChanges (DebugInfo ? debugInfo) async {
137+ void _handleDebugInfoChanges (DebugInfo ? debugInfo) {
126138 if (debugInfo == null && _isDartApp) {
127139 _isDartApp = false ;
128140 if (! _warningBannerIsVisible ()) {
@@ -137,13 +149,23 @@ void _handleDebugInfoChanges(DebugInfo? debugInfo) async {
137149 }
138150}
139151
140- void _handleDevToolsUriChanges (String ? devToolsUri) async {
152+ void _handleDevToolsUriChanges (String ? devToolsUri) {
141153 if (devToolsUri != null ) {
142154 _injectDevToolsIframe (devToolsUri);
143155 }
144156}
145157
146- void _maybeUpdateFileABugLink () async {
158+ void _maybeShowMultipleAppsWarning (String ? multipleApps) {
159+ if (multipleApps != null ) {
160+ _showWarningBanner (_multipleAppsMsg);
161+ } else {
162+ if (_warningBannerIsVisible (message: _multipleAppsMsg)) {
163+ _hideWarningBanner ();
164+ }
165+ }
166+ }
167+
168+ Future <void > _maybeUpdateFileABugLink () async {
147169 final debugInfo = await fetchStorageObject <DebugInfo >(
148170 type: StorageObject .debugInfo,
149171 tabId: _tabId,
@@ -157,7 +179,7 @@ void _maybeUpdateFileABugLink() async {
157179 }
158180}
159181
160- void _setColorThemeToMatchChromeDevTools () async {
182+ void _setColorThemeToMatchChromeDevTools () {
161183 final chromeTheme = chrome.devtools.panels.themeName;
162184 final panelBody = document.getElementById (_panelBodyId);
163185 if (chromeTheme == 'dark' ) {
@@ -217,9 +239,13 @@ void _handleConnectFailure(ConnectFailureReason reason) {
217239 _updateElementVisibility (_loadingSpinnerId, visible: false );
218240}
219241
220- bool _warningBannerIsVisible () {
242+ bool _warningBannerIsVisible ({ String ? message} ) {
221243 final warningBanner = document.getElementById (_warningBannerId);
222- return warningBanner != null && warningBanner.classes.contains (_showClass);
244+ final isVisible =
245+ warningBanner != null && warningBanner.classes.contains (_showClass);
246+ if (message == null || isVisible == false ) return isVisible;
247+ final warningMsg = document.getElementById (_warningMsgId);
248+ return warningMsg? .innerHtml == message;
223249}
224250
225251void _showWarningBanner (String message) {
@@ -234,7 +260,7 @@ void _hideWarningBanner() {
234260 warningBanner? .classes.remove (_showClass);
235261}
236262
237- void _launchDebugConnection (Event _) async {
263+ Future < void > _launchDebugConnection (Event _) async {
238264 _updateElementVisibility (_launchDebugConnectionButtonId, visible: false );
239265 _updateElementVisibility (_loadingSpinnerId, visible: true );
240266 final json = jsonEncode (serializers.serialize (DebugStateChange ((b) => b
@@ -245,10 +271,10 @@ void _launchDebugConnection(Event _) async {
245271 body: json,
246272 sender: Script .debuggerPanel,
247273 recipient: Script .background);
248- _maybeHandleConnectionTimeout ();
274+ unawaited ( _maybeHandleConnectionTimeout (). catchError ((_) {}) );
249275}
250276
251- void _maybeHandleConnectionTimeout () async {
277+ Future < void > _maybeHandleConnectionTimeout () async {
252278 _connecting = true ;
253279 await Future .delayed (Duration (seconds: 10 ));
254280 if (_connecting == true ) {
0 commit comments