terminal: fix A11yButtons crash when the selection is empty

Change-Id: I6a5185a0c12c2a912a0201057b20cedb332d9456
Reviewed-on: https://chromium-review.googlesource.com/c/apps/libapps/+/4019835
Reviewed-by: Joel Hockey <joelhockey@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
diff --git a/terminal/js/terminal_emulator.js b/terminal/js/terminal_emulator.js
index 095b626..85f66de 100644
--- a/terminal/js/terminal_emulator.js
+++ b/terminal/js/terminal_emulator.js
@@ -334,7 +334,7 @@
   onSelectionChange_() {
     this.resetPos_();
 
-    const selectedElement = document.getSelection().anchorNode.parentElement;
+    const selectedElement = document.getSelection().anchorNode?.parentElement;
     if (selectedElement === this.pageUpButton) {
       this.pageUpButton.style.top = '16px';
     } else if (selectedElement === this.pageDownButton) {