From 4f32cd9d713ab54279018f71120bac2a6cd4e676 Mon Sep 17 00:00:00 2001 From: Elvira Khabirova Date: Sun, 29 Jun 2025 11:05:37 +0200 Subject: [PATCH] Check rangeCount before getRangeAt(0) Apparently on WebKit (including ish's webview), getSelection() can return an object with no ranges (rangeCount == 0). In those cases, calling getRangeAt(0) causes an error to be thrown: "IndexSizeError: The index is not in the allowed range" This error was appearing in the JS console when tapping/clicking randomly. Checking rangeCount here fixes the error. See also: https://stackoverflow.com/questions/22935320/uncaught-indexsizeerror-failed-to-execute-getrangeat-on-selection-0-is-not Signed-off-by: Elvira Khabirova --- hterm/js/hterm_screen.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hterm/js/hterm_screen.js b/hterm/js/hterm_screen.js index 4d4bb0eb..a1b3b410 100644 --- a/hterm/js/hterm_screen.js +++ b/hterm/js/hterm_screen.js @@ -927,6 +927,10 @@ hterm.Screen.prototype.expandSelectionWithWordBreakMatches_ = return; } + if (selection.rangeCount == 0) { + return; + } + const range = selection.getRangeAt(0); if (!range || range.toString().match(/\s/)) { return;