File tree Expand file tree Collapse file tree 1 file changed +24
-10
lines changed
Expand file tree Collapse file tree 1 file changed +24
-10
lines changed Original file line number Diff line number Diff line change @@ -3,19 +3,33 @@ let NODE_DEBUG;
33/* eslint no-undef: 0 */
44
55function shouldDebug ( ) {
6- if ( typeof window === "undefined" ) {
7- // Avoid multiple calls to process.env
8- if ( ! NODE_DEBUG ) {
9- NODE_DEBUG = ( process . env . DEBUG || "" ) . includes ( "kuzzle-sdk" ) ;
6+ /**
7+ * Some framework like react-native or other might emulate the window object
8+ * but when on plateforms like iOS / Android, the window.location is undefined.
9+ *
10+ * So we need to check if window.location is defined before using it otherwise
11+ * we will get an error.
12+ *
13+ * If something went wrong, be sure to return false to avoid any error.
14+ */
15+ try {
16+ if ( typeof window === "undefined" ) {
17+ // Avoid multiple calls to process.env
18+ if ( ! NODE_DEBUG ) {
19+ NODE_DEBUG = ( process . env . DEBUG || "" ) . includes ( "kuzzle-sdk" ) ;
20+ }
21+
22+ return NODE_DEBUG ;
1023 }
1124
12- return NODE_DEBUG ;
25+ return (
26+ window . debugKuzzleSdk ||
27+ ( window . location &&
28+ new URL ( window . location ) . searchParams . get ( "debugKuzzleSdk" ) !== null )
29+ ) ;
30+ } catch ( e ) {
31+ return false ;
1332 }
14-
15- return (
16- window . debugKuzzleSdk ||
17- new URL ( window . location ) . searchParams . get ( "debugKuzzleSdk" ) !== null
18- ) ;
1933}
2034
2135/**
You can’t perform that action at this time.
0 commit comments