var canonical = document.querySelector('link[rel="canonical"]');
    var url = canonical ? canonical.getAttribute("href") : window.location.href;