File tree Expand file tree Collapse file tree 1 file changed +15
-10
lines changed
Expand file tree Collapse file tree 1 file changed +15
-10
lines changed Original file line number Diff line number Diff line change @@ -42,22 +42,27 @@ function getElementsWithSelections(acc, win) {
4242 var doc ;
4343 try {
4444 doc = win . document ;
45+ if ( ! doc ) {
46+ return acc ;
47+ }
4548 } catch ( e ) {
4649 return acc ;
4750 }
4851 var element = null ;
4952 if ( win . getSelection ) {
5053 var selection = win . getSelection ( ) ;
51- var startNode = selection . anchorNode ;
52- var endNode = selection . focusNode ;
53- var startOffset = selection . anchorOffset ;
54- var endOffset = selection . focusOffset ;
55- if ( startNode && startNode . childNodes . length ) {
56- if ( startNode . childNodes [ startOffset ] === endNode . childNodes [ endOffset ] ) {
57- element = startNode . childNodes [ startOffset ] ;
58- }
59- } else {
60- element = startNode ;
54+ if ( selection ) {
55+ var startNode = selection . anchorNode ;
56+ var endNode = selection . focusNode ;
57+ var startOffset = selection . anchorOffset ;
58+ var endOffset = selection . focusOffset ;
59+ if ( startNode && startNode . childNodes . length ) {
60+ if ( startNode . childNodes [ startOffset ] === endNode . childNodes [ endOffset ] ) {
61+ element = startNode . childNodes [ startOffset ] ;
62+ }
63+ } else {
64+ element = startNode ;
65+ }
6166 }
6267 } else if ( doc . selection ) {
6368 var range = doc . selection . createRange ( ) ;
You can’t perform that action at this time.
0 commit comments