Change from document.location to window.location and added a fix for location.origin
new build