Checking for existence of `window` before using it