@microsoft/applicationinsights-core-js 3.0.0-beta.2208-03 → 3.0.0-beta.2208-16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -0
- package/browser/applicationinsights-core-js.integrity.json +9 -9
- package/browser/applicationinsights-core-js.js +2040 -2155
- package/browser/applicationinsights-core-js.js.map +1 -1
- package/browser/applicationinsights-core-js.min.js +2 -2
- package/browser/applicationinsights-core-js.min.js.map +1 -1
- package/dist/applicationinsights-core-js.api.json +6998 -10817
- package/dist/applicationinsights-core-js.api.md +88 -177
- package/dist/applicationinsights-core-js.d.ts +94 -494
- package/dist/applicationinsights-core-js.js +2040 -2155
- package/dist/applicationinsights-core-js.js.map +1 -1
- package/dist/applicationinsights-core-js.min.js +2 -2
- package/dist/applicationinsights-core-js.min.js.map +1 -1
- package/dist/applicationinsights-core-js.rollup.d.ts +94 -494
- package/dist-esm/JavaScriptSDK/AppInsightsCore.js +2 -2
- package/dist-esm/JavaScriptSDK/AppInsightsCore.js.map +1 -1
- package/dist-esm/JavaScriptSDK/BaseCore.js +11 -12
- package/dist-esm/JavaScriptSDK/BaseCore.js.map +1 -1
- package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js +3 -2
- package/dist-esm/JavaScriptSDK/BaseTelemetryPlugin.js.map +1 -1
- package/dist-esm/JavaScriptSDK/ChannelController.js +2 -2
- package/dist-esm/JavaScriptSDK/ChannelController.js.map +1 -1
- package/dist-esm/JavaScriptSDK/CookieMgr.js +27 -26
- package/dist-esm/JavaScriptSDK/CookieMgr.js.map +1 -1
- package/dist-esm/JavaScriptSDK/CoreUtils.js +8 -140
- package/dist-esm/JavaScriptSDK/CoreUtils.js.map +1 -1
- package/dist-esm/JavaScriptSDK/DataCacheHelper.js +2 -2
- package/dist-esm/JavaScriptSDK/DataCacheHelper.js.map +1 -1
- package/dist-esm/JavaScriptSDK/DbgExtensionUtils.js +3 -3
- package/dist-esm/JavaScriptSDK/DbgExtensionUtils.js.map +1 -1
- package/dist-esm/JavaScriptSDK/DiagnosticLogger.js +4 -3
- package/dist-esm/JavaScriptSDK/DiagnosticLogger.js.map +1 -1
- package/dist-esm/JavaScriptSDK/EnvUtils.js +132 -136
- package/dist-esm/JavaScriptSDK/EnvUtils.js.map +1 -1
- package/dist-esm/JavaScriptSDK/EventHelpers.js +2 -3
- package/dist-esm/JavaScriptSDK/EventHelpers.js.map +1 -1
- package/dist-esm/JavaScriptSDK/HelperFuncs.js +23 -470
- package/dist-esm/JavaScriptSDK/HelperFuncs.js.map +1 -1
- package/dist-esm/JavaScriptSDK/InstrumentHooks.js +5 -5
- package/dist-esm/JavaScriptSDK/InstrumentHooks.js.map +1 -1
- package/dist-esm/JavaScriptSDK/InternalConstants.js +4 -4
- package/dist-esm/JavaScriptSDK/InternalConstants.js.map +1 -1
- package/dist-esm/JavaScriptSDK/NotificationManager.js +2 -2
- package/dist-esm/JavaScriptSDK/NotificationManager.js.map +1 -1
- package/dist-esm/JavaScriptSDK/PerfManager.js +4 -8
- package/dist-esm/JavaScriptSDK/PerfManager.js.map +1 -1
- package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js +3 -3
- package/dist-esm/JavaScriptSDK/ProcessTelemetryContext.js.map +1 -1
- package/dist-esm/JavaScriptSDK/RandomHelper.js +1 -1
- package/dist-esm/JavaScriptSDK/TelemetryHelpers.js +2 -2
- package/dist-esm/JavaScriptSDK/TelemetryHelpers.js.map +1 -1
- package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js +3 -3
- package/dist-esm/JavaScriptSDK/TelemetryInitializerPlugin.js.map +1 -1
- package/dist-esm/JavaScriptSDK/UnloadHandlerContainer.js +2 -3
- package/dist-esm/JavaScriptSDK/UnloadHandlerContainer.js.map +1 -1
- package/dist-esm/JavaScriptSDK/W3cTraceParent.js +2 -2
- package/dist-esm/JavaScriptSDK/W3cTraceParent.js.map +1 -1
- package/dist-esm/JavaScriptSDK.Enums/EnumHelperFuncs.js +5 -31
- package/dist-esm/JavaScriptSDK.Enums/EnumHelperFuncs.js.map +1 -1
- package/dist-esm/JavaScriptSDK.Enums/EventsDiscardedReason.js +1 -1
- package/dist-esm/JavaScriptSDK.Enums/LoggingEnums.js +1 -1
- package/dist-esm/JavaScriptSDK.Enums/SendRequestReason.js +1 -1
- package/dist-esm/JavaScriptSDK.Enums/TelemetryUnloadReason.js +1 -1
- package/dist-esm/JavaScriptSDK.Enums/TelemetryUpdateReason.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IAppInsightsCore.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IChannelControls.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IConfiguration.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ICookieMgr.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IDbgExtension.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IDiagnosticLogger.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IDistributedTraceContext.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IInstrumentHooks.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/INotificationListener.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/INotificationManager.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IPerfEvent.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IPerfManager.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IProcessTelemetryContext.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryInitializers.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryItem.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPlugin.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryPluginChain.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUnloadState.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITelemetryUpdateState.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/ITraceParent.js +1 -1
- package/dist-esm/JavaScriptSDK.Interfaces/IUnloadableComponent.js +1 -1
- package/dist-esm/__DynamicConstants.js +11 -13
- package/dist-esm/__DynamicConstants.js.map +1 -1
- package/dist-esm/applicationinsights-core-js.js +6 -5
- package/dist-esm/applicationinsights-core-js.js.map +1 -1
- package/package.json +4 -3
- package/src/JavaScriptSDK/AppInsightsCore.ts +1 -1
- package/src/JavaScriptSDK/BaseCore.ts +2 -4
- package/src/JavaScriptSDK/BaseTelemetryPlugin.ts +2 -1
- package/src/JavaScriptSDK/ChannelController.ts +1 -1
- package/src/JavaScriptSDK/CookieMgr.ts +6 -5
- package/src/JavaScriptSDK/CoreUtils.ts +7 -423
- package/src/JavaScriptSDK/DbgExtensionUtils.ts +2 -2
- package/src/JavaScriptSDK/DiagnosticLogger.ts +3 -2
- package/src/JavaScriptSDK/EnvUtils.ts +145 -148
- package/src/JavaScriptSDK/EventHelpers.ts +1 -2
- package/src/JavaScriptSDK/HelperFuncs.ts +22 -536
- package/src/JavaScriptSDK/InstrumentHooks.ts +4 -4
- package/src/JavaScriptSDK/InternalConstants.ts +3 -3
- package/src/JavaScriptSDK/NotificationManager.ts +1 -1
- package/src/JavaScriptSDK/PerfManager.ts +3 -7
- package/src/JavaScriptSDK/ProcessTelemetryContext.ts +4 -4
- package/src/JavaScriptSDK/TelemetryHelpers.ts +1 -1
- package/src/JavaScriptSDK/TelemetryInitializerPlugin.ts +2 -2
- package/src/JavaScriptSDK/UnloadHandlerContainer.ts +1 -2
- package/src/JavaScriptSDK/W3cTraceParent.ts +1 -1
- package/src/JavaScriptSDK.Enums/EnumHelperFuncs.ts +5 -36
- package/src/JavaScriptSDK.Interfaces/ITelemetryPlugin.ts +7 -0
- package/tsconfig.json +1 -1
- package/types/JavaScriptSDK/CoreUtils.d.ts +0 -270
- package/types/JavaScriptSDK/EnvUtils.d.ts +0 -65
- package/types/JavaScriptSDK/HelperFuncs.d.ts +3 -154
- package/types/JavaScriptSDK.Enums/EnumHelperFuncs.d.ts +6 -18
- package/types/JavaScriptSDK.Interfaces/ITelemetryPlugin.d.ts +6 -0
- package/types/__DynamicConstants.d.ts +2 -4
- package/types/applicationinsights-core-js.d.ts +5 -4
- package/types/tsdoc-metadata.json +1 -1
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Application Insights JavaScript SDK - Core, 3.0.0-beta.2208-
|
|
2
|
+
* Application Insights JavaScript SDK - Core, 3.0.0-beta.2208-16
|
|
3
3
|
* Copyright (c) Microsoft and contributors. All rights reserved.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
"use strict";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
8
|
+
import { strShimObject, strShimPrototype, strShimUndefined } from "@microsoft/applicationinsights-shims";
|
|
9
|
+
import { getDocument, getInst, getNavigator, hasNavigator, isString, isUndefined } from "@nevware21/ts-utils";
|
|
10
|
+
import { _DYN_LENGTH, _DYN_NAME, _DYN_SPLIT, _DYN_TO_LOWER_CASE, _DYN_USER_AGENT } from "../__DynamicConstants";
|
|
11
|
+
import { strContains } from "./HelperFuncs";
|
|
11
12
|
import { STR_EMPTY } from "./InternalConstants";
|
|
12
13
|
/**
|
|
13
14
|
* This file exists to hold environment utilities that are required to check and
|
|
@@ -15,11 +16,7 @@ import { STR_EMPTY } from "./InternalConstants";
|
|
|
15
16
|
* only use defined methods (functions) in this class so that users of these
|
|
16
17
|
* functions/properties only need to include those that are used within their own modules.
|
|
17
18
|
*/
|
|
18
|
-
var strWindow = "window";
|
|
19
|
-
var strDocument = "document";
|
|
20
19
|
var strDocumentMode = "documentMode";
|
|
21
|
-
var strNavigator = "navigator";
|
|
22
|
-
var strHistory = "history";
|
|
23
20
|
var strLocation = "location";
|
|
24
21
|
var strConsole = "console";
|
|
25
22
|
var strPerformance = "performance";
|
|
@@ -69,107 +66,107 @@ function _hasProperty(theClass, property) {
|
|
|
69
66
|
export function setEnableEnvMocks(enabled) {
|
|
70
67
|
_enableMocks = enabled;
|
|
71
68
|
}
|
|
72
|
-
/**
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
export function
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
export
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
export function getWindow() {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
export function hasDocument() {
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
export function getDocument() {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
export function hasNavigator() {
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
export function getNavigator() {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
export function hasHistory() {
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
export function getHistory() {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
}
|
|
69
|
+
// /**
|
|
70
|
+
// * Return the named global object if available, will return null if the object is not available.
|
|
71
|
+
// * @param name The globally named object
|
|
72
|
+
// */
|
|
73
|
+
// export function getinst<T>(name:string): T {
|
|
74
|
+
// let gbl = getGlobal();
|
|
75
|
+
// if (gbl && gbl[name]) {
|
|
76
|
+
// return gbl[name] as T;
|
|
77
|
+
// }
|
|
78
|
+
// // Test workaround, for environments where <global>.window (when global == window) doesn't return the base window
|
|
79
|
+
// if (name === strWindow && hasWindow()) {
|
|
80
|
+
// // tslint:disable-next-line: no-angle-bracket-type-assertion
|
|
81
|
+
// return <any>window as T;
|
|
82
|
+
// }
|
|
83
|
+
// return null;
|
|
84
|
+
// }
|
|
85
|
+
// /**
|
|
86
|
+
// * Checks if window object is available, this is required as we support the API running without a
|
|
87
|
+
// * window /document (eg. Node server, electron webworkers) and if we attempt to assign a window
|
|
88
|
+
// * object to a local variable or pass as an argument an "Uncaught ReferenceError: window is not defined"
|
|
89
|
+
// * exception will be thrown.
|
|
90
|
+
// * Defined as a function to support lazy / late binding environments.
|
|
91
|
+
// */
|
|
92
|
+
// export const hasWindow = () => boolean = hasWindow;
|
|
93
|
+
// return Boolean(typeof window === strShimObject && window);
|
|
94
|
+
// }
|
|
95
|
+
// /**
|
|
96
|
+
// * Returns the global window object if it is present otherwise null.
|
|
97
|
+
// * This helper is used to access the window object without causing an exception
|
|
98
|
+
// * "Uncaught ReferenceError: window is not defined"
|
|
99
|
+
// */
|
|
100
|
+
// export function getWindow(): Window | null {
|
|
101
|
+
// if (hasWindow()) {
|
|
102
|
+
// return window;
|
|
103
|
+
// }
|
|
104
|
+
// // Return the global instance or null
|
|
105
|
+
// return getInst(strWindow);
|
|
106
|
+
// }
|
|
107
|
+
// /**
|
|
108
|
+
// * Checks if document object is available, this is required as we support the API running without a
|
|
109
|
+
// * window /document (eg. Node server, electron webworkers) and if we attempt to assign a document
|
|
110
|
+
// * object to a local variable or pass as an argument an "Uncaught ReferenceError: document is not defined"
|
|
111
|
+
// * exception will be thrown.
|
|
112
|
+
// * Defined as a function to support lazy / late binding environments.
|
|
113
|
+
// */
|
|
114
|
+
// export function hasDocument(): boolean {
|
|
115
|
+
// return Boolean(typeof document === strShimObject && document);
|
|
116
|
+
// }
|
|
117
|
+
// /**
|
|
118
|
+
// * Returns the global document object if it is present otherwise null.
|
|
119
|
+
// * This helper is used to access the document object without causing an exception
|
|
120
|
+
// * "Uncaught ReferenceError: document is not defined"
|
|
121
|
+
// */
|
|
122
|
+
// export function getDocument(): Document | null {
|
|
123
|
+
// if (hasDocument()) {
|
|
124
|
+
// return document;
|
|
125
|
+
// }
|
|
126
|
+
// return getInst(strDocument);
|
|
127
|
+
// }
|
|
128
|
+
// /**
|
|
129
|
+
// * Checks if navigator object is available, this is required as we support the API running without a
|
|
130
|
+
// * window /document (eg. Node server, electron webworkers) and if we attempt to assign a navigator
|
|
131
|
+
// * object to a local variable or pass as an argument an "Uncaught ReferenceError: navigator is not defined"
|
|
132
|
+
// * exception will be thrown.
|
|
133
|
+
// * Defined as a function to support lazy / late binding environments.
|
|
134
|
+
// */
|
|
135
|
+
// export function hasNavigator(): boolean {
|
|
136
|
+
// return Boolean(typeof navigator === strShimObject && navigator);
|
|
137
|
+
// }
|
|
138
|
+
// /**
|
|
139
|
+
// * Returns the global navigator object if it is present otherwise null.
|
|
140
|
+
// * This helper is used to access the navigator object without causing an exception
|
|
141
|
+
// * "Uncaught ReferenceError: navigator is not defined"
|
|
142
|
+
// */
|
|
143
|
+
// export function getNavigator(): Navigator | null {
|
|
144
|
+
// if (hasNavigator()) {
|
|
145
|
+
// return navigator;
|
|
146
|
+
// }
|
|
147
|
+
// return getInst(strNavigator);
|
|
148
|
+
// }
|
|
149
|
+
// /**
|
|
150
|
+
// * Checks if history object is available, this is required as we support the API running without a
|
|
151
|
+
// * window /document (eg. Node server, electron webworkers) and if we attempt to assign a history
|
|
152
|
+
// * object to a local variable or pass as an argument an "Uncaught ReferenceError: history is not defined"
|
|
153
|
+
// * exception will be thrown.
|
|
154
|
+
// * Defined as a function to support lazy / late binding environments.
|
|
155
|
+
// */
|
|
156
|
+
// export function hasHistory(): boolean {
|
|
157
|
+
// return Boolean(typeof history === strShimObject && history);
|
|
158
|
+
// }
|
|
159
|
+
// /**
|
|
160
|
+
// * Returns the global history object if it is present otherwise null.
|
|
161
|
+
// * This helper is used to access the history object without causing an exception
|
|
162
|
+
// * "Uncaught ReferenceError: history is not defined"
|
|
163
|
+
// */
|
|
164
|
+
// export function getHistory(): History | null {
|
|
165
|
+
// if (hasHistory()) {
|
|
166
|
+
// return history;
|
|
167
|
+
// }
|
|
168
|
+
// return getInst(strHistory);
|
|
169
|
+
// }
|
|
173
170
|
/**
|
|
174
171
|
* Returns the global location object if it is present otherwise null.
|
|
175
172
|
* This helper is used to access the location object without causing an exception
|
|
@@ -177,7 +174,7 @@ export function getHistory() {
|
|
|
177
174
|
*/
|
|
178
175
|
export function getLocation(checkForMock) {
|
|
179
176
|
if (checkForMock && _enableMocks) {
|
|
180
|
-
var mockLocation =
|
|
177
|
+
var mockLocation = getInst("__mockLocation");
|
|
181
178
|
if (mockLocation) {
|
|
182
179
|
return mockLocation;
|
|
183
180
|
}
|
|
@@ -185,7 +182,7 @@ export function getLocation(checkForMock) {
|
|
|
185
182
|
if (typeof location === strShimObject && location) {
|
|
186
183
|
return location;
|
|
187
184
|
}
|
|
188
|
-
return
|
|
185
|
+
return getInst(strLocation);
|
|
189
186
|
}
|
|
190
187
|
/**
|
|
191
188
|
* Returns the global console object
|
|
@@ -194,7 +191,7 @@ export function getConsole() {
|
|
|
194
191
|
if (typeof console !== strShimUndefined) {
|
|
195
192
|
return console;
|
|
196
193
|
}
|
|
197
|
-
return
|
|
194
|
+
return getInst(strConsole);
|
|
198
195
|
}
|
|
199
196
|
/**
|
|
200
197
|
* Returns the performance object if it is present otherwise null.
|
|
@@ -202,7 +199,7 @@ export function getConsole() {
|
|
|
202
199
|
* global instance which could be window or globalThis for a web worker
|
|
203
200
|
*/
|
|
204
201
|
export function getPerformance() {
|
|
205
|
-
return
|
|
202
|
+
return getInst(strPerformance);
|
|
206
203
|
}
|
|
207
204
|
/**
|
|
208
205
|
* Checks if JSON object is available, this is required as we support the API running without a
|
|
@@ -212,7 +209,7 @@ export function getPerformance() {
|
|
|
212
209
|
* Defined as a function to support lazy / late binding environments.
|
|
213
210
|
*/
|
|
214
211
|
export function hasJSON() {
|
|
215
|
-
return Boolean((typeof JSON === strShimObject && JSON) ||
|
|
212
|
+
return Boolean((typeof JSON === strShimObject && JSON) || getInst(strJSON) !== null);
|
|
216
213
|
}
|
|
217
214
|
/**
|
|
218
215
|
* Returns the global JSON object if it is present otherwise null.
|
|
@@ -221,7 +218,7 @@ export function hasJSON() {
|
|
|
221
218
|
*/
|
|
222
219
|
export function getJSON() {
|
|
223
220
|
if (hasJSON()) {
|
|
224
|
-
return JSON ||
|
|
221
|
+
return JSON || getInst(strJSON);
|
|
225
222
|
}
|
|
226
223
|
return null;
|
|
227
224
|
}
|
|
@@ -231,7 +228,7 @@ export function getJSON() {
|
|
|
231
228
|
* global instance which could be window or globalThis for a web worker
|
|
232
229
|
*/
|
|
233
230
|
export function getCrypto() {
|
|
234
|
-
return
|
|
231
|
+
return getInst(strCrypto);
|
|
235
232
|
}
|
|
236
233
|
/**
|
|
237
234
|
* Returns the crypto object if it is present otherwise null.
|
|
@@ -239,7 +236,7 @@ export function getCrypto() {
|
|
|
239
236
|
* global instance which could be window or globalThis for a web worker
|
|
240
237
|
*/
|
|
241
238
|
export function getMsCrypto() {
|
|
242
|
-
return
|
|
239
|
+
return getInst(strMsCrypto);
|
|
243
240
|
}
|
|
244
241
|
/**
|
|
245
242
|
* Returns whether the environment is reporting that we are running in a React Native Environment
|
|
@@ -288,27 +285,26 @@ export function getIEVersion(userAgentStr) {
|
|
|
288
285
|
}
|
|
289
286
|
return null;
|
|
290
287
|
}
|
|
291
|
-
/**
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
export function dumpObj(object) {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
}
|
|
288
|
+
// /**
|
|
289
|
+
// * Returns string representation of an object suitable for diagnostics logging.
|
|
290
|
+
// */
|
|
291
|
+
// export function dumpObj(object: any): string {
|
|
292
|
+
// const objectTypeDump: string = Object[strShimPrototype].toString.call(object);
|
|
293
|
+
// let propertyValueDump: string = STR_EMPTY;
|
|
294
|
+
// if (objectTypeDump === "[object Error]") {
|
|
295
|
+
// propertyValueDump = "{ stack: '" + object.stack + "', message: '" + object.message + "', name: '" + object.name + "'";
|
|
296
|
+
// } else if (hasJSON()) {
|
|
297
|
+
// propertyValueDump = getJSON().stringify(object);
|
|
298
|
+
// }
|
|
299
|
+
// return objectTypeDump + propertyValueDump;
|
|
300
|
+
// }
|
|
305
301
|
export function isSafari(userAgentStr) {
|
|
306
302
|
if (!userAgentStr || !isString(userAgentStr)) {
|
|
307
303
|
var navigator_2 = getNavigator() || {};
|
|
308
304
|
userAgentStr = navigator_2 ? (navigator_2[_DYN_USER_AGENT /* @min:%2euserAgent */] || STR_EMPTY)[_DYN_TO_LOWER_CASE /* @min:%2etoLowerCase */]() : STR_EMPTY;
|
|
309
305
|
}
|
|
310
306
|
var ua = (userAgentStr || STR_EMPTY)[_DYN_TO_LOWER_CASE /* @min:%2etoLowerCase */]();
|
|
311
|
-
return (ua
|
|
307
|
+
return (ua.indexOf("safari") >= 0);
|
|
312
308
|
}
|
|
313
309
|
/**
|
|
314
310
|
* Checks if HTML5 Beacons are supported in the current environment.
|
|
@@ -328,8 +324,8 @@ export function isBeaconsSupported() {
|
|
|
328
324
|
export function isFetchSupported(withKeepAlive) {
|
|
329
325
|
var isSupported = false;
|
|
330
326
|
try {
|
|
331
|
-
isSupported = !!
|
|
332
|
-
var request =
|
|
327
|
+
isSupported = !!getInst("fetch");
|
|
328
|
+
var request = getInst("Request");
|
|
333
329
|
if (isSupported && withKeepAlive && request) {
|
|
334
330
|
isSupported = _hasProperty(request, "keepalive");
|
|
335
331
|
}
|
|
@@ -343,7 +339,7 @@ export function useXDomainRequest() {
|
|
|
343
339
|
if (_useXDomainRequest === null) {
|
|
344
340
|
_useXDomainRequest = (typeof XDomainRequest !== strShimUndefined);
|
|
345
341
|
if (_useXDomainRequest && isXhrSupported()) {
|
|
346
|
-
_useXDomainRequest = _useXDomainRequest && !_hasProperty(
|
|
342
|
+
_useXDomainRequest = _useXDomainRequest && !_hasProperty(getInst(strXMLHttpRequest), "withCredentials");
|
|
347
343
|
}
|
|
348
344
|
}
|
|
349
345
|
return _useXDomainRequest;
|
|
@@ -355,7 +351,7 @@ export function useXDomainRequest() {
|
|
|
355
351
|
export function isXhrSupported() {
|
|
356
352
|
var isSupported = false;
|
|
357
353
|
try {
|
|
358
|
-
var xmlHttpRequest =
|
|
354
|
+
var xmlHttpRequest = getInst(strXMLHttpRequest);
|
|
359
355
|
isSupported = !!xmlHttpRequest;
|
|
360
356
|
}
|
|
361
357
|
catch (e) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EnvUtils.js.map","sources":["EnvUtils.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\n\"use strict\";\r\nimport { getGlobal, strShimObject, strShimPrototype, strShimUndefined } from \"@microsoft/applicationinsights-shims\";\r\nimport { _DYN_CALL, _DYN_INDEX_OF, _DYN_LENGTH, _DYN_NAME, _DYN_SPLIT, _DYN_TO_LOWER_CASE, _DYN_USER_AGENT } from \"../__DynamicConstants\";\r\nimport { isString, isUndefined, strContains } from \"./HelperFuncs\";\r\nimport { STR_EMPTY } from \"./InternalConstants\";\r\n/**\r\n * This file exists to hold environment utilities that are required to check and\r\n * validate the current operating environment. Unless otherwise required, please\r\n * only use defined methods (functions) in this class so that users of these\r\n * functions/properties only need to include those that are used within their own modules.\r\n */\r\nvar strWindow = \"window\";\r\nvar strDocument = \"document\";\r\nvar strDocumentMode = \"documentMode\";\r\nvar strNavigator = \"navigator\";\r\nvar strHistory = \"history\";\r\nvar strLocation = \"location\";\r\nvar strConsole = \"console\";\r\nvar strPerformance = \"performance\";\r\nvar strJSON = \"JSON\";\r\nvar strCrypto = \"crypto\";\r\nvar strMsCrypto = \"msCrypto\";\r\nvar strReactNative = \"ReactNative\";\r\nvar strMsie = \"msie\";\r\nvar strTrident = \"trident/\";\r\nvar strXMLHttpRequest = \"XMLHttpRequest\";\r\nvar _isTrident = null;\r\nvar _navUserAgentCheck = null;\r\nvar _enableMocks = false;\r\nvar _useXDomainRequest = null;\r\nvar _beaconsSupported = null;\r\nfunction _hasProperty(theClass, property) {\r\n var supported = false;\r\n if (theClass) {\r\n try {\r\n supported = property in theClass;\r\n if (!supported) {\r\n var proto = theClass[strShimPrototype];\r\n if (proto) {\r\n supported = property in proto;\r\n }\r\n }\r\n }\r\n catch (e) {\r\n // Do Nothing\r\n }\r\n if (!supported) {\r\n try {\r\n var tmp = new theClass();\r\n supported = !isUndefined(tmp[property]);\r\n }\r\n catch (e) {\r\n // Do Nothing\r\n }\r\n }\r\n }\r\n return supported;\r\n}\r\n/**\r\n * Enable the lookup of test mock objects if requested\r\n * @param enabled\r\n */\r\nexport function setEnableEnvMocks(enabled) {\r\n _enableMocks = enabled;\r\n}\r\n/**\r\n * Return the named global object if available, will return null if the object is not available.\r\n * @param name The globally named object\r\n */\r\nexport function getGlobalInst(name) {\r\n var gbl = getGlobal();\r\n if (gbl && gbl[name]) {\r\n return gbl[name];\r\n }\r\n // Test workaround, for environments where <global>.window (when global == window) doesn't return the base window\r\n if (name === strWindow && hasWindow()) {\r\n // tslint:disable-next-line: no-angle-bracket-type-assertion\r\n return window;\r\n }\r\n return null;\r\n}\r\n/**\r\n * Checks if window object is available, this is required as we support the API running without a\r\n * window /document (eg. Node server, electron webworkers) and if we attempt to assign a window\r\n * object to a local variable or pass as an argument an \"Uncaught ReferenceError: window is not defined\"\r\n * exception will be thrown.\r\n * Defined as a function to support lazy / late binding environments.\r\n */\r\nexport function hasWindow() {\r\n return Boolean(typeof window === strShimObject && window);\r\n}\r\n/**\r\n * Returns the global window object if it is present otherwise null.\r\n * This helper is used to access the window object without causing an exception\r\n * \"Uncaught ReferenceError: window is not defined\"\r\n */\r\nexport function getWindow() {\r\n if (hasWindow()) {\r\n return window;\r\n }\r\n // Return the global instance or null\r\n return getGlobalInst(strWindow);\r\n}\r\n/**\r\n * Checks if document object is available, this is required as we support the API running without a\r\n * window /document (eg. Node server, electron webworkers) and if we attempt to assign a document\r\n * object to a local variable or pass as an argument an \"Uncaught ReferenceError: document is not defined\"\r\n * exception will be thrown.\r\n * Defined as a function to support lazy / late binding environments.\r\n */\r\nexport function hasDocument() {\r\n return Boolean(typeof document === strShimObject && document);\r\n}\r\n/**\r\n * Returns the global document object if it is present otherwise null.\r\n * This helper is used to access the document object without causing an exception\r\n * \"Uncaught ReferenceError: document is not defined\"\r\n */\r\nexport function getDocument() {\r\n if (hasDocument()) {\r\n return document;\r\n }\r\n return getGlobalInst(strDocument);\r\n}\r\n/**\r\n * Checks if navigator object is available, this is required as we support the API running without a\r\n * window /document (eg. Node server, electron webworkers) and if we attempt to assign a navigator\r\n * object to a local variable or pass as an argument an \"Uncaught ReferenceError: navigator is not defined\"\r\n * exception will be thrown.\r\n * Defined as a function to support lazy / late binding environments.\r\n */\r\nexport function hasNavigator() {\r\n return Boolean(typeof navigator === strShimObject && navigator);\r\n}\r\n/**\r\n * Returns the global navigator object if it is present otherwise null.\r\n * This helper is used to access the navigator object without causing an exception\r\n * \"Uncaught ReferenceError: navigator is not defined\"\r\n */\r\nexport function getNavigator() {\r\n if (hasNavigator()) {\r\n return navigator;\r\n }\r\n return getGlobalInst(strNavigator);\r\n}\r\n/**\r\n * Checks if history object is available, this is required as we support the API running without a\r\n * window /document (eg. Node server, electron webworkers) and if we attempt to assign a history\r\n * object to a local variable or pass as an argument an \"Uncaught ReferenceError: history is not defined\"\r\n * exception will be thrown.\r\n * Defined as a function to support lazy / late binding environments.\r\n */\r\nexport function hasHistory() {\r\n return Boolean(typeof history === strShimObject && history);\r\n}\r\n/**\r\n * Returns the global history object if it is present otherwise null.\r\n * This helper is used to access the history object without causing an exception\r\n * \"Uncaught ReferenceError: history is not defined\"\r\n */\r\nexport function getHistory() {\r\n if (hasHistory()) {\r\n return history;\r\n }\r\n return getGlobalInst(strHistory);\r\n}\r\n/**\r\n * Returns the global location object if it is present otherwise null.\r\n * This helper is used to access the location object without causing an exception\r\n * \"Uncaught ReferenceError: location is not defined\"\r\n */\r\nexport function getLocation(checkForMock) {\r\n if (checkForMock && _enableMocks) {\r\n var mockLocation = getGlobalInst(\"__mockLocation\");\r\n if (mockLocation) {\r\n return mockLocation;\r\n }\r\n }\r\n if (typeof location === strShimObject && location) {\r\n return location;\r\n }\r\n return getGlobalInst(strLocation);\r\n}\r\n/**\r\n * Returns the global console object\r\n */\r\nexport function getConsole() {\r\n if (typeof console !== strShimUndefined) {\r\n return console;\r\n }\r\n return getGlobalInst(strConsole);\r\n}\r\n/**\r\n * Returns the performance object if it is present otherwise null.\r\n * This helper is used to access the performance object from the current\r\n * global instance which could be window or globalThis for a web worker\r\n */\r\nexport function getPerformance() {\r\n return getGlobalInst(strPerformance);\r\n}\r\n/**\r\n * Checks if JSON object is available, this is required as we support the API running without a\r\n * window /document (eg. Node server, electron webworkers) and if we attempt to assign a history\r\n * object to a local variable or pass as an argument an \"Uncaught ReferenceError: JSON is not defined\"\r\n * exception will be thrown.\r\n * Defined as a function to support lazy / late binding environments.\r\n */\r\nexport function hasJSON() {\r\n return Boolean((typeof JSON === strShimObject && JSON) || getGlobalInst(strJSON) !== null);\r\n}\r\n/**\r\n * Returns the global JSON object if it is present otherwise null.\r\n * This helper is used to access the JSON object without causing an exception\r\n * \"Uncaught ReferenceError: JSON is not defined\"\r\n */\r\nexport function getJSON() {\r\n if (hasJSON()) {\r\n return JSON || getGlobalInst(strJSON);\r\n }\r\n return null;\r\n}\r\n/**\r\n * Returns the crypto object if it is present otherwise null.\r\n * This helper is used to access the crypto object from the current\r\n * global instance which could be window or globalThis for a web worker\r\n */\r\nexport function getCrypto() {\r\n return getGlobalInst(strCrypto);\r\n}\r\n/**\r\n * Returns the crypto object if it is present otherwise null.\r\n * This helper is used to access the crypto object from the current\r\n * global instance which could be window or globalThis for a web worker\r\n */\r\nexport function getMsCrypto() {\r\n return getGlobalInst(strMsCrypto);\r\n}\r\n/**\r\n * Returns whether the environment is reporting that we are running in a React Native Environment\r\n */\r\nexport function isReactNative() {\r\n // If running in React Native, navigator.product will be populated\r\n var nav = getNavigator();\r\n if (nav && nav.product) {\r\n return nav.product === strReactNative;\r\n }\r\n return false;\r\n}\r\n/**\r\n * Identifies whether the current environment appears to be IE\r\n */\r\nexport function isIE() {\r\n var nav = getNavigator();\r\n if (nav && (nav[_DYN_USER_AGENT /* @min:%2euserAgent */] !== _navUserAgentCheck || _isTrident === null)) {\r\n // Added to support test mocking of the user agent\r\n _navUserAgentCheck = nav[_DYN_USER_AGENT /* @min:%2euserAgent */];\r\n var userAgent = (_navUserAgentCheck || STR_EMPTY)[_DYN_TO_LOWER_CASE /* @min:%2etoLowerCase */]();\r\n _isTrident = (strContains(userAgent, strMsie) || strContains(userAgent, strTrident));\r\n }\r\n return _isTrident;\r\n}\r\n/**\r\n * Gets IE version returning the document emulation mode if we are running on IE, or null otherwise\r\n */\r\nexport function getIEVersion(userAgentStr) {\r\n if (userAgentStr === void 0) { userAgentStr = null; }\r\n if (!userAgentStr) {\r\n var navigator_1 = getNavigator() || {};\r\n userAgentStr = navigator_1 ? (navigator_1[_DYN_USER_AGENT /* @min:%2euserAgent */] || STR_EMPTY)[_DYN_TO_LOWER_CASE /* @min:%2etoLowerCase */]() : STR_EMPTY;\r\n }\r\n var ua = (userAgentStr || STR_EMPTY)[_DYN_TO_LOWER_CASE /* @min:%2etoLowerCase */]();\r\n // Also check for documentMode in case X-UA-Compatible meta tag was included in HTML.\r\n if (strContains(ua, strMsie)) {\r\n var doc = getDocument() || {};\r\n return Math.max(parseInt(ua[_DYN_SPLIT /* @min:%2esplit */](strMsie)[1]), (doc[strDocumentMode] || 0));\r\n }\r\n else if (strContains(ua, strTrident)) {\r\n var tridentVer = parseInt(ua[_DYN_SPLIT /* @min:%2esplit */](strTrident)[1]);\r\n if (tridentVer) {\r\n return tridentVer + 4;\r\n }\r\n }\r\n return null;\r\n}\r\n/**\r\n * Returns string representation of an object suitable for diagnostics logging.\r\n */\r\nexport function dumpObj(object) {\r\n var objectTypeDump = Object[strShimPrototype].toString[_DYN_CALL /* @min:%2ecall */](object);\r\n var propertyValueDump = STR_EMPTY;\r\n if (objectTypeDump === \"[object Error]\") {\r\n propertyValueDump = \"{ stack: '\" + object.stack + \"', message: '\" + object.message + \"', name: '\" + object[_DYN_NAME /* @min:%2ename */] + \"'\";\r\n }\r\n else if (hasJSON()) {\r\n propertyValueDump = getJSON().stringify(object);\r\n }\r\n return objectTypeDump + propertyValueDump;\r\n}\r\nexport function isSafari(userAgentStr) {\r\n if (!userAgentStr || !isString(userAgentStr)) {\r\n var navigator_2 = getNavigator() || {};\r\n userAgentStr = navigator_2 ? (navigator_2[_DYN_USER_AGENT /* @min:%2euserAgent */] || STR_EMPTY)[_DYN_TO_LOWER_CASE /* @min:%2etoLowerCase */]() : STR_EMPTY;\r\n }\r\n var ua = (userAgentStr || STR_EMPTY)[_DYN_TO_LOWER_CASE /* @min:%2etoLowerCase */]();\r\n return (ua[_DYN_INDEX_OF /* @min:%2eindexOf */](\"safari\") >= 0);\r\n}\r\n/**\r\n * Checks if HTML5 Beacons are supported in the current environment.\r\n * @returns True if supported, false otherwise.\r\n */\r\nexport function isBeaconsSupported() {\r\n if (_beaconsSupported === null) {\r\n _beaconsSupported = hasNavigator() && Boolean(getNavigator().sendBeacon);\r\n }\r\n return _beaconsSupported;\r\n}\r\n/**\r\n * Checks if the Fetch API is supported in the current environment.\r\n * @param withKeepAlive - [Optional] If True, check if fetch is available and it supports the keepalive feature, otherwise only check if fetch is supported\r\n * @returns True if supported, otherwise false\r\n */\r\nexport function isFetchSupported(withKeepAlive) {\r\n var isSupported = false;\r\n try {\r\n isSupported = !!getGlobalInst(\"fetch\");\r\n var request = getGlobalInst(\"Request\");\r\n if (isSupported && withKeepAlive && request) {\r\n isSupported = _hasProperty(request, \"keepalive\");\r\n }\r\n }\r\n catch (e) {\r\n // Just Swallow any failure during availability checks\r\n }\r\n return isSupported;\r\n}\r\nexport function useXDomainRequest() {\r\n if (_useXDomainRequest === null) {\r\n _useXDomainRequest = (typeof XDomainRequest !== strShimUndefined);\r\n if (_useXDomainRequest && isXhrSupported()) {\r\n _useXDomainRequest = _useXDomainRequest && !_hasProperty(getGlobalInst(strXMLHttpRequest), \"withCredentials\");\r\n }\r\n }\r\n return _useXDomainRequest;\r\n}\r\n/**\r\n * Checks if XMLHttpRequest is supported\r\n * @returns True if supported, otherwise false\r\n */\r\nexport function isXhrSupported() {\r\n var isSupported = false;\r\n try {\r\n var xmlHttpRequest = getGlobalInst(strXMLHttpRequest);\r\n isSupported = !!xmlHttpRequest;\r\n }\r\n catch (e) {\r\n // Just Swallow any failure during availability checks\r\n }\r\n return isSupported;\r\n}\r\nfunction _getNamedValue(values, name) {\r\n if (values) {\r\n for (var i = 0; i < values[_DYN_LENGTH /* @min:%2elength */]; i++) {\r\n var value = values[i];\r\n if (value[_DYN_NAME /* @min:%2ename */]) {\r\n if (value[_DYN_NAME /* @min:%2ename */] === name) {\r\n return value;\r\n }\r\n }\r\n }\r\n }\r\n return {};\r\n}\r\n/**\r\n * Helper function to fetch the named meta-tag from the page.\r\n * @param name\r\n */\r\nexport function findMetaTag(name) {\r\n var doc = getDocument();\r\n if (doc && name) {\r\n // Look for a meta-tag\r\n return _getNamedValue(doc.querySelectorAll(\"meta\"), name).content;\r\n }\r\n return null;\r\n}\r\n/**\r\n * Helper function to fetch the named server timing value from the page response (first navigation event).\r\n * @param name\r\n */\r\nexport function findNamedServerTiming(name) {\r\n var value;\r\n var perf = getPerformance();\r\n if (perf) {\r\n // Try looking for a server-timing header\r\n var navPerf = perf.getEntriesByType(\"navigation\") || [];\r\n value = _getNamedValue((navPerf[_DYN_LENGTH /* @min:%2elength */] > 0 ? navPerf[0] : {}).serverTiming, name).description;\r\n }\r\n return value;\r\n}\r\n//# sourceMappingURL=EnvUtils.js.map"],"names":[],"mappings":";;;;AAA4D;AAC1B;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA"}
|
|
1
|
+
{"version":3,"file":"EnvUtils.js.map","sources":["EnvUtils.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\n\"use strict\";\r\nimport { strShimObject, strShimPrototype, strShimUndefined } from \"@microsoft/applicationinsights-shims\";\r\nimport { getDocument, getInst, getNavigator, hasNavigator, isString, isUndefined } from \"@nevware21/ts-utils\";\r\nimport { _DYN_LENGTH, _DYN_NAME, _DYN_SPLIT, _DYN_TO_LOWER_CASE, _DYN_USER_AGENT } from \"../__DynamicConstants\";\r\nimport { strContains } from \"./HelperFuncs\";\r\nimport { STR_EMPTY } from \"./InternalConstants\";\r\n/**\r\n * This file exists to hold environment utilities that are required to check and\r\n * validate the current operating environment. Unless otherwise required, please\r\n * only use defined methods (functions) in this class so that users of these\r\n * functions/properties only need to include those that are used within their own modules.\r\n */\r\nvar strDocumentMode = \"documentMode\";\r\nvar strLocation = \"location\";\r\nvar strConsole = \"console\";\r\nvar strPerformance = \"performance\";\r\nvar strJSON = \"JSON\";\r\nvar strCrypto = \"crypto\";\r\nvar strMsCrypto = \"msCrypto\";\r\nvar strReactNative = \"ReactNative\";\r\nvar strMsie = \"msie\";\r\nvar strTrident = \"trident/\";\r\nvar strXMLHttpRequest = \"XMLHttpRequest\";\r\nvar _isTrident = null;\r\nvar _navUserAgentCheck = null;\r\nvar _enableMocks = false;\r\nvar _useXDomainRequest = null;\r\nvar _beaconsSupported = null;\r\nfunction _hasProperty(theClass, property) {\r\n var supported = false;\r\n if (theClass) {\r\n try {\r\n supported = property in theClass;\r\n if (!supported) {\r\n var proto = theClass[strShimPrototype];\r\n if (proto) {\r\n supported = property in proto;\r\n }\r\n }\r\n }\r\n catch (e) {\r\n // Do Nothing\r\n }\r\n if (!supported) {\r\n try {\r\n var tmp = new theClass();\r\n supported = !isUndefined(tmp[property]);\r\n }\r\n catch (e) {\r\n // Do Nothing\r\n }\r\n }\r\n }\r\n return supported;\r\n}\r\n/**\r\n * Enable the lookup of test mock objects if requested\r\n * @param enabled\r\n */\r\nexport function setEnableEnvMocks(enabled) {\r\n _enableMocks = enabled;\r\n}\r\n// /**\r\n// * Return the named global object if available, will return null if the object is not available.\r\n// * @param name The globally named object\r\n// */\r\n// export function getinst<T>(name:string): T {\r\n// let gbl = getGlobal();\r\n// if (gbl && gbl[name]) {\r\n// return gbl[name] as T;\r\n// }\r\n// // Test workaround, for environments where <global>.window (when global == window) doesn't return the base window\r\n// if (name === strWindow && hasWindow()) {\r\n// // tslint:disable-next-line: no-angle-bracket-type-assertion\r\n// return <any>window as T;\r\n// }\r\n// return null;\r\n// }\r\n// /**\r\n// * Checks if window object is available, this is required as we support the API running without a\r\n// * window /document (eg. Node server, electron webworkers) and if we attempt to assign a window\r\n// * object to a local variable or pass as an argument an \"Uncaught ReferenceError: window is not defined\"\r\n// * exception will be thrown.\r\n// * Defined as a function to support lazy / late binding environments.\r\n// */\r\n// export const hasWindow = () => boolean = hasWindow;\r\n// return Boolean(typeof window === strShimObject && window);\r\n// }\r\n// /**\r\n// * Returns the global window object if it is present otherwise null.\r\n// * This helper is used to access the window object without causing an exception\r\n// * \"Uncaught ReferenceError: window is not defined\"\r\n// */\r\n// export function getWindow(): Window | null {\r\n// if (hasWindow()) {\r\n// return window;\r\n// }\r\n// // Return the global instance or null\r\n// return getInst(strWindow);\r\n// }\r\n// /**\r\n// * Checks if document object is available, this is required as we support the API running without a\r\n// * window /document (eg. Node server, electron webworkers) and if we attempt to assign a document\r\n// * object to a local variable or pass as an argument an \"Uncaught ReferenceError: document is not defined\"\r\n// * exception will be thrown.\r\n// * Defined as a function to support lazy / late binding environments.\r\n// */\r\n// export function hasDocument(): boolean {\r\n// return Boolean(typeof document === strShimObject && document);\r\n// }\r\n// /**\r\n// * Returns the global document object if it is present otherwise null.\r\n// * This helper is used to access the document object without causing an exception\r\n// * \"Uncaught ReferenceError: document is not defined\"\r\n// */\r\n// export function getDocument(): Document | null {\r\n// if (hasDocument()) {\r\n// return document;\r\n// }\r\n// return getInst(strDocument);\r\n// }\r\n// /**\r\n// * Checks if navigator object is available, this is required as we support the API running without a\r\n// * window /document (eg. Node server, electron webworkers) and if we attempt to assign a navigator\r\n// * object to a local variable or pass as an argument an \"Uncaught ReferenceError: navigator is not defined\"\r\n// * exception will be thrown.\r\n// * Defined as a function to support lazy / late binding environments.\r\n// */\r\n// export function hasNavigator(): boolean {\r\n// return Boolean(typeof navigator === strShimObject && navigator);\r\n// }\r\n// /**\r\n// * Returns the global navigator object if it is present otherwise null.\r\n// * This helper is used to access the navigator object without causing an exception\r\n// * \"Uncaught ReferenceError: navigator is not defined\"\r\n// */\r\n// export function getNavigator(): Navigator | null {\r\n// if (hasNavigator()) {\r\n// return navigator;\r\n// }\r\n// return getInst(strNavigator);\r\n// }\r\n// /**\r\n// * Checks if history object is available, this is required as we support the API running without a\r\n// * window /document (eg. Node server, electron webworkers) and if we attempt to assign a history\r\n// * object to a local variable or pass as an argument an \"Uncaught ReferenceError: history is not defined\"\r\n// * exception will be thrown.\r\n// * Defined as a function to support lazy / late binding environments.\r\n// */\r\n// export function hasHistory(): boolean {\r\n// return Boolean(typeof history === strShimObject && history);\r\n// }\r\n// /**\r\n// * Returns the global history object if it is present otherwise null.\r\n// * This helper is used to access the history object without causing an exception\r\n// * \"Uncaught ReferenceError: history is not defined\"\r\n// */\r\n// export function getHistory(): History | null {\r\n// if (hasHistory()) {\r\n// return history;\r\n// }\r\n// return getInst(strHistory);\r\n// }\r\n/**\r\n * Returns the global location object if it is present otherwise null.\r\n * This helper is used to access the location object without causing an exception\r\n * \"Uncaught ReferenceError: location is not defined\"\r\n */\r\nexport function getLocation(checkForMock) {\r\n if (checkForMock && _enableMocks) {\r\n var mockLocation = getInst(\"__mockLocation\");\r\n if (mockLocation) {\r\n return mockLocation;\r\n }\r\n }\r\n if (typeof location === strShimObject && location) {\r\n return location;\r\n }\r\n return getInst(strLocation);\r\n}\r\n/**\r\n * Returns the global console object\r\n */\r\nexport function getConsole() {\r\n if (typeof console !== strShimUndefined) {\r\n return console;\r\n }\r\n return getInst(strConsole);\r\n}\r\n/**\r\n * Returns the performance object if it is present otherwise null.\r\n * This helper is used to access the performance object from the current\r\n * global instance which could be window or globalThis for a web worker\r\n */\r\nexport function getPerformance() {\r\n return getInst(strPerformance);\r\n}\r\n/**\r\n * Checks if JSON object is available, this is required as we support the API running without a\r\n * window /document (eg. Node server, electron webworkers) and if we attempt to assign a history\r\n * object to a local variable or pass as an argument an \"Uncaught ReferenceError: JSON is not defined\"\r\n * exception will be thrown.\r\n * Defined as a function to support lazy / late binding environments.\r\n */\r\nexport function hasJSON() {\r\n return Boolean((typeof JSON === strShimObject && JSON) || getInst(strJSON) !== null);\r\n}\r\n/**\r\n * Returns the global JSON object if it is present otherwise null.\r\n * This helper is used to access the JSON object without causing an exception\r\n * \"Uncaught ReferenceError: JSON is not defined\"\r\n */\r\nexport function getJSON() {\r\n if (hasJSON()) {\r\n return JSON || getInst(strJSON);\r\n }\r\n return null;\r\n}\r\n/**\r\n * Returns the crypto object if it is present otherwise null.\r\n * This helper is used to access the crypto object from the current\r\n * global instance which could be window or globalThis for a web worker\r\n */\r\nexport function getCrypto() {\r\n return getInst(strCrypto);\r\n}\r\n/**\r\n * Returns the crypto object if it is present otherwise null.\r\n * This helper is used to access the crypto object from the current\r\n * global instance which could be window or globalThis for a web worker\r\n */\r\nexport function getMsCrypto() {\r\n return getInst(strMsCrypto);\r\n}\r\n/**\r\n * Returns whether the environment is reporting that we are running in a React Native Environment\r\n */\r\nexport function isReactNative() {\r\n // If running in React Native, navigator.product will be populated\r\n var nav = getNavigator();\r\n if (nav && nav.product) {\r\n return nav.product === strReactNative;\r\n }\r\n return false;\r\n}\r\n/**\r\n * Identifies whether the current environment appears to be IE\r\n */\r\nexport function isIE() {\r\n var nav = getNavigator();\r\n if (nav && (nav[_DYN_USER_AGENT /* @min:%2euserAgent */] !== _navUserAgentCheck || _isTrident === null)) {\r\n // Added to support test mocking of the user agent\r\n _navUserAgentCheck = nav[_DYN_USER_AGENT /* @min:%2euserAgent */];\r\n var userAgent = (_navUserAgentCheck || STR_EMPTY)[_DYN_TO_LOWER_CASE /* @min:%2etoLowerCase */]();\r\n _isTrident = (strContains(userAgent, strMsie) || strContains(userAgent, strTrident));\r\n }\r\n return _isTrident;\r\n}\r\n/**\r\n * Gets IE version returning the document emulation mode if we are running on IE, or null otherwise\r\n */\r\nexport function getIEVersion(userAgentStr) {\r\n if (userAgentStr === void 0) { userAgentStr = null; }\r\n if (!userAgentStr) {\r\n var navigator_1 = getNavigator() || {};\r\n userAgentStr = navigator_1 ? (navigator_1[_DYN_USER_AGENT /* @min:%2euserAgent */] || STR_EMPTY)[_DYN_TO_LOWER_CASE /* @min:%2etoLowerCase */]() : STR_EMPTY;\r\n }\r\n var ua = (userAgentStr || STR_EMPTY)[_DYN_TO_LOWER_CASE /* @min:%2etoLowerCase */]();\r\n // Also check for documentMode in case X-UA-Compatible meta tag was included in HTML.\r\n if (strContains(ua, strMsie)) {\r\n var doc = getDocument() || {};\r\n return Math.max(parseInt(ua[_DYN_SPLIT /* @min:%2esplit */](strMsie)[1]), (doc[strDocumentMode] || 0));\r\n }\r\n else if (strContains(ua, strTrident)) {\r\n var tridentVer = parseInt(ua[_DYN_SPLIT /* @min:%2esplit */](strTrident)[1]);\r\n if (tridentVer) {\r\n return tridentVer + 4;\r\n }\r\n }\r\n return null;\r\n}\r\n// /**\r\n// * Returns string representation of an object suitable for diagnostics logging.\r\n// */\r\n// export function dumpObj(object: any): string {\r\n// const objectTypeDump: string = Object[strShimPrototype].toString.call(object);\r\n// let propertyValueDump: string = STR_EMPTY;\r\n// if (objectTypeDump === \"[object Error]\") {\r\n// propertyValueDump = \"{ stack: '\" + object.stack + \"', message: '\" + object.message + \"', name: '\" + object.name + \"'\";\r\n// } else if (hasJSON()) {\r\n// propertyValueDump = getJSON().stringify(object);\r\n// }\r\n// return objectTypeDump + propertyValueDump;\r\n// }\r\nexport function isSafari(userAgentStr) {\r\n if (!userAgentStr || !isString(userAgentStr)) {\r\n var navigator_2 = getNavigator() || {};\r\n userAgentStr = navigator_2 ? (navigator_2[_DYN_USER_AGENT /* @min:%2euserAgent */] || STR_EMPTY)[_DYN_TO_LOWER_CASE /* @min:%2etoLowerCase */]() : STR_EMPTY;\r\n }\r\n var ua = (userAgentStr || STR_EMPTY)[_DYN_TO_LOWER_CASE /* @min:%2etoLowerCase */]();\r\n return (ua.indexOf(\"safari\") >= 0);\r\n}\r\n/**\r\n * Checks if HTML5 Beacons are supported in the current environment.\r\n * @returns True if supported, false otherwise.\r\n */\r\nexport function isBeaconsSupported() {\r\n if (_beaconsSupported === null) {\r\n _beaconsSupported = hasNavigator() && Boolean(getNavigator().sendBeacon);\r\n }\r\n return _beaconsSupported;\r\n}\r\n/**\r\n * Checks if the Fetch API is supported in the current environment.\r\n * @param withKeepAlive - [Optional] If True, check if fetch is available and it supports the keepalive feature, otherwise only check if fetch is supported\r\n * @returns True if supported, otherwise false\r\n */\r\nexport function isFetchSupported(withKeepAlive) {\r\n var isSupported = false;\r\n try {\r\n isSupported = !!getInst(\"fetch\");\r\n var request = getInst(\"Request\");\r\n if (isSupported && withKeepAlive && request) {\r\n isSupported = _hasProperty(request, \"keepalive\");\r\n }\r\n }\r\n catch (e) {\r\n // Just Swallow any failure during availability checks\r\n }\r\n return isSupported;\r\n}\r\nexport function useXDomainRequest() {\r\n if (_useXDomainRequest === null) {\r\n _useXDomainRequest = (typeof XDomainRequest !== strShimUndefined);\r\n if (_useXDomainRequest && isXhrSupported()) {\r\n _useXDomainRequest = _useXDomainRequest && !_hasProperty(getInst(strXMLHttpRequest), \"withCredentials\");\r\n }\r\n }\r\n return _useXDomainRequest;\r\n}\r\n/**\r\n * Checks if XMLHttpRequest is supported\r\n * @returns True if supported, otherwise false\r\n */\r\nexport function isXhrSupported() {\r\n var isSupported = false;\r\n try {\r\n var xmlHttpRequest = getInst(strXMLHttpRequest);\r\n isSupported = !!xmlHttpRequest;\r\n }\r\n catch (e) {\r\n // Just Swallow any failure during availability checks\r\n }\r\n return isSupported;\r\n}\r\nfunction _getNamedValue(values, name) {\r\n if (values) {\r\n for (var i = 0; i < values[_DYN_LENGTH /* @min:%2elength */]; i++) {\r\n var value = values[i];\r\n if (value[_DYN_NAME /* @min:%2ename */]) {\r\n if (value[_DYN_NAME /* @min:%2ename */] === name) {\r\n return value;\r\n }\r\n }\r\n }\r\n }\r\n return {};\r\n}\r\n/**\r\n * Helper function to fetch the named meta-tag from the page.\r\n * @param name\r\n */\r\nexport function findMetaTag(name) {\r\n var doc = getDocument();\r\n if (doc && name) {\r\n // Look for a meta-tag\r\n return _getNamedValue(doc.querySelectorAll(\"meta\"), name).content;\r\n }\r\n return null;\r\n}\r\n/**\r\n * Helper function to fetch the named server timing value from the page response (first navigation event).\r\n * @param name\r\n */\r\nexport function findNamedServerTiming(name) {\r\n var value;\r\n var perf = getPerformance();\r\n if (perf) {\r\n // Try looking for a server-timing header\r\n var navPerf = perf.getEntriesByType(\"navigation\") || [];\r\n value = _getNamedValue((navPerf[_DYN_LENGTH /* @min:%2elength */] > 0 ? navPerf[0] : {}).serverTiming, name).description;\r\n }\r\n return value;\r\n}\r\n//# sourceMappingURL=EnvUtils.js.map"],"names":[],"mappings":";;;;AAA4D;AAC1B;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA"}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Application Insights JavaScript SDK - Core, 3.0.0-beta.2208-
|
|
2
|
+
* Application Insights JavaScript SDK - Core, 3.0.0-beta.2208-16
|
|
3
3
|
* Copyright (c) Microsoft and contributors. All rights reserved.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
|
|
7
|
+
import { arrForEach, arrIndexOf, getDocument, getWindow, isArray, objForEachKey, objKeys } from "@nevware21/ts-utils";
|
|
7
8
|
import { _DYN_HANDLER, _DYN_LENGTH, _DYN_NAME, _DYN_PUSH, _DYN_REPLACE, _DYN_SPLICE, _DYN_SPLIT, _DYN_TYPE } from "../__DynamicConstants";
|
|
8
9
|
import { createElmNodeData, createUniqueNamespace } from "./DataCacheHelper";
|
|
9
|
-
import { getDocument, getWindow } from "./EnvUtils";
|
|
10
|
-
import { arrForEach, arrIndexOf, isArray, objForEachKey, objKeys } from "./HelperFuncs";
|
|
11
10
|
import { STR_EMPTY } from "./InternalConstants";
|
|
12
11
|
// Added to help with minfication
|
|
13
12
|
var strOnPrefix = "on";
|