If you change this to `document.body.contains` then it appears to work correctly.