From dc5148a9a48f525e161a64770ffa2c8991aa6c9f Mon Sep 17 00:00:00 2001 From: Henrik Hjelte Date: Sun, 9 Nov 2014 21:10:51 +0100 Subject: [PATCH] support web-workers XMLHttpRequest for a web-worker, window is unavailable butXMLHttpRequest is available on the global 'self' object --- index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index fedd2a2..73ea11e 100644 --- a/index.js +++ b/index.js @@ -50,7 +50,10 @@ http.Agent = function () {}; http.Agent.defaultMaxSockets = 4; var xhrHttp = (function () { - if (typeof window === 'undefined') { + if (typeof self !== 'undefined' && self.XMLHttpRequest) { + return self.XMLHttpRequest; + } + else if (typeof window === 'undefined') { throw new Error('no window object present'); } else if (window.XMLHttpRequest) {