From 0267cfbb8fba0ef78a33353a911718c46a9336ff Mon Sep 17 00:00:00 2001 From: Saif Hakim Date: Tue, 22 Sep 2015 04:30:30 -0700 Subject: [PATCH] Fix ReactDOMSelection to avoid erroring on Firefox's anonymous divs --- src/renderers/dom/client/ReactDOMSelection.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/renderers/dom/client/ReactDOMSelection.js b/src/renderers/dom/client/ReactDOMSelection.js index 31912ae2ff..b483c2aea7 100644 --- a/src/renderers/dom/client/ReactDOMSelection.js +++ b/src/renderers/dom/client/ReactDOMSelection.js @@ -76,6 +76,22 @@ function getModernOffsets(node) { var currentRange = selection.getRangeAt(0); + // In Firefox, range.startContainer and range.endContainer can be "anonymous + // divs", e.g. the up/down buttons on an . Anonymous + // divs do not seem to expose properties, triggering a "Permission denied + // error" if any of its properties are accessed. The only seemingly possible + // way to avoid erroring is to access a property that typically works for + // non-anonymous divs and catch any error that may otherwise arise. See + // https://bugzilla.mozilla.org/show_bug.cgi?id=208427 + try { + /* eslint-disable no-unused-expressions */ + currentRange.startContainer.nodeType; + currentRange.endContainer.nodeType; + /* eslint-enable no-unused-expressions */ + } catch (e) { + return null; + } + // If the node and offset values are the same, the selection is collapsed. // `Selection.isCollapsed` is available natively, but IE sometimes gets // this value wrong.