JSFiddle - React, Tailwind, and code Playground
HTML
<body>
<!-- hello world -->
<h1>Finding comments using xpath</h1>
</body>
JavaScript
var iterator = document.evaluate('//comment()', document.body, null, XPathResult.UNORDERED_NODE_ITERATOR_TYPE, null);
var thisNode = iterator.iterateNext();
while (thisNode) {
alert(thisNode.textContent);
thisNode = iterator.iterateNext();
}