From ca42bb1d2a93d20c234eb1c9ab998aea062f83f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Holas?= Date: Mon, 13 Jul 2015 09:42:27 +0200 Subject: [PATCH 1/2] In browsers check for XMLHttpRequest, not window In nodejs testing environment it's possible to use https://github.com/tmpvar/jsdom library to define a window object, but you still want to use node http adapter. Due to those diverse testing environmnents, I propose to test for XMLHttpRequest directly, because window global object is not a sure sign of a browser environment anymore. --- lib/core/dispatchRequest.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/core/dispatchRequest.js b/lib/core/dispatchRequest.js index f063497..54db2e7 100644 --- a/lib/core/dispatchRequest.js +++ b/lib/core/dispatchRequest.js @@ -11,7 +11,7 @@ module.exports = function dispatchRequest(config) { return new Promise(function (resolve, reject) { try { // For browsers use XHR adapter - if (typeof window !== 'undefined') { + if (typeof XMLHttpRequest !== 'undefined') { require('../adapters/xhr')(resolve, reject, config); } // For node use HTTP adapter From 72fc02f2a501a8345e80f2652fafa6ddb07cacca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Holas?= Date: Thu, 23 Jul 2015 14:19:14 +0200 Subject: [PATCH 2/2] XHR browser check now works in IE8 Test for ActiveXObject --- lib/core/dispatchRequest.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/core/dispatchRequest.js b/lib/core/dispatchRequest.js index 54db2e7..1ec313f 100644 --- a/lib/core/dispatchRequest.js +++ b/lib/core/dispatchRequest.js @@ -11,7 +11,7 @@ module.exports = function dispatchRequest(config) { return new Promise(function (resolve, reject) { try { // For browsers use XHR adapter - if (typeof XMLHttpRequest !== 'undefined') { + if ((typeof XMLHttpRequest !== 'undefined') || (typeof ActiveXObject !== 'undefined')) { require('../adapters/xhr')(resolve, reject, config); } // For node use HTTP adapter