After enabled LWS in sandbox windows.location.hostname is returning null

I am unable fetch the base url using window.location.hostname due to LWS being enabled in the sandbox. If LWS disabled it workings fine. Any solution would be much appreciated.

alert(window.location.hostname);

alert is showing null.