Skip to content

Conversation

hankhero
Copy link

@hankhero hankhero commented Nov 9, 2014

for a web-worker, window is unavailable butXMLHttpRequest is available on the global 'self' object

for a web-worker, window is unavailable butXMLHttpRequest is available on the global 'self' object
@canastro
Copy link

This would be really useful!

@@ -50,7 +50,10 @@ http.Agent = function () {};
http.Agent.defaultMaxSockets = 4;

var xhrHttp = (function () {
if (typeof window === 'undefined') {
if (typeof self !== 'undefined' && self.XMLHttpRequest) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about this:

if (typeof XMLHttpRequest !== 'undefined') {
    return XMLHttpRequest;
}

And then remove the second check for window.XMLHttpRequest below.

@tschaub
Copy link
Contributor

tschaub commented Aug 19, 2015

Agreed this would be useful. For others looking to work around the window checking, you can add this hack to whatever module requires http:

self.window = self;

And with this, window.XMLHttpRequest will be defined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants