How about support window and web workers?

Added window check which should work in both main thread and web workers.  Fancy this option?