Skip to content

Commit c1f325c

Browse files
authored
[MV3 Debug Extension] Bolt debugging: can reload the page and continue to debug (#1991)
1 parent 057f598 commit c1f325c

File tree

4 files changed

+110
-49
lines changed

4 files changed

+110
-49
lines changed

dwds/debug_extension_mv3/web/background.dart

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ Future<void> _handleRuntimeMessages(
9393
}
9494
// Save the debug info for the Dart app in storage:
9595
await setStorageObject<DebugInfo>(
96-
type: StorageObject.debugInfo, value: debugInfo, tabId: dartTab.id);
96+
type: StorageObject.debugInfo,
97+
value: _addTabUrl(debugInfo, tabUrl: dartTab.url),
98+
tabId: dartTab.id);
9799
// Update the icon to show that a Dart app has been detected:
98100
final currentTab = await activeTab;
99101
if (currentTab?.id == dartTab.id) {
@@ -137,10 +139,13 @@ Future<void> _handleRuntimeMessages(
137139

138140
Future<void> _detectNavigationAwayFromDartApp(
139141
NavigationInfo navigationInfo) async {
142+
// Ignore any navigation events within the page itself (e.g., opening a link,
143+
// reloading an IFRAME, etc):
144+
if (_isInternalNavigation(navigationInfo)) return;
140145
final tabId = navigationInfo.tabId;
141146
final debugInfo = await _fetchDebugInfo(navigationInfo.tabId);
142147
if (debugInfo == null) return;
143-
if (debugInfo.appUrl != navigationInfo.url) {
148+
if (debugInfo.tabUrl != navigationInfo.url) {
144149
_setDefaultIcon();
145150
await clearStaleDebugSession(tabId);
146151
await removeStorageObject(type: StorageObject.debugInfo, tabId: tabId);
@@ -152,6 +157,29 @@ Future<void> _detectNavigationAwayFromDartApp(
152157
}
153158
}
154159

160+
bool _isInternalNavigation(NavigationInfo navigationInfo) {
161+
return [
162+
'auto_subframe',
163+
'form_submit',
164+
'link',
165+
'manual_subframe',
166+
].contains(navigationInfo.transitionType);
167+
}
168+
169+
DebugInfo _addTabUrl(DebugInfo debugInfo, {required String tabUrl}) {
170+
return DebugInfo((b) => b
171+
..appEntrypointPath = debugInfo.appEntrypointPath
172+
..appId = debugInfo.appId
173+
..appInstanceId = debugInfo.appInstanceId
174+
..appOrigin = debugInfo.appOrigin
175+
..appUrl = debugInfo.appUrl
176+
..authUrl = debugInfo.authUrl
177+
..extensionUrl = debugInfo.extensionUrl
178+
..isInternalBuild = debugInfo.isInternalBuild
179+
..isFlutterApp = debugInfo.isFlutterApp
180+
..tabUrl = tabUrl);
181+
}
182+
155183
Future<void> _updateIcon(int activeTabId) async {
156184
final debugInfo = await _fetchDebugInfo(activeTabId);
157185
if (debugInfo == null) {

dwds/lib/data/debug_info.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ abstract class DebugInfo implements Built<DebugInfo, DebugInfoBuilder> {
2424
String? get extensionUrl;
2525
bool? get isInternalBuild;
2626
bool? get isFlutterApp;
27+
String? get tabUrl;
2728
}

dwds/lib/data/debug_info.g.dart

Lines changed: 27 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)