2022
You can now combine a window
resize
listener with the window.visualViewport.height
property (which has a very good compatibility):
window.addEventListener('resize', () => {
// For the rare legacy browsers that don't support it
if (!window.visualViewport) {
return
}
console.log(window.visualViewport.height)
})