Check for null to avoid UnhandledPromiseRejection in Main.Main.SearchActionDelegate.handleAction

An UnhandledPromiseRejection exception is sometimes thrown by
Main.Main.SearchActionDelegate.handleAction, because in this function it
calls UI.inspectorView.currentPanelDeprecated().searchableView(), but
UI.inspectorView.currentPanelDeprecated() can return null.

Call stack:
ShortcutRegistry.js:handleKey
Action.js:handleAction
Main.js:SearchActionDelegate.handleAction

This CL
- checks if UI.inspectorView.currentPanelDeprecated() is null before calling
.searchableView() on it
- fixes return type of currentPanelDeprecated since
UI.viewManager.materializedWidget can return null
- wrap await call in ShortcutRegistry.js:handleKey with try-catch block to
avoid UnhandledPromiseRejection exceptions

Change-Id: I691129dc22da944df35e2134f01821638864b4d0
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/1947172
Commit-Queue: Mandy Chen <[email protected]>
Reviewed-by: Robert Paveza <[email protected]>
diff --git a/front_end/main/MainImpl.js b/front_end/main/MainImpl.js
index 5232b94..ab633c6 100644
--- a/front_end/main/MainImpl.js
+++ b/front_end/main/MainImpl.js
@@ -516,10 +516,15 @@
    * @suppressGlobalPropertiesCheck
    */
   handleAction(context, actionId) {
-    const searchableView = UI.SearchableView.fromElement(document.deepActiveElement()) ||
-        UI.inspectorView.currentPanelDeprecated().searchableView();
+    let searchableView = UI.SearchableView.fromElement(document.deepActiveElement());
     if (!searchableView) {
-      return false;
+      const currentPanel = UI.inspectorView.currentPanelDeprecated();
+      if (currentPanel) {
+        searchableView = currentPanel.searchableView();
+      }
+      if (!searchableView) {
+        return false;
+      }
     }
     switch (actionId) {
       case 'main.search-in-panel.find':