Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

Handle `document.body` not being available gracefully (#5045)

Karl-Aksel Puulmannaa563b026eb4
diff --git a/tracker/src/plausible.js b/tracker/src/plausible.js
index 3fc4a40c87..61cf7a60f9 100644
--- a/tracker/src/plausible.js
+++ b/tracker/src/plausible.js
@@ -55,13 +55,15 @@
var pageLeaveSending = false
function getDocumentHeight() {
+ var body = document.body || {}
+ var el = document.documentElement || {}
return Math.max(
- document.body.scrollHeight || 0,
- document.body.offsetHeight || 0,
- document.body.clientHeight || 0,
- document.documentElement.scrollHeight || 0,
- document.documentElement.offsetHeight || 0,
- document.documentElement.clientHeight || 0
+ body.scrollHeight || 0,
+ body.offsetHeight || 0,
+ body.clientHeight || 0,
+ el.scrollHeight || 0,
+ el.offsetHeight || 0,
+ el.clientHeight || 0
)
}