From 603bd2f66c225b3fa8e3317978d06cccdb1f78cc Mon Sep 17 00:00:00 2001 From: Viktor Date: Sat, 25 Feb 2017 12:14:43 +0100 Subject: [PATCH 1/2] added proper detection of react-native in isStandardBrowserEnv function --- lib/utils.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index aef5fa1..94477ed 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -169,19 +169,22 @@ function trim(str) { * * This allows axios to run in a web worker, and react-native. * Both environments support XMLHttpRequest, but not fully standard globals. + * As of react-native 0.13, it can be identified from navigator.product. * * web workers: * typeof window -> undefined * typeof document -> undefined * * react-native: - * typeof document.createElement -> undefined + * navigator.product -> 'ReactNative' */ function isStandardBrowserEnv() { + if (typeof navigator.product !== 'undefined' && navigator.product === 'ReactNative') { + return false; + } return ( typeof window !== 'undefined' && - typeof document !== 'undefined' && - typeof document.createElement === 'function' + typeof document !== 'undefined' ); } From 5df39d8fa056e7eadf5aaceedb778b2568a4a73c Mon Sep 17 00:00:00 2001 From: Nick Uraltsev Date: Wed, 1 Mar 2017 21:52:42 -0800 Subject: [PATCH 2/2] Check that navigator is defined --- lib/utils.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index 94477ed..180820f 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -169,7 +169,6 @@ function trim(str) { * * This allows axios to run in a web worker, and react-native. * Both environments support XMLHttpRequest, but not fully standard globals. - * As of react-native 0.13, it can be identified from navigator.product. * * web workers: * typeof window -> undefined @@ -179,7 +178,7 @@ function trim(str) { * navigator.product -> 'ReactNative' */ function isStandardBrowserEnv() { - if (typeof navigator.product !== 'undefined' && navigator.product === 'ReactNative') { + if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') { return false; } return (