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 @@ -41,22 +41,27 @@ function getElementsWithSelections(acc, win) {
41
41
var doc ;
42
42
try {
43
43
doc = win . document ;
44
+ if ( ! doc ) {
45
+ return acc ;
46
+ }
44
47
} catch ( e ) {
45
48
return acc ;
46
49
}
47
50
var element = null ;
48
51
if ( win . getSelection ) {
49
52
var selection = win . getSelection ( ) ;
50
- var startNode = selection . anchorNode ;
51
- var endNode = selection . focusNode ;
52
- var startOffset = selection . anchorOffset ;
53
- var endOffset = selection . focusOffset ;
54
- if ( startNode && startNode . childNodes . length ) {
55
- if ( startNode . childNodes [ startOffset ] === endNode . childNodes [ endOffset ] ) {
56
- element = startNode . childNodes [ startOffset ] ;
57
- }
58
- } else {
59
- element = startNode ;
53
+ if ( selection ) {
54
+ var startNode = selection . anchorNode ;
55
+ var endNode = selection . focusNode ;
56
+ var startOffset = selection . anchorOffset ;
57
+ var endOffset = selection . focusOffset ;
58
+ if ( startNode && startNode . childNodes . length ) {
59
+ if ( startNode . childNodes [ startOffset ] === endNode . childNodes [ endOffset ] ) {
60
+ element = startNode . childNodes [ startOffset ] ;
61
+ }
62
+ } else {
63
+ element = startNode ;
64
+ }
60
65
}
61
66
} else if ( doc . selection ) {
62
67
var range = doc . selection . createRange ( ) ;
You can’t perform that action at this time.
0 commit comments