mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-03-06 05:49:47 +01:00
Gracefully handle permission denied error when checking for element.nodeType (#2178)
This commit is contained in:
parent
ea950ac1af
commit
3e7116dce1
@ -14,6 +14,8 @@ import getChildrenDecorations from '../utils/get-children-decorations'
|
|||||||
import scrollToSelection from '../utils/scroll-to-selection'
|
import scrollToSelection from '../utils/scroll-to-selection'
|
||||||
import removeAllRanges from '../utils/remove-all-ranges'
|
import removeAllRanges from '../utils/remove-all-ranges'
|
||||||
|
|
||||||
|
const FIREFOX_NODE_TYPE_ACCESS_ERROR = /Permission denied to access property "nodeType"/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Debug.
|
* Debug.
|
||||||
*
|
*
|
||||||
@ -264,9 +266,24 @@ class Content extends React.Component {
|
|||||||
|
|
||||||
isInEditor = target => {
|
isInEditor = target => {
|
||||||
const { element } = this
|
const { element } = this
|
||||||
|
|
||||||
|
let el
|
||||||
|
|
||||||
|
try {
|
||||||
// COMPAT: Text nodes don't have `isContentEditable` property. So, when
|
// COMPAT: Text nodes don't have `isContentEditable` property. So, when
|
||||||
// `target` is a text node use its parent node for check.
|
// `target` is a text node use its parent node for check.
|
||||||
const el = target.nodeType === 3 ? target.parentNode : target
|
el = target.nodeType === 3 ? target.parentNode : target
|
||||||
|
} catch (err) {
|
||||||
|
// COMPAT: In Firefox, `target.nodeType` will throw an error if target is
|
||||||
|
// originating from an internal "restricted" element (e.g. a stepper
|
||||||
|
// arrow on a number input)
|
||||||
|
// see github.com/ianstormtaylor/slate/issues/1819
|
||||||
|
if (IS_FIREFOX && FIREFOX_NODE_TYPE_ACCESS_ERROR.test(err.message)) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
throw err
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
el.isContentEditable &&
|
el.isContentEditable &&
|
||||||
(el === element || el.closest('[data-slate-editor]') === element)
|
(el === element || el.closest('[data-slate-editor]') === element)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user