Browse Source

Be a bit more defensive about the event target.

Ian Rose 6 years ago
parent
commit
a0a0686f1f
1 changed files with 5 additions and 2 deletions
  1. 5 2
      packages/application/src/frontend.ts

+ 5 - 2
packages/application/src/frontend.ts

@@ -109,13 +109,16 @@ export abstract class JupyterFrontEnd<
   contextMenuHitTest(
     test: (node: HTMLElement) => boolean
   ): HTMLElement | undefined {
-    if (!this._contextMenuEvent) {
+    if (
+      !this._contextMenuEvent ||
+      !(this._contextMenuEvent.target instanceof HTMLElement)
+    ) {
       return undefined;
     }
     // This one-liner doesn't work, but should at some point in the future
     // `return this._contextMenuEvent.composedPath() as HTMLElement[];`
     // cf. (https://developer.mozilla.org/en-US/docs/Web/API/Event)
-    let node: HTMLElement = this._contextMenuEvent.target as HTMLElement;
+    let node = this._contextMenuEvent.target as HTMLElement;
     do {
       if (test(node)) {
         return node;