Check if actions are registered in Network Panel before using them
The 'inspector-main.reload' action for reloading the inspected page
isn't available if e.g. inspecting service workers through
chrome://inspect. This led to a blank network tab, since the action
registry was throwing an error. Make sure to check first if actions are
registered before using them.
Fixed: 401515593
Change-Id: I0db18ca60f779531ea1f43ca76cd1de3c7c886ac
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6329492
Reviewed-by: Benedikt Meurer <[email protected]>
Commit-Queue: Kim-Anh Tran <[email protected]>
diff --git a/front_end/panels/network/NetworkLogView.test.ts b/front_end/panels/network/NetworkLogView.test.ts
index 82aa624..ba950e8 100644
--- a/front_end/panels/network/NetworkLogView.test.ts
+++ b/front_end/panels/network/NetworkLogView.test.ts
@@ -18,7 +18,12 @@
getMenuItemLabels,
} from '../../testing/ContextMenuHelpers.js';
import {dispatchClickEvent, raf} from '../../testing/DOMHelpers.js';
-import {createTarget, registerNoopActions, stubNoopSettings} from '../../testing/EnvironmentHelpers.js';
+import {
+ createTarget,
+ describeWithEnvironment,
+ registerNoopActions,
+ stubNoopSettings
+} from '../../testing/EnvironmentHelpers.js';
import {expectCalled} from '../../testing/ExpectStubCall.js';
import {stubFileManager} from '../../testing/FileManagerHelpers.js';
import {describeWithMockConnection, dispatchEvent} from '../../testing/MockConnection.js';
@@ -938,6 +943,22 @@
});
});
+describeWithEnvironment('NetworkLogView', () => {
+ it('renders when actions aren\'t registered', async () => {
+ stubNoopSettings();
+ sinon.stub(UI.ShortcutRegistry.ShortcutRegistry, 'instance').returns({
+ shortcutTitleForAction: () => 'Ctrl',
+ shortcutsForAction: () => [new UI.KeyboardShortcut.KeyboardShortcut(
+ [{key: UI.KeyboardShortcut.Keys.Ctrl.code, name: 'Ctrl'}], '', UI.KeyboardShortcut.Type.DEFAULT_SHORTCUT)],
+ } as unknown as UI.ShortcutRegistry.ShortcutRegistry);
+ try {
+ createNetworkLogView();
+ } catch {
+ assert.fail('Creating the network view without registring the actions shouldn\'t fail.');
+ }
+ });
+});
+
function testPlaceholderText(
networkLogView: Network.NetworkLogView.NetworkLogView, expectedHeaderText: string,
expectedDescriptionText: string) {
diff --git a/front_end/panels/network/NetworkLogView.ts b/front_end/panels/network/NetworkLogView.ts
index 727db20..f02c996 100644
--- a/front_end/panels/network/NetworkLogView.ts
+++ b/front_end/panels/network/NetworkLogView.ts
@@ -1095,8 +1095,9 @@
private showRecordingHint(): void {
this.hideRecordingHint();
+ const actionRegistry = UI.ActionRegistry.ActionRegistry.instance();
const actionName = this.recording ? 'inspector-main.reload' : 'network.toggle-recording';
- const action = UI.ActionRegistry.ActionRegistry.instance().getAction(actionName);
+ const action = actionRegistry.hasAction(actionName) ? actionRegistry.getAction(actionName) : null;
const shortcutTitle = UI.ShortcutRegistry.ShortcutRegistry.instance().shortcutTitleForAction(actionName) ?? '';
const header = this.recording ? i18nString(UIStrings.recordingNetworkActivity) :
@@ -1114,11 +1115,13 @@
this.recordingHint.element.classList.add('network-status-pane');
this.recordingHint.appendLink(
'https://developer.chrome.com/docs/devtools/network/' as Platform.DevToolsPath.UrlString);
- const button = UI.UIUtils.createTextButton(buttonText, () => action.execute(), {
- jslogContext: actionName,
- variant: Buttons.Button.Variant.TONAL,
- });
- this.recordingHint.contentElement.appendChild(button);
+ if (shortcutTitle && action) {
+ const button = UI.UIUtils.createTextButton(buttonText, () => action.execute(), {
+ jslogContext: actionName,
+ variant: Buttons.Button.Variant.TONAL,
+ });
+ this.recordingHint.contentElement.appendChild(button);
+ }
this.recordingHint.show(this.element);
this.setHidden(true);