Prefer CommonJS over window

If we are running in browser env, "window" always exists. We can however still run in CommonJS env.
This allows CommonJS apps to use this module when running in browsers as well