Communities with embedded Twitter Feeds

The error is TypeError: document.getElementById(…) is null

Apparently the #sidebar div is not inserted on every page?

It can be fixed by properly checking if the element is not null.

api.onPageChange(() => {
    if (Discourse.User.current() !== null){ 
        var sb = document.getElementById("sidebar")
        if (sb) { 
            sb.style.display = "block"; 
        }
    } 
});
api.onPageChange(() => { 
    var is_iPad = navigator.userAgent.match(/iPad/i) != null;
    if(is_iPad)  {
        var sb = document.getElementById("sidebar")
        if (sb) { 
            sb.style.display = "none"; 
        }
    }
});