@microsoft/applicationinsights-web-basic 2.8.0-beta.2203-03 → 2.8.0-beta.2203-06

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.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Application Insights JavaScript Web SDK - Basic, 2.8.0-beta.2203-03
2
+ * Application Insights JavaScript Web SDK - Basic, 2.8.0-beta.2203-06
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
  (function (global, factory) {
@@ -357,6 +357,7 @@
357
357
  var strIsInitialized = "isInitialized";
358
358
  var strTeardown = "teardown";
359
359
  var strCore = "core";
360
+ var strUpdate = "update";
360
361
  var strDisabled = "disabled";
361
362
  var strDoTeardown = "_doTeardown";
362
363
  var strProcessNext = "processNext";
@@ -798,7 +799,7 @@
798
799
  }
799
800
  return theObject;
800
801
  }
801
- function objExtend(obj, obj2, obj3, obj4, obj5, obj6) {
802
+ function objExtend(obj1, obj2, obj3, obj4, obj5, obj6) {
802
803
  var theArgs = arguments;
803
804
  var extended = theArgs[0] || {};
804
805
  var argLen = theArgs.length;
@@ -1227,6 +1228,10 @@
1227
1228
  }
1228
1229
  return DiagnosticLogger;
1229
1230
  }());
1231
+ function _throwInternal(logger, severity, msgId, msg, properties, isUserAct) {
1232
+ if (isUserAct === void 0) { isUserAct = false; }
1233
+ (logger || new DiagnosticLogger()).throwInternal(severity, msgId, msg, properties, isUserAct);
1234
+ }
1230
1235
 
1231
1236
  var strExecutionContextKey = "ctx";
1232
1237
  var _defaultPerfManager = null;
@@ -1651,7 +1656,7 @@
1651
1656
  completeDetails.func.call(completeDetails.self, completeDetails.args);
1652
1657
  }
1653
1658
  catch (e) {
1654
- core.logger.throwInternal(2 , 73 , "Unexpected Exception during onComplete - " + dumpObj(e));
1659
+ _throwInternal(core.logger, 2 , 73 , "Unexpected Exception during onComplete - " + dumpObj(e));
1655
1660
  }
1656
1661
  });
1657
1662
  _onComplete = [];
@@ -1750,6 +1755,27 @@
1750
1755
  context.createNew = _createNew;
1751
1756
  return context;
1752
1757
  }
1758
+ function createProcessTelemetryUpdateContext(telemetryChain, config, core, startAt) {
1759
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1760
+ var context = internalContext.ctx;
1761
+ function _processNext(updateState) {
1762
+ return context.iterate(function (plugin) {
1763
+ if (isFunction(plugin[strUpdate])) {
1764
+ plugin[strUpdate](context, updateState);
1765
+ }
1766
+ });
1767
+ }
1768
+ function _createNew(plugins, startAt) {
1769
+ if (plugins === void 0) { plugins = null; }
1770
+ if (isArray(plugins)) {
1771
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1772
+ }
1773
+ return createProcessTelemetryUpdateContext(plugins || context.getNext(), config, core, startAt);
1774
+ }
1775
+ context.processNext = _processNext;
1776
+ context.createNew = _createNew;
1777
+ return context;
1778
+ }
1753
1779
  function createTelemetryProxyChain(plugins, config, core, startAt) {
1754
1780
  var firstProxy = null;
1755
1781
  var add = startAt ? false : true;
@@ -1796,6 +1822,7 @@
1796
1822
  },
1797
1823
  processTelemetry: _processTelemetry,
1798
1824
  unload: _unloadPlugin,
1825
+ update: _updatePlugin,
1799
1826
  _id: chainId,
1800
1827
  _setNext: function (nextPlugin) {
1801
1828
  nextProxy = nextPlugin;
@@ -1835,7 +1862,7 @@
1835
1862
  hasRun = true;
1836
1863
  }
1837
1864
  if (!nextProxy || !hasNextRun) {
1838
- itemCtx.diagLog().throwInternal(1 , 73 , "Plugin [" + plugin.identifier + "] failed during " + name + " - " + dumpObj(error) + ", run flags: " + dumpObj(hasRunContext));
1865
+ _throwInternal(itemCtx.diagLog(), 1 , 73 , "Plugin [" + plugin.identifier + "] failed during " + name + " - " + dumpObj(error) + ", run flags: " + dumpObj(hasRunContext));
1839
1866
  }
1840
1867
  }
1841
1868
  }, details, isAsync);
@@ -1883,6 +1910,24 @@
1883
1910
  unloadCtx.processNext(unloadState);
1884
1911
  }
1885
1912
  }
1913
+ function _updatePlugin(updateCtx, updateState) {
1914
+ function _callUpdate() {
1915
+ var hasRun = false;
1916
+ if (plugin) {
1917
+ var pluginState = _getPluginState(plugin);
1918
+ var pluginCore = plugin[strCore] || pluginState.core;
1919
+ if (plugin && (!pluginCore || pluginCore === updateCtx[strCore]()) && !pluginState[strTeardown]) {
1920
+ if (plugin[strUpdate] && plugin[strUpdate](updateCtx, updateState) === true) {
1921
+ hasRun = true;
1922
+ }
1923
+ }
1924
+ }
1925
+ return hasRun;
1926
+ }
1927
+ if (!_processChain(updateCtx, _callUpdate, "update", function () { }, false)) {
1928
+ updateCtx.processNext(updateState);
1929
+ }
1930
+ }
1886
1931
  return objFreeze(proxyChain);
1887
1932
  }
1888
1933
 
@@ -2033,7 +2078,7 @@
2033
2078
  _supportsCookies = doc[strCookie] !== undefined;
2034
2079
  }
2035
2080
  catch (e) {
2036
- logger && logger.throwInternal(2 , 68 , "Cannot access document.cookie - " + getExceptionName(e), { exception: dumpObj(e) });
2081
+ _throwInternal(logger, 2 , 68 , "Cannot access document.cookie - " + getExceptionName(e), { exception: dumpObj(e) });
2037
2082
  }
2038
2083
  }
2039
2084
  return _supportsCookies;
@@ -2162,6 +2207,17 @@
2162
2207
  }
2163
2208
  _runChainOnComplete();
2164
2209
  }
2210
+ function _doUpdate(updateCtx, updateState) {
2211
+ var theUpdateState = updateState || {
2212
+ reason: 0
2213
+ };
2214
+ _processChannelQueue(channelQueue, updateCtx, function (chainCtx) {
2215
+ chainCtx[strProcessNext](theUpdateState);
2216
+ }, function () {
2217
+ updateCtx[strProcessNext](theUpdateState);
2218
+ });
2219
+ return true;
2220
+ }
2165
2221
  function _doTeardown(unloadCtx, unloadState) {
2166
2222
  var theUnloadState = unloadState || {
2167
2223
  reason: 0 ,
@@ -2213,7 +2269,8 @@
2213
2269
  }, function () {
2214
2270
  itemCtx[strProcessNext](item);
2215
2271
  });
2216
- }
2272
+ },
2273
+ update: _doUpdate
2217
2274
  },
2218
2275
  _a[strPause] = function () {
2219
2276
  _processChannelQueue(channelQueue, _getTelCtx(), function (chainCtx) {
@@ -2311,7 +2368,7 @@
2311
2368
  handler(unloadCtx, unloadState);
2312
2369
  }
2313
2370
  catch (e) {
2314
- unloadCtx.diagLog().throwInternal(2 , 73 , "Unexpected error calling unload handler - " + dumpObj(e));
2371
+ _throwInternal(unloadCtx.diagLog(), 2 , 73 , "Unexpected error calling unload handler - " + dumpObj(e));
2315
2372
  }
2316
2373
  });
2317
2374
  handlers = [];
@@ -2370,6 +2427,30 @@
2370
2427
  }
2371
2428
  return result;
2372
2429
  };
2430
+ _self.update = function (updateCtx, updateState) {
2431
+ if (!_self.core || (updateCtx && _self.core !== updateCtx.core())) {
2432
+ return;
2433
+ }
2434
+ var result;
2435
+ var updateDone = false;
2436
+ var theUpdateCtx = updateCtx || createProcessTelemetryUpdateContext(null, {}, _self.core, _nextPlugin && _nextPlugin[strGetPlugin] ? _nextPlugin[strGetPlugin]() : _nextPlugin);
2437
+ var theUpdateState = updateState || {
2438
+ reason: 0
2439
+ };
2440
+ function _updateCallback() {
2441
+ if (!updateDone) {
2442
+ updateDone = true;
2443
+ _setDefaults(theUpdateCtx.getCfg(), theUpdateCtx.core(), theUpdateCtx.getNext());
2444
+ }
2445
+ }
2446
+ if (!_self._doUpdate || _self._doUpdate(theUpdateCtx, theUpdateState, _updateCallback) !== true) {
2447
+ _updateCallback();
2448
+ }
2449
+ else {
2450
+ result = true;
2451
+ }
2452
+ return result;
2453
+ };
2373
2454
  _self._addHook = function (hooks) {
2374
2455
  if (hooks) {
2375
2456
  if (isArray(hooks)) {
@@ -2484,7 +2565,7 @@
2484
2565
  }
2485
2566
  }
2486
2567
  catch (e) {
2487
- itemCtx.diagLog().throwInternal(1 , 64 , "One of telemetry initializers failed, telemetry item will not be sent: " + getExceptionName(e), { exception: dumpObj(e) }, true);
2568
+ _throwInternal(itemCtx.diagLog(), 1 , 64 , "One of telemetry initializers failed, telemetry item will not be sent: " + getExceptionName(e), { exception: dumpObj(e) }, true);
2488
2569
  }
2489
2570
  }
2490
2571
  }
@@ -2605,7 +2686,7 @@
2605
2686
  _configExtensions = [];
2606
2687
  _configExtensions.push.apply(_configExtensions, __spreadArrayFn(__spreadArrayFn([], extensions, false), config.extensions));
2607
2688
  _channelConfig = (config || {}).channels;
2608
- _initPluginChain(config);
2689
+ _initPluginChain(config, null);
2609
2690
  if (_self.getTransmissionControls().length === 0) {
2610
2691
  throwError("No channels available");
2611
2692
  }
@@ -2748,22 +2829,28 @@
2748
2829
  _logOrThrowError("Plugin [" + plugin.identifier + "] is already loaded!");
2749
2830
  return;
2750
2831
  }
2832
+ var updateState = {
2833
+ reason: 16
2834
+ };
2751
2835
  function _addPlugin(removed) {
2752
2836
  _configExtensions.push(plugin);
2753
- _initPluginChain(_self.config);
2837
+ updateState.added = [plugin];
2838
+ _initPluginChain(_self.config, updateState);
2754
2839
  addCb && addCb(true);
2755
2840
  }
2756
2841
  if (existingPlugin) {
2757
- var removedPlugins = [existingPlugin.plugin];
2842
+ var removedPlugins_1 = [existingPlugin.plugin];
2758
2843
  var unloadState = {
2759
2844
  reason: 2 ,
2760
2845
  isAsync: isAsync
2761
2846
  };
2762
- _removePlugins(removedPlugins, unloadState, function (removed) {
2847
+ _removePlugins(removedPlugins_1, unloadState, function (removed) {
2763
2848
  if (!removed) {
2764
2849
  addCb && addCb(false);
2765
2850
  }
2766
2851
  else {
2852
+ updateState.removed = removedPlugins_1;
2853
+ updateState.reason |= 32 ;
2767
2854
  _addPlugin();
2768
2855
  }
2769
2856
  });
@@ -2801,7 +2888,7 @@
2801
2888
  function _createTelCtx() {
2802
2889
  return createProcessTelemetryContext(_getPluginChain(), _self.config, _self);
2803
2890
  }
2804
- function _initPluginChain(config) {
2891
+ function _initPluginChain(config, updateState) {
2805
2892
  var theExtensions = _validateExtensions(_self.logger, ChannelControllerPriority, _configExtensions);
2806
2893
  _coreExtensions = theExtensions.core;
2807
2894
  _pluginChain = null;
@@ -2827,6 +2914,9 @@
2827
2914
  _channelControl.initialize(config, _self, allExtensions);
2828
2915
  initializePlugins(_createTelCtx(), allExtensions);
2829
2916
  _self._extensions = objFreeze(sortPlugins(_coreExtensions || [])).slice();
2917
+ if (updateState) {
2918
+ _doUpdate(updateState);
2919
+ }
2830
2920
  }
2831
2921
  function _getPlugin(pluginIdentifier) {
2832
2922
  var theExt = null;
@@ -2859,7 +2949,10 @@
2859
2949
  };
2860
2950
  _removePlugins(pluginsToRemove, unloadState, function (removed) {
2861
2951
  if (removed) {
2862
- _initPluginChain(_self.config);
2952
+ _initPluginChain(_self.config, {
2953
+ reason: 32 ,
2954
+ removed: pluginsToRemove
2955
+ });
2863
2956
  }
2864
2957
  removeCb && removeCb(removed);
2865
2958
  });
@@ -2956,10 +3049,16 @@
2956
3049
  var extConfig = getSetValue(config, strExtensionConfig);
2957
3050
  extConfig.NotificationManager = _notificationManager;
2958
3051
  }
3052
+ function _doUpdate(updateState) {
3053
+ var updateCtx = createProcessTelemetryUpdateContext(_getPluginChain(), _self.config, _self);
3054
+ if (!_self._updateHook || _self._updateHook(updateCtx, updateState) !== true) {
3055
+ updateCtx.processNext(updateState);
3056
+ }
3057
+ }
2959
3058
  function _logOrThrowError(message) {
2960
3059
  var logger = _self.logger;
2961
3060
  if (logger) {
2962
- logger.throwInternal(2 , 73 , message);
3061
+ _throwInternal(logger, 2 , 73 , message);
2963
3062
  }
2964
3063
  else {
2965
3064
  throwError(message);
@@ -3074,6 +3173,8 @@
3074
3173
  var strOnPrefix = "on";
3075
3174
  var strAttachEvent = "attachEvent";
3076
3175
  var strAddEventHelper = "addEventListener";
3176
+ var strDetachEvent = "detachEvent";
3177
+ var strRemoveEventListener = "removeEventListener";
3077
3178
  var strEvents = "events";
3078
3179
  createUniqueNamespace("aiEvtPageHide");
3079
3180
  createUniqueNamespace("aiEvtPageShow");
@@ -3086,12 +3187,12 @@
3086
3187
  }
3087
3188
  return name;
3088
3189
  }
3089
- function _getEvtNamespace(eventName, namespaces) {
3090
- if (namespaces) {
3190
+ function _getEvtNamespace(eventName, evtNamespace) {
3191
+ if (evtNamespace) {
3091
3192
  var theNamespace_1 = "";
3092
- if (isArray(namespaces)) {
3193
+ if (isArray(evtNamespace)) {
3093
3194
  theNamespace_1 = "";
3094
- arrForEach(namespaces, function (name) {
3195
+ arrForEach(evtNamespace, function (name) {
3095
3196
  name = _normalizeNamespace(name);
3096
3197
  if (name) {
3097
3198
  if (name[0] !== ".") {
@@ -3102,7 +3203,7 @@
3102
3203
  });
3103
3204
  }
3104
3205
  else {
3105
- theNamespace_1 = _normalizeNamespace(namespaces);
3206
+ theNamespace_1 = _normalizeNamespace(evtNamespace);
3106
3207
  }
3107
3208
  if (theNamespace_1) {
3108
3209
  if (theNamespace_1[0] !== ".") {
@@ -3126,6 +3227,16 @@
3126
3227
  }
3127
3228
  return registeredEvents;
3128
3229
  }
3230
+ function _doDetach(obj, evtName, handlerRef, useCapture) {
3231
+ if (obj && evtName && evtName.type) {
3232
+ if (obj[strRemoveEventListener]) {
3233
+ obj[strRemoveEventListener](evtName.type, handlerRef, useCapture);
3234
+ }
3235
+ else if (obj[strDetachEvent]) {
3236
+ obj[strDetachEvent](strOnPrefix + evtName.type, handlerRef);
3237
+ }
3238
+ }
3239
+ }
3129
3240
  function _doAttach(obj, evtName, handlerRef, useCapture) {
3130
3241
  var result = false;
3131
3242
  if (obj && evtName && evtName.type && handlerRef) {
@@ -3140,6 +3251,49 @@
3140
3251
  }
3141
3252
  return result;
3142
3253
  }
3254
+ function _doUnregister(target, events, evtName, unRegFn) {
3255
+ var idx = events.length;
3256
+ while (idx--) {
3257
+ var theEvent = events[idx];
3258
+ if (theEvent) {
3259
+ if (!evtName.ns || evtName.ns === theEvent.evtName.ns) {
3260
+ if (!unRegFn || unRegFn(theEvent)) {
3261
+ _doDetach(target, theEvent.evtName, theEvent.handler, theEvent.capture);
3262
+ events.splice(idx, 1);
3263
+ }
3264
+ }
3265
+ }
3266
+ }
3267
+ }
3268
+ function _unregisterEvents(target, evtName, unRegFn) {
3269
+ if (evtName.type) {
3270
+ _doUnregister(target, _getRegisteredEvents(target, evtName.type), evtName, unRegFn);
3271
+ }
3272
+ else {
3273
+ var eventCache = elmNodeData.get(target, strEvents, {});
3274
+ objForEachKey(eventCache, function (evtType, events) {
3275
+ _doUnregister(target, events, evtName, unRegFn);
3276
+ });
3277
+ if (objKeys(eventCache).length === 0) {
3278
+ elmNodeData.kill(target, strEvents);
3279
+ }
3280
+ }
3281
+ }
3282
+ function mergeEvtNamespace(theNamespace, namespaces) {
3283
+ var newNamespaces;
3284
+ if (namespaces) {
3285
+ if (isArray(namespaces)) {
3286
+ newNamespaces = [theNamespace].concat(namespaces);
3287
+ }
3288
+ else {
3289
+ newNamespaces = [theNamespace, namespaces];
3290
+ }
3291
+ }
3292
+ else {
3293
+ newNamespaces = theNamespace;
3294
+ }
3295
+ return newNamespaces;
3296
+ }
3143
3297
  function eventOn(target, eventName, handlerRef, evtNamespace, useCapture) {
3144
3298
  if (useCapture === void 0) { useCapture = false; }
3145
3299
  var result = false;
@@ -3162,9 +3316,26 @@
3162
3316
  }
3163
3317
  return result;
3164
3318
  }
3165
- function attachEvent(obj, eventNameWithoutOn, handlerRef, useCapture) {
3319
+ function eventOff(target, eventName, handlerRef, evtNamespace, useCapture) {
3166
3320
  if (useCapture === void 0) { useCapture = false; }
3167
- return eventOn(obj, eventNameWithoutOn, handlerRef, null, useCapture);
3321
+ if (target) {
3322
+ try {
3323
+ var evtName_1 = _getEvtNamespace(eventName, evtNamespace);
3324
+ var found_1 = false;
3325
+ _unregisterEvents(target, evtName_1, function (regEvent) {
3326
+ if ((evtName_1.ns && !handlerRef) || regEvent.handler === handlerRef) {
3327
+ found_1 = true;
3328
+ return true;
3329
+ }
3330
+ return false;
3331
+ });
3332
+ if (!found_1) {
3333
+ _doDetach(target, evtName_1, handlerRef, useCapture);
3334
+ }
3335
+ }
3336
+ catch (e) {
3337
+ }
3338
+ }
3168
3339
  }
3169
3340
  function addEventHandler(eventName, callback, evtNamespace) {
3170
3341
  var result = false;
@@ -3404,7 +3575,7 @@
3404
3575
  name = strTrim(name.toString());
3405
3576
  if (name.length > 150 ) {
3406
3577
  nameTrunc = name.substring(0, 150 );
3407
- logger && logger.throwInternal(2 , _InternalMessageId.NameTooLong, "name is too long. It has been truncated to " + 150 + " characters.", { name: name }, true);
3578
+ _throwInternal(logger, 2 , _InternalMessageId.NameTooLong, "name is too long. It has been truncated to " + 150 + " characters.", { name: name }, true);
3408
3579
  }
3409
3580
  }
3410
3581
  return nameTrunc || name;
@@ -3417,7 +3588,7 @@
3417
3588
  value = strTrim(value);
3418
3589
  if (value.toString().length > maxLength) {
3419
3590
  valueTrunc = value.toString().substring(0, maxLength);
3420
- logger && logger.throwInternal(2 , _InternalMessageId.StringValueTooLong, "string value is too long. It has been truncated to " + maxLength + " characters.", { value: value }, true);
3591
+ _throwInternal(logger, 2 , _InternalMessageId.StringValueTooLong, "string value is too long. It has been truncated to " + maxLength + " characters.", { value: value }, true);
3421
3592
  }
3422
3593
  }
3423
3594
  return valueTrunc || value;
@@ -3430,7 +3601,7 @@
3430
3601
  if (message) {
3431
3602
  if (message.length > 32768 ) {
3432
3603
  messageTrunc = message.substring(0, 32768 );
3433
- logger && logger.throwInternal(2 , _InternalMessageId.MessageTruncated, "message is too long, it has been truncated to " + 32768 + " characters.", { message: message }, true);
3604
+ _throwInternal(logger, 2 , _InternalMessageId.MessageTruncated, "message is too long, it has been truncated to " + 32768 + " characters.", { message: message }, true);
3434
3605
  }
3435
3606
  }
3436
3607
  return messageTrunc || message;
@@ -3441,7 +3612,7 @@
3441
3612
  var value = "" + exception;
3442
3613
  if (value.length > 32768 ) {
3443
3614
  exceptionTrunc = value.substring(0, 32768 );
3444
- logger && logger.throwInternal(2 , _InternalMessageId.ExceptionTruncated, "exception is too long, it has been truncated to " + 32768 + " characters.", { exception: exception }, true);
3615
+ _throwInternal(logger, 2 , _InternalMessageId.ExceptionTruncated, "exception is too long, it has been truncated to " + 32768 + " characters.", { exception: exception }, true);
3445
3616
  }
3446
3617
  }
3447
3618
  return exceptionTrunc || exception;
@@ -3455,7 +3626,7 @@
3455
3626
  value = getJSON().stringify(value);
3456
3627
  }
3457
3628
  catch (e) {
3458
- logger && logger.throwInternal(2 , _InternalMessageId.CannotSerializeObjectNonSerializable, "custom property is not valid", { exception: e }, true);
3629
+ _throwInternal(logger, 2 , _InternalMessageId.CannotSerializeObjectNonSerializable, "custom property is not valid", { exception: e }, true);
3459
3630
  }
3460
3631
  }
3461
3632
  value = dataSanitizeString(logger, value, 8192 );
@@ -3486,7 +3657,7 @@
3486
3657
  input = strTrim(input);
3487
3658
  if (input.length > maxLength) {
3488
3659
  inputTrunc = input.substring(0, maxLength);
3489
- logger && logger.throwInternal(2 , _msgId, "input is too long, it has been truncated to " + maxLength + " characters.", { data: input }, true);
3660
+ _throwInternal(logger, 2 , _msgId, "input is too long, it has been truncated to " + maxLength + " characters.", { data: input }, true);
3490
3661
  }
3491
3662
  }
3492
3663
  return inputTrunc || input;
@@ -3555,8 +3726,8 @@
3555
3726
  }
3556
3727
  return null;
3557
3728
  }
3558
- function utlCanUseSessionStorage() {
3559
- if (_canUseSessionStorage === undefined) {
3729
+ function utlCanUseSessionStorage(reset) {
3730
+ if (reset || _canUseSessionStorage === undefined) {
3560
3731
  _canUseSessionStorage = !!_getVerifiedStorageObject(StorageType.SessionStorage);
3561
3732
  }
3562
3733
  return _canUseSessionStorage;
@@ -3569,7 +3740,7 @@
3569
3740
  }
3570
3741
  catch (e) {
3571
3742
  _canUseSessionStorage = false;
3572
- logger.throwInternal(2 , _InternalMessageId.BrowserCannotReadSessionStorage, "Browser failed read of session storage. " + getExceptionName(e), { exception: dumpObj(e) });
3743
+ _throwInternal(logger, 2 , _InternalMessageId.BrowserCannotReadSessionStorage, "Browser failed read of session storage. " + getExceptionName(e), { exception: dumpObj(e) });
3573
3744
  }
3574
3745
  }
3575
3746
  return null;
@@ -3583,7 +3754,7 @@
3583
3754
  }
3584
3755
  catch (e) {
3585
3756
  _canUseSessionStorage = false;
3586
- logger.throwInternal(2 , _InternalMessageId.BrowserCannotWriteSessionStorage, "Browser failed write to session storage. " + getExceptionName(e), { exception: dumpObj(e) });
3757
+ _throwInternal(logger, 2 , _InternalMessageId.BrowserCannotWriteSessionStorage, "Browser failed write to session storage. " + getExceptionName(e), { exception: dumpObj(e) });
3587
3758
  }
3588
3759
  }
3589
3760
  return false;
@@ -4869,7 +5040,7 @@
4869
5040
  }
4870
5041
  }
4871
5042
  var EnvelopeCreator = {
4872
- Version: "2.8.0-beta.2203-03"
5043
+ Version: "2.8.0-beta.2203-06"
4873
5044
  };
4874
5045
  function DependencyEnvelopeCreator(logger, telemetryItem, customUndefinedValue) {
4875
5046
  EnvelopeCreatorInit(logger, telemetryItem);
@@ -5164,65 +5335,81 @@
5164
5335
  return Serializer;
5165
5336
  }());
5166
5337
 
5167
- var OfflineListener = /** @class */ (function () {
5168
- function OfflineListener() {
5169
- var _window = getWindow();
5170
- var _document = getDocument();
5171
- var isListening = false;
5172
- var _onlineStatus = true;
5173
- dynamicProto(OfflineListener, this, function (_self) {
5174
- try {
5175
- if (_window) {
5176
- if (attachEvent(_window, "online", _setOnline)) {
5177
- attachEvent(_window, "offline", _setOffline);
5178
- isListening = true;
5179
- }
5180
- }
5181
- if (_document) {
5182
- var target = _document.body || _document;
5183
- if (!isUndefined(target.ononline)) {
5184
- target.ononline = _setOnline;
5185
- target.onoffline = _setOffline;
5186
- isListening = true;
5187
- }
5188
- }
5189
- if (isListening) {
5190
- var _navigator = getNavigator();
5191
- if (_navigator && !isNullOrUndefined(_navigator.onLine)) {
5192
- _onlineStatus = _navigator.onLine;
5193
- }
5338
+ function _disableEvents(target, evtNamespace) {
5339
+ eventOff(target, null, null, evtNamespace);
5340
+ }
5341
+ function createOfflineListener(parentEvtNamespace) {
5342
+ var _document = getDocument();
5343
+ var _navigator = getNavigator();
5344
+ var _isListening = false;
5345
+ var _onlineStatus = true;
5346
+ var _evtNamespace = mergeEvtNamespace(createUniqueNamespace("OfflineListener"), parentEvtNamespace);
5347
+ try {
5348
+ if (_enableEvents(getWindow())) {
5349
+ _isListening = true;
5350
+ }
5351
+ if (_document) {
5352
+ var target = _document.body || _document;
5353
+ if (target.ononline) {
5354
+ if (_enableEvents(target)) {
5355
+ _isListening = true;
5194
5356
  }
5195
5357
  }
5196
- catch (e) {
5197
- isListening = false;
5358
+ }
5359
+ if (_isListening) {
5360
+ if (_navigator && !isNullOrUndefined(_navigator.onLine)) {
5361
+ _onlineStatus = _navigator.onLine;
5198
5362
  }
5199
- _self.isListening = isListening;
5200
- _self.isOnline = function () {
5201
- var result = true;
5202
- var _navigator = getNavigator();
5203
- if (isListening) {
5204
- result = _onlineStatus;
5205
- }
5206
- else if (_navigator && !isNullOrUndefined(_navigator.onLine)) {
5207
- result = _navigator.onLine;
5208
- }
5209
- return result;
5210
- };
5211
- _self.isOffline = function () {
5212
- return !_self.isOnline();
5213
- };
5214
- function _setOnline() {
5215
- _onlineStatus = true;
5363
+ }
5364
+ }
5365
+ catch (e) {
5366
+ _isListening = false;
5367
+ }
5368
+ function _enableEvents(target) {
5369
+ var enabled = false;
5370
+ if (target) {
5371
+ enabled = eventOn(target, "online", _setOnline, _evtNamespace);
5372
+ if (enabled) {
5373
+ eventOn(target, "offline", _setOffline, _evtNamespace);
5216
5374
  }
5217
- function _setOffline() {
5218
- _onlineStatus = false;
5375
+ }
5376
+ return enabled;
5377
+ }
5378
+ function _setOnline() {
5379
+ _onlineStatus = true;
5380
+ }
5381
+ function _setOffline() {
5382
+ _onlineStatus = false;
5383
+ }
5384
+ function _isOnline() {
5385
+ var result = true;
5386
+ if (_isListening) {
5387
+ result = _onlineStatus;
5388
+ }
5389
+ else if (_navigator && !isNullOrUndefined(_navigator.onLine)) {
5390
+ result = _navigator.onLine;
5391
+ }
5392
+ return result;
5393
+ }
5394
+ function _unload() {
5395
+ var win = getWindow();
5396
+ if (win && _isListening) {
5397
+ _disableEvents(win, _evtNamespace);
5398
+ if (_document) {
5399
+ var target = _document.body || _document;
5400
+ if (!isUndefined(target.ononline)) {
5401
+ _disableEvents(target, _evtNamespace);
5402
+ }
5219
5403
  }
5220
- });
5404
+ _isListening = false;
5405
+ }
5221
5406
  }
5222
- OfflineListener.Offline = new OfflineListener;
5223
- return OfflineListener;
5224
- }());
5225
- var Offline = OfflineListener.Offline;
5407
+ return {
5408
+ isOnline: _isOnline,
5409
+ isListening: function () { return _isListening; },
5410
+ unload: _unload
5411
+ };
5412
+ }
5226
5413
 
5227
5414
  var MIN_INPUT_LENGTH = 8;
5228
5415
  var HashCodeScoreGenerator = /** @class */ (function () {
@@ -5350,22 +5537,22 @@
5350
5537
  var _this = _super.call(this) || this;
5351
5538
  _this.priority = 1001;
5352
5539
  _this.identifier = BreezeChannelIdentifier;
5540
+ _this._senderConfig = _getDefaultAppInsightsChannelConfig();
5353
5541
  var _consecutiveErrors;
5354
5542
  var _retryAt;
5355
5543
  var _lastSend;
5356
- var _paused = false;
5544
+ var _paused;
5357
5545
  var _timeoutHandle;
5358
5546
  var _serializer;
5359
5547
  var _stamp_specific_redirects;
5360
- var _headers = {};
5548
+ var _headers;
5361
5549
  var _syncFetchPayload = 0;
5362
5550
  var _fallbackSender;
5363
5551
  var _syncUnloadSender;
5364
- _this._senderConfig = _getDefaultAppInsightsChannelConfig();
5552
+ var _offlineListener;
5553
+ var _evtNamespace;
5365
5554
  dynamicProto(Sender, _this, function (_self, _base) {
5366
- function _notImplemented() {
5367
- throwError("Method not implemented.");
5368
- }
5555
+ _initDefaults();
5369
5556
  _self.pause = function () {
5370
5557
  _clearScheduledTimer();
5371
5558
  _paused = true;
@@ -5388,7 +5575,7 @@
5388
5575
  _self.triggerSend(isAsync, null, sendReason || 1 );
5389
5576
  }
5390
5577
  catch (e) {
5391
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.FlushFailed, "flush failed, telemetry will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
5578
+ _throwInternal(_self.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.FlushFailed, "flush failed, telemetry will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
5392
5579
  }
5393
5580
  }
5394
5581
  };
@@ -5399,7 +5586,7 @@
5399
5586
  _self.triggerSend(true, _doUnloadSend, 2 );
5400
5587
  }
5401
5588
  catch (e) {
5402
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.FailedToSendQueuedTelemetry, "failed to flush with beacon sender on page unload, telemetry will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
5589
+ _throwInternal(_self.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.FailedToSendQueuedTelemetry, "failed to flush with beacon sender on page unload, telemetry will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
5403
5590
  }
5404
5591
  }
5405
5592
  else {
@@ -5407,7 +5594,6 @@
5407
5594
  }
5408
5595
  }
5409
5596
  };
5410
- _self.teardown = _notImplemented;
5411
5597
  _self.addHeader = function (name, value) {
5412
5598
  _headers[name] = value;
5413
5599
  };
@@ -5422,6 +5608,8 @@
5422
5608
  _self._sender = null;
5423
5609
  _stamp_specific_redirects = 0;
5424
5610
  var diagLog = _self.diagLog();
5611
+ _evtNamespace = mergeEvtNamespace(createUniqueNamespace("Sender"), core.evtNamespace && core.evtNamespace());
5612
+ _offlineListener = createOfflineListener(_evtNamespace);
5425
5613
  var defaultConfig = _getDefaultAppInsightsChannelConfig();
5426
5614
  objForEachKey(defaultConfig, function (field, value) {
5427
5615
  _self._senderConfig[field] = function () { return ctx.getConfig(identifier, field, value()); };
@@ -5430,7 +5618,7 @@
5430
5618
  ? new SessionStorageSendBuffer(diagLog, _self._senderConfig) : new ArraySendBuffer(diagLog, _self._senderConfig);
5431
5619
  _self._sample = new Sample(_self._senderConfig.samplingPercentage(), diagLog);
5432
5620
  if (!_validateInstrumentationKey(config)) {
5433
- diagLog.throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.InvalidInstrumentationKey, "Invalid Instrumentation key " + config.instrumentationKey);
5621
+ _throwInternal(diagLog, LoggingSeverity.CRITICAL, _InternalMessageId.InvalidInstrumentationKey, "Invalid Instrumentation key " + config.instrumentationKey);
5434
5622
  }
5435
5623
  if (!isInternalApplicationInsightsEndpoint(_self._senderConfig.endpointUrl()) && _self._senderConfig.customHeaders() && _self._senderConfig.customHeaders().length > 0) {
5436
5624
  arrForEach(_self._senderConfig.customHeaders(), function (customHeader) {
@@ -5476,22 +5664,22 @@
5476
5664
  return;
5477
5665
  }
5478
5666
  if (!telemetryItem) {
5479
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.CannotSendEmptyTelemetry, "Cannot send empty telemetry");
5667
+ _throwInternal(itemCtx.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.CannotSendEmptyTelemetry, "Cannot send empty telemetry");
5480
5668
  return;
5481
5669
  }
5482
5670
  if (telemetryItem.baseData && !telemetryItem.baseType) {
5483
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.InvalidEvent, "Cannot send telemetry without baseData and baseType");
5671
+ _throwInternal(itemCtx.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.InvalidEvent, "Cannot send telemetry without baseData and baseType");
5484
5672
  return;
5485
5673
  }
5486
5674
  if (!telemetryItem.baseType) {
5487
5675
  telemetryItem.baseType = "EventData";
5488
5676
  }
5489
5677
  if (!_self._sender) {
5490
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.SenderNotInitialized, "Sender was not initialized");
5678
+ _throwInternal(itemCtx.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.SenderNotInitialized, "Sender was not initialized");
5491
5679
  return;
5492
5680
  }
5493
5681
  if (!_isSampledIn(telemetryItem)) {
5494
- itemCtx.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TelemetrySampledAndNotSent, "Telemetry item was sampled out and not sent", { SampleRate: _self._sample.sampleRate });
5682
+ _throwInternal(itemCtx.diagLog(), LoggingSeverity.WARNING, _InternalMessageId.TelemetrySampledAndNotSent, "Telemetry item was sampled out and not sent", { SampleRate: _self._sample.sampleRate });
5495
5683
  return;
5496
5684
  }
5497
5685
  else {
@@ -5501,7 +5689,7 @@
5501
5689
  var defaultEnvelopeIkey = telemetryItem.iKey || _self._senderConfig.instrumentationKey();
5502
5690
  var aiEnvelope_1 = Sender.constructEnvelope(telemetryItem, defaultEnvelopeIkey, itemCtx.diagLog(), convertUndefined);
5503
5691
  if (!aiEnvelope_1) {
5504
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.CreateEnvelopeError, "Unable to create an AppInsights envelope");
5692
+ _throwInternal(itemCtx.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.CreateEnvelopeError, "Unable to create an AppInsights envelope");
5505
5693
  return;
5506
5694
  }
5507
5695
  var doNotSendItem_1 = false;
@@ -5514,7 +5702,7 @@
5514
5702
  }
5515
5703
  }
5516
5704
  catch (e) {
5517
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TelemetryInitializerFailed, "One of telemetry initializers failed, telemetry item will not be sent: " + getExceptionName(e), { exception: dumpObj(e) }, true);
5705
+ _throwInternal(itemCtx.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.TelemetryInitializerFailed, "One of telemetry initializers failed, telemetry item will not be sent: " + getExceptionName(e), { exception: dumpObj(e) }, true);
5518
5706
  }
5519
5707
  });
5520
5708
  delete telemetryItem.tags[ProcessLegacy];
@@ -5532,7 +5720,7 @@
5532
5720
  _setupTimer();
5533
5721
  }
5534
5722
  catch (e) {
5535
- itemCtx.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.FailedAddingTelemetryToBuffer, "Failed adding telemetry to the sender's buffer, some telemetry will be lost: " + getExceptionName(e), { exception: dumpObj(e) });
5723
+ _throwInternal(itemCtx.diagLog(), LoggingSeverity.WARNING, _InternalMessageId.FailedAddingTelemetryToBuffer, "Failed adding telemetry to the sender's buffer, some telemetry will be lost: " + getExceptionName(e), { exception: dumpObj(e) });
5536
5724
  }
5537
5725
  _self.processNext(telemetryItem, itemCtx);
5538
5726
  };
@@ -5567,13 +5755,18 @@
5567
5755
  catch (e) {
5568
5756
  var ieVer = getIEVersion();
5569
5757
  if (!ieVer || ieVer > 9) {
5570
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TransmissionFailed, "Telemetry transmission failed, some telemetry will be lost: " + getExceptionName(e), { exception: dumpObj(e) });
5758
+ _throwInternal(_self.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.TransmissionFailed, "Telemetry transmission failed, some telemetry will be lost: " + getExceptionName(e), { exception: dumpObj(e) });
5571
5759
  }
5572
5760
  }
5573
5761
  }
5574
5762
  };
5763
+ _self._doTeardown = function (unloadCtx, unloadState) {
5764
+ _self.onunloadFlush();
5765
+ _offlineListener.unload();
5766
+ _initDefaults();
5767
+ };
5575
5768
  _self._onError = function (payload, message, event) {
5576
- _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.OnError, "Failed to send telemetry.", { message: message });
5769
+ _throwInternal(_self.diagLog(), LoggingSeverity.WARNING, _InternalMessageId.OnError, "Failed to send telemetry.", { message: message });
5577
5770
  _self._buffer.clearSent(payload);
5578
5771
  };
5579
5772
  _self._onPartialSuccess = function (payload, results) {
@@ -5598,7 +5791,7 @@
5598
5791
  }
5599
5792
  if (retry.length > 0) {
5600
5793
  _resendPayload(retry);
5601
- _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, "Partial success. " +
5794
+ _throwInternal(_self.diagLog(), LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, "Partial success. " +
5602
5795
  "Delivered: " + payload.length + ", Failed: " + failed.length +
5603
5796
  ". Will retry to send " + retry.length + " our of " + results.itemsReceived + " items");
5604
5797
  }
@@ -5643,18 +5836,18 @@
5643
5836
  }
5644
5837
  if (!_self._senderConfig.isRetryDisabled() && _isRetriable(status)) {
5645
5838
  _resendPayload(payload);
5646
- _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " +
5839
+ _throwInternal(_self.diagLog(), LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " +
5647
5840
  "Response code " + status + ". Will retry to send " + payload.length + " items.");
5648
5841
  }
5649
5842
  else {
5650
5843
  _self._onError(payload, errorMessage);
5651
5844
  }
5652
5845
  }
5653
- else if (Offline.isOffline()) {
5846
+ else if (_offlineListener && !_offlineListener.isOnline()) {
5654
5847
  if (!_self._senderConfig.isRetryDisabled()) {
5655
5848
  var offlineBackOffMultiplier = 10;
5656
5849
  _resendPayload(payload, offlineBackOffMultiplier);
5657
- _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". Offline - Response Code: ".concat(status, ". Offline status: ").concat(Offline.isOffline(), ". Will retry to send ").concat(payload.length, " items."));
5850
+ _throwInternal(_self.diagLog(), LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". Offline - Response Code: ".concat(status, ". Offline status: ").concat(!_offlineListener.isOnline(), ". Will retry to send ").concat(payload.length, " items."));
5658
5851
  }
5659
5852
  }
5660
5853
  else {
@@ -5721,8 +5914,8 @@
5721
5914
  }
5722
5915
  }
5723
5916
  if (droppedPayload.length > 0) {
5724
- _fallbackSender(droppedPayload, true);
5725
- _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " + "Failed to send telemetry with Beacon API, retried with normal sender.");
5917
+ _fallbackSender && _fallbackSender(droppedPayload, true);
5918
+ _throwInternal(_self.diagLog(), LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " + "Failed to send telemetry with Beacon API, retried with normal sender.");
5726
5919
  }
5727
5920
  }
5728
5921
  }
@@ -5763,7 +5956,7 @@
5763
5956
  }
5764
5957
  else {
5765
5958
  _fallbackSender && _fallbackSender(payload, true);
5766
- _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " + "Failed to send telemetry with Beacon API, retried with xhrSender.");
5959
+ _throwInternal(_self.diagLog(), LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " + "Failed to send telemetry with Beacon API, retried with xhrSender.");
5767
5960
  }
5768
5961
  }
5769
5962
  }
@@ -5854,7 +6047,7 @@
5854
6047
  }
5855
6048
  }
5856
6049
  catch (e) {
5857
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.InvalidBackendResponse, "Cannot parse the response. " + getExceptionName(e), {
6050
+ _throwInternal(_self.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.InvalidBackendResponse, "Cannot parse the response. " + getExceptionName(e), {
5858
6051
  response: response
5859
6052
  });
5860
6053
  }
@@ -5925,7 +6118,7 @@
5925
6118
  xdr.onerror = function (event) { return _self._onError(payload, _formatErrorMessageXdr(xdr), event); };
5926
6119
  var hostingProtocol = _window && _window.location && _window.location.protocol || "";
5927
6120
  if (_self._senderConfig.endpointUrl().lastIndexOf(hostingProtocol, 0) !== 0) {
5928
- _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " +
6121
+ _throwInternal(_self.diagLog(), LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " +
5929
6122
  "Cannot send XDomain request. The endpoint URL protocol doesn't match the hosting page protocol.");
5930
6123
  buffer.clear();
5931
6124
  return;
@@ -5956,7 +6149,7 @@
5956
6149
  manager.eventsSendRequest(sendRequest, isAsync);
5957
6150
  }
5958
6151
  catch (e) {
5959
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.NotificationException, "send request notification failed: " + getExceptionName(e), { exception: dumpObj(e) });
6152
+ _throwInternal(_self.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.NotificationException, "send request notification failed: " + getExceptionName(e), { exception: dumpObj(e) });
5960
6153
  }
5961
6154
  }
5962
6155
  }
@@ -5969,6 +6162,25 @@
5969
6162
  var regexp = new RegExp(UUID_Regex);
5970
6163
  return regexp.test(config.instrumentationKey);
5971
6164
  }
6165
+ function _initDefaults() {
6166
+ _self._sender = null;
6167
+ _self._buffer = null;
6168
+ _self._appId = null;
6169
+ _self._sample = null;
6170
+ _headers = {};
6171
+ _offlineListener = null;
6172
+ _consecutiveErrors = 0;
6173
+ _retryAt = null;
6174
+ _lastSend = null;
6175
+ _paused = false;
6176
+ _timeoutHandle = null;
6177
+ _serializer = null;
6178
+ _stamp_specific_redirects = 0;
6179
+ _syncFetchPayload = 0;
6180
+ _fallbackSender = null;
6181
+ _syncUnloadSender = null;
6182
+ _evtNamespace = null;
6183
+ }
5972
6184
  });
5973
6185
  return _this;
5974
6186
  }
@@ -6039,4 +6251,4 @@
6039
6251
  (function(obj, prop, descriptor) { /* ai_es3_polyfil defineProperty */ var func = Object["defineProperty"]; if (func) { try { return func(obj, prop, descriptor); } catch(e) { /* IE8 defines defineProperty, but will throw */ } } if (descriptor && typeof descriptor.value !== undefined) { obj[prop] = descriptor.value; } return obj; })(exports, '__esModule', { value: true });
6040
6252
 
6041
6253
  }));
6042
- //# sourceMappingURL=aib.2.8.0-beta.2203-03.js.map
6254
+ //# sourceMappingURL=aib.2.8.0-beta.2203-06.js.map