From 51032d1eca04820a80f34dfd511a927c55975c1f Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 2 May 2020 12:59:59 -0400 Subject: [PATCH] Catch WrongDocumentError thrown by compareBoundaryPoints (#491) * Catch WrongDocumentError thrown by compareBoundaryPoints * Filter error based on name --- ext/fg/js/source.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ext/fg/js/source.js b/ext/fg/js/source.js index 3d9afe0f..0b21b5cc 100644 --- a/ext/fg/js/source.js +++ b/ext/fg/js/source.js @@ -94,7 +94,15 @@ class TextSourceRange { this.rangeStartOffset === other.rangeStartOffset ); } else { - return this.range.compareBoundaryPoints(Range.START_TO_START, other.range) === 0; + try { + return this.range.compareBoundaryPoints(Range.START_TO_START, other.range) === 0; + } catch (e) { + if (e.name === 'WrongDocumentError') { + // This can happen with shadow DOMs if the ranges are in different documents. + return false; + } + throw e; + } } }