From 33ec369eff87ace3e8b49c6461fa1b9a5d2a1202 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Mon, 10 Dec 2018 17:09:06 -0500 Subject: Catch exceptions thrown by range.getClientRects() Firefox dev 65 was throwing an exception --- ext/fg/js/document.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'ext/fg/js/document.js') diff --git a/ext/fg/js/document.js b/ext/fg/js/document.js index 9366832e..73e89d99 100644 --- a/ext/fg/js/document.js +++ b/ext/fg/js/document.js @@ -92,7 +92,19 @@ function docRangeFromPoint(point) { if(imposter !== null) imposter.style.zIndex = -2147483646; - const rect = range.getClientRects()[0]; + let rects; + try { + rects = range.getClientRects(); + } + catch (e) { + return; + } + + if (rects.length === 0) { + return; + } + + const rect = rects[0]; if (point.y > rect.bottom + 2) { return; } -- cgit v1.2.3 From dd52a1c01af117d69c953241fc9380596e7bab20 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Wed, 20 Feb 2019 21:47:31 -0500 Subject: Improve handling of null values from caretRangeFromPoint --- ext/fg/js/document.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'ext/fg/js/document.js') diff --git a/ext/fg/js/document.js b/ext/fg/js/document.js index 73e89d99..13acb036 100644 --- a/ext/fg/js/document.js +++ b/ext/fg/js/document.js @@ -85,20 +85,18 @@ function docRangeFromPoint(point) { range.setEnd(position.offsetNode, position.offset); return range; } + return null; }; } const range = document.caretRangeFromPoint(point.x, point.y); + if (range === null) { + return; + } if(imposter !== null) imposter.style.zIndex = -2147483646; - let rects; - try { - rects = range.getClientRects(); - } - catch (e) { - return; - } + const rects = range.getClientRects(); if (rects.length === 0) { return; -- cgit v1.2.3