diff --git a/lib/core/utils/get-selector.js b/lib/core/utils/get-selector.js index afe6dcd183..d4bbf20698 100644 --- a/lib/core/utils/get-selector.js +++ b/lib/core/utils/get-selector.js @@ -392,6 +392,9 @@ axe.utils.getSelector = function createUniqueSelector(elm, options = {}) { // DOCUMENT_FRAGMENT let stack = []; while (doc.nodeType === 11) { + if (!doc.host) { + return ''; + } stack.push({ elm: elm, doc: doc }); elm = doc.host; doc = elm.getRootNode(); diff --git a/test/core/utils/get-selector.js b/test/core/utils/get-selector.js index 19de415e3b..c98a52cdec 100644 --- a/test/core/utils/get-selector.js +++ b/test/core/utils/get-selector.js @@ -593,4 +593,14 @@ describe('axe.utils.getSelector', function() { var test = document.querySelector(sel); assert.isTrue(test === top); }); + + it('should not error if fragment is no longer in the DOM', function() { + var fragment = document.createDocumentFragment(); + var node = document.createElement('div'); + fragment.appendChild(node); + fixtureSetup(); + assert.doesNotThrow(function() { + axe.utils.getSelector(node); + }); + }); });