Support the web worker context in window.js

I noticed an issue when in the Web Worker context that we write window to an empty object. I believe that `self` is the correct global object for the Worker context, https://developer.mozilla.org/en-US/docs/Web/API/DedicatedWorkerGlobalScope. But I am not 100 % sure. 

Please me know if you think this an reasonable fix. 

Note that I found this issue because `xhr` is currently broken in web workers, but I don't see any reason why it can't work. 

Thanks.