/**
 * Get the document scroll height, this means the actual height of the page from the top to the bottom of the DOM
 */ export default function getDocumentScrollHeight ( ) { const viewPortHeight = Math . max ( document . documentElement . clientHeight , window . innerHeight || 0 ) ; const scrollHeight = document . documentElement . scrollHeight ; const bodyScrollHeight = document . body . scrollHeight ; if ( ( viewPortHeight === scrollHeight ) && ( bodyScrollHeight > scrollHeight ) ) { return bodyScrollHeight ; } let pageHeight = 0 ; let largestNodeElement = document . querySelector ( 'body' ) ; if ( bodyScrollHeight === scrollHeight && bodyScrollHeight === viewPortHeight ) { findHighestNode ( document . documentElement . childNodes ) ; return pageHeight + largestNodeElement . getBoundingClientRect ( ) . top ; } return scrollHeight ; param nodesList function findHighestNode ( nodesList ) { for ( let i = nodesList . length - 1 ; i >= 0 ; i -- ) { const currentNode = nodesList [ i ] ; if ( currentNode . scrollHeight && currentNode . clientHeight ) { const elHeight = Math . max ( currentNode . scrollHeight , currentNode . clientHeight ) ; pageHeight = Math . max ( elHeight , pageHeight ) ; if ( elHeight === pageHeight ) { largestNodeElement = currentNode ; } } if ( currentNode . childNodes . length ) { findHighestNode ( currentNode . childNodes ) ; } } } }