@microsoft/applicationinsights-channel-js 2.7.5-nightly.2203-02 → 2.7.5-nightly.2203-03

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.
Files changed (38) hide show
  1. package/browser/applicationinsights-channel-js.integrity.json +9 -9
  2. package/browser/applicationinsights-channel-js.js +1208 -429
  3. package/browser/applicationinsights-channel-js.js.map +1 -1
  4. package/browser/applicationinsights-channel-js.min.js +2 -2
  5. package/browser/applicationinsights-channel-js.min.js.map +1 -1
  6. package/dist/applicationinsights-channel-js.api.json +1 -30
  7. package/dist/applicationinsights-channel-js.api.md +0 -2
  8. package/dist/applicationinsights-channel-js.d.ts +1 -2
  9. package/dist/applicationinsights-channel-js.js +1208 -429
  10. package/dist/applicationinsights-channel-js.js.map +1 -1
  11. package/dist/applicationinsights-channel-js.min.js +2 -2
  12. package/dist/applicationinsights-channel-js.min.js.map +1 -1
  13. package/dist/applicationinsights-channel-js.rollup.d.ts +1 -2
  14. package/dist-esm/EnvelopeCreator.js +2 -2
  15. package/dist-esm/EnvelopeCreator.js.map +1 -1
  16. package/dist-esm/Interfaces.js +1 -1
  17. package/dist-esm/Offline.js +77 -65
  18. package/dist-esm/Offline.js.map +1 -1
  19. package/dist-esm/SendBuffer.js +1 -1
  20. package/dist-esm/Sender.js +72 -62
  21. package/dist-esm/Sender.js.map +1 -1
  22. package/dist-esm/Serializer.js +1 -1
  23. package/dist-esm/TelemetryProcessors/Sample.js +3 -3
  24. package/dist-esm/TelemetryProcessors/Sample.js.map +1 -1
  25. package/dist-esm/TelemetryProcessors/SamplingScoreGenerators/HashCodeScoreGenerator.js +1 -1
  26. package/dist-esm/TelemetryProcessors/SamplingScoreGenerators/SamplingScoreGenerator.js +1 -1
  27. package/dist-esm/applicationinsights-channel-js.js +1 -1
  28. package/package.json +4 -4
  29. package/src/EnvelopeCreator.ts +2 -2
  30. package/src/Offline.ts +88 -76
  31. package/src/Sender.ts +83 -90
  32. package/src/Serializer.ts +4 -8
  33. package/src/TelemetryProcessors/Sample.ts +1 -1
  34. package/src/TelemetryProcessors/SamplingScoreGenerators/HashCodeScoreGenerator.ts +3 -1
  35. package/types/Offline.d.ts +8 -11
  36. package/types/Sender.d.ts +0 -1
  37. package/types/TelemetryProcessors/Sample.d.ts +2 -2
  38. package/types/tsdoc-metadata.json +1 -1
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Application Insights JavaScript SDK - Channel, 2.7.5-nightly.2203-02
2
+ * Application Insights JavaScript SDK - Channel, 2.7.5-nightly.2203-03
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
  (function (global, factory) {
@@ -75,7 +75,9 @@
75
75
  var __assignFn = ObjAssign || __objAssignFnImpl;
76
76
  var extendStaticsFn = function (d, b) {
77
77
  extendStaticsFn = ObjClass["setPrototypeOf"] ||
78
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
78
+ ({ __proto__: [] } instanceof Array && function (d, b) {
79
+ d.__proto__ = b;
80
+ }) ||
79
81
  function (d, b) {
80
82
  for (var p in b) {
81
83
  if (b[strShimHasOwnProperty](p)) {
@@ -90,7 +92,9 @@
90
92
  throwTypeError("Class extends value " + String(b) + " is not a constructor or null");
91
93
  }
92
94
  extendStaticsFn(d, b);
93
- function __() { this.constructor = d; }
95
+ function __() {
96
+ this.constructor = d;
97
+ }
94
98
  d[strShimPrototype] = b === null ? objCreateFn(b) : (__[strShimPrototype] = b[strShimPrototype], new __());
95
99
  }
96
100
 
@@ -109,11 +113,11 @@
109
113
  var DynAllowInstChkTag = DynInstChkTag;
110
114
  var DynProtoDefaultOptions = '_dfOpts';
111
115
  var UnknownValue = '_unknown_';
112
- var str__Proto = "__proto__";
116
+ var str__Proto$1 = "__proto__";
113
117
  var strUseBaseInst = 'useBaseInst';
114
118
  var strSetInstFuncs = 'setInstFuncs';
115
119
  var Obj = Object;
116
- var _objGetPrototypeOf = Obj["getPrototypeOf"];
120
+ var _objGetPrototypeOf$1 = Obj["getPrototypeOf"];
117
121
  var _dynamicNames = 0;
118
122
  function _hasOwnProperty(obj, prop) {
119
123
  return obj && Obj[Prototype].hasOwnProperty.call(obj, prop);
@@ -124,12 +128,12 @@
124
128
  function _isObjectArrayOrFunctionPrototype(target) {
125
129
  return _isObjectOrArrayPrototype(target) || target === Function[Prototype];
126
130
  }
127
- function _getObjProto(target) {
131
+ function _getObjProto$1(target) {
128
132
  if (target) {
129
- if (_objGetPrototypeOf) {
130
- return _objGetPrototypeOf(target);
133
+ if (_objGetPrototypeOf$1) {
134
+ return _objGetPrototypeOf$1(target);
131
135
  }
132
- var newProto = target[str__Proto] || target[Prototype] || (target[Constructor] ? target[Constructor][Prototype] : null);
136
+ var newProto = target[str__Proto$1] || target[Prototype] || (target[Constructor] ? target[Constructor][Prototype] : null);
133
137
  if (newProto) {
134
138
  return newProto;
135
139
  }
@@ -195,16 +199,16 @@
195
199
  _forEachProp(instFuncs, function (name) {
196
200
  baseFuncs[name] = _instFuncProxy(thisTarget, instFuncs, name);
197
201
  });
198
- var baseProto = _getObjProto(classProto);
202
+ var baseProto = _getObjProto$1(classProto);
199
203
  var visited = [];
200
204
  while (baseProto && !_isObjectArrayOrFunctionPrototype(baseProto) && !_hasVisited(visited, baseProto)) {
201
205
  _forEachProp(baseProto, function (name) {
202
- if (!baseFuncs[name] && _isDynamicCandidate(baseProto, name, !_objGetPrototypeOf)) {
206
+ if (!baseFuncs[name] && _isDynamicCandidate(baseProto, name, !_objGetPrototypeOf$1)) {
203
207
  baseFuncs[name] = _instFuncProxy(thisTarget, baseProto, name);
204
208
  }
205
209
  });
206
210
  visited.push(baseProto);
207
- baseProto = _getObjProto(baseProto);
211
+ baseProto = _getObjProto$1(baseProto);
208
212
  }
209
213
  return baseFuncs;
210
214
  }
@@ -218,7 +222,7 @@
218
222
  }
219
223
  if (!instFunc[DynInstChkTag] && instFuncTable[DynAllowInstChkTag] !== false) {
220
224
  var canAddInst = !_hasOwnProperty(target, funcName);
221
- var objProto = _getObjProto(target);
225
+ var objProto = _getObjProto$1(target);
222
226
  var visited = [];
223
227
  while (canAddInst && objProto && !_isObjectArrayOrFunctionPrototype(objProto) && !_hasVisited(visited, objProto)) {
224
228
  var protoFunc = objProto[funcName];
@@ -227,7 +231,7 @@
227
231
  break;
228
232
  }
229
233
  visited.push(objProto);
230
- objProto = _getObjProto(objProto);
234
+ objProto = _getObjProto$1(objProto);
231
235
  }
232
236
  try {
233
237
  if (canAddInst) {
@@ -245,7 +249,7 @@
245
249
  function _getProtoFunc(funcName, proto, currentDynProtoProxy) {
246
250
  var protoFunc = proto[funcName];
247
251
  if (protoFunc === currentDynProtoProxy) {
248
- protoFunc = _getObjProto(proto)[funcName];
252
+ protoFunc = _getObjProto$1(proto)[funcName];
249
253
  }
250
254
  if (typeof protoFunc !== strFunction) {
251
255
  _throwTypeError("[" + funcName + "] is not a " + strFunction);
@@ -279,15 +283,15 @@
279
283
  }
280
284
  }
281
285
  function _checkPrototype(classProto, thisTarget) {
282
- if (_objGetPrototypeOf) {
286
+ if (_objGetPrototypeOf$1) {
283
287
  var visited = [];
284
- var thisProto = _getObjProto(thisTarget);
288
+ var thisProto = _getObjProto$1(thisTarget);
285
289
  while (thisProto && !_isObjectArrayOrFunctionPrototype(thisProto) && !_hasVisited(visited, thisProto)) {
286
290
  if (thisProto === classProto) {
287
291
  return true;
288
292
  }
289
293
  visited.push(thisProto);
290
- thisProto = _getObjProto(thisProto);
294
+ thisProto = _getObjProto$1(thisProto);
291
295
  }
292
296
  }
293
297
  return false;
@@ -323,7 +327,7 @@
323
327
  var instFuncs = _getInstanceFuncs(target);
324
328
  var baseFuncs = _getBaseFuncs(classProto, target, instFuncs, useBaseInst);
325
329
  delegateFunc(target, baseFuncs);
326
- var setInstanceFunc = !!_objGetPrototypeOf && !!perfOptions[strSetInstFuncs];
330
+ var setInstanceFunc = !!_objGetPrototypeOf$1 && !!perfOptions[strSetInstFuncs];
327
331
  if (setInstanceFunc && options) {
328
332
  setInstanceFunc = !!options[strSetInstFuncs];
329
333
  }
@@ -335,105 +339,24 @@
335
339
  };
336
340
  dynamicProto[DynProtoDefaultOptions] = perfDefaults;
337
341
 
338
- var LoggingSeverity;
339
- (function (LoggingSeverity) {
340
- LoggingSeverity[LoggingSeverity["CRITICAL"] = 1] = "CRITICAL";
341
- LoggingSeverity[LoggingSeverity["WARNING"] = 2] = "WARNING";
342
- })(LoggingSeverity || (LoggingSeverity = {}));
343
- var _InternalMessageId = {
344
- BrowserDoesNotSupportLocalStorage: 0,
345
- BrowserCannotReadLocalStorage: 1,
346
- BrowserCannotReadSessionStorage: 2,
347
- BrowserCannotWriteLocalStorage: 3,
348
- BrowserCannotWriteSessionStorage: 4,
349
- BrowserFailedRemovalFromLocalStorage: 5,
350
- BrowserFailedRemovalFromSessionStorage: 6,
351
- CannotSendEmptyTelemetry: 7,
352
- ClientPerformanceMathError: 8,
353
- ErrorParsingAISessionCookie: 9,
354
- ErrorPVCalc: 10,
355
- ExceptionWhileLoggingError: 11,
356
- FailedAddingTelemetryToBuffer: 12,
357
- FailedMonitorAjaxAbort: 13,
358
- FailedMonitorAjaxDur: 14,
359
- FailedMonitorAjaxOpen: 15,
360
- FailedMonitorAjaxRSC: 16,
361
- FailedMonitorAjaxSend: 17,
362
- FailedMonitorAjaxGetCorrelationHeader: 18,
363
- FailedToAddHandlerForOnBeforeUnload: 19,
364
- FailedToSendQueuedTelemetry: 20,
365
- FailedToReportDataLoss: 21,
366
- FlushFailed: 22,
367
- MessageLimitPerPVExceeded: 23,
368
- MissingRequiredFieldSpecification: 24,
369
- NavigationTimingNotSupported: 25,
370
- OnError: 26,
371
- SessionRenewalDateIsZero: 27,
372
- SenderNotInitialized: 28,
373
- StartTrackEventFailed: 29,
374
- StopTrackEventFailed: 30,
375
- StartTrackFailed: 31,
376
- StopTrackFailed: 32,
377
- TelemetrySampledAndNotSent: 33,
378
- TrackEventFailed: 34,
379
- TrackExceptionFailed: 35,
380
- TrackMetricFailed: 36,
381
- TrackPVFailed: 37,
382
- TrackPVFailedCalc: 38,
383
- TrackTraceFailed: 39,
384
- TransmissionFailed: 40,
385
- FailedToSetStorageBuffer: 41,
386
- FailedToRestoreStorageBuffer: 42,
387
- InvalidBackendResponse: 43,
388
- FailedToFixDepricatedValues: 44,
389
- InvalidDurationValue: 45,
390
- TelemetryEnvelopeInvalid: 46,
391
- CreateEnvelopeError: 47,
392
- CannotSerializeObject: 48,
393
- CannotSerializeObjectNonSerializable: 49,
394
- CircularReferenceDetected: 50,
395
- ClearAuthContextFailed: 51,
396
- ExceptionTruncated: 52,
397
- IllegalCharsInName: 53,
398
- ItemNotInArray: 54,
399
- MaxAjaxPerPVExceeded: 55,
400
- MessageTruncated: 56,
401
- NameTooLong: 57,
402
- SampleRateOutOfRange: 58,
403
- SetAuthContextFailed: 59,
404
- SetAuthContextFailedAccountName: 60,
405
- StringValueTooLong: 61,
406
- StartCalledMoreThanOnce: 62,
407
- StopCalledWithoutStart: 63,
408
- TelemetryInitializerFailed: 64,
409
- TrackArgumentsNotSpecified: 65,
410
- UrlTooLong: 66,
411
- SessionStorageBufferFull: 67,
412
- CannotAccessCookie: 68,
413
- IdTooLong: 69,
414
- InvalidEvent: 70,
415
- FailedMonitorAjaxSetRequestHeader: 71,
416
- SendBrowserInfoOnUserInit: 72,
417
- PluginException: 73,
418
- NotificationException: 74,
419
- SnippetScriptLoadFailure: 99,
420
- InvalidInstrumentationKey: 100,
421
- CannotParseAiBlobValue: 101,
422
- InvalidContentBlob: 102,
423
- TrackPageActionEventFailed: 103,
424
- FailedAddingCustomDefinedRequestContext: 104,
425
- InMemoryStorageBufferFull: 105
426
- };
342
+ var strEmpty$1 = "";
343
+ var strSetNextPlugin = "setNextPlugin";
344
+ var strIsInitialized = "isInitialized";
345
+ var strTeardown = "teardown";
346
+ var strCore = "core";
347
+ var strUpdate = "update";
348
+ var strDisabled = "disabled";
349
+ var strDoTeardown = "_doTeardown";
427
350
 
428
- var strOnPrefix = "on";
429
- var strAttachEvent = "attachEvent";
430
- var strAddEventHelper = "addEventListener";
431
351
  var strToISOString = "toISOString";
432
352
  var strIndexOf = "indexOf";
433
353
  var strMap = "map";
434
354
  var cStrTrim = "trim";
435
355
  var strToString = "toString";
436
- var _objDefineProperty = ObjDefineProperty;
356
+ var str__Proto = "__proto__";
357
+ var strConstructor = "constructor";
358
+ var _objDefineProperty$1 = ObjDefineProperty;
359
+ var _objFreeze = ObjClass.freeze;
437
360
  var _objKeys = ObjClass.keys;
438
361
  var StringProto = String[strShimPrototype];
439
362
  var _strTrim = StringProto[cStrTrim];
@@ -442,7 +365,23 @@
442
365
  var _isArray = Array.isArray;
443
366
  var _objToString = ObjProto[strToString];
444
367
  var _fnToString = ObjHasOwnProperty[strToString];
445
- _fnToString.call(ObjClass);
368
+ var _objFunctionString = _fnToString.call(ObjClass);
369
+ var rCamelCase = /-([a-z])/g;
370
+ var rNormalizeInvalid = /([^\w\d_$])/g;
371
+ var rLeadingNumeric = /^(\d+[\w\d_$])/;
372
+ var _objGetPrototypeOf = Object["getPrototypeOf"];
373
+ function _getObjProto(target) {
374
+ if (target) {
375
+ if (_objGetPrototypeOf) {
376
+ return _objGetPrototypeOf(target);
377
+ }
378
+ var newProto = target[str__Proto] || target[strShimPrototype] || target[strConstructor];
379
+ if (newProto) {
380
+ return newProto;
381
+ }
382
+ }
383
+ return null;
384
+ }
446
385
  function isUndefined(value) {
447
386
  return value === undefined || typeof value === strShimUndefined;
448
387
  }
@@ -455,24 +394,18 @@
455
394
  function isFunction(value) {
456
395
  return !!(value && typeof value === strShimFunction);
457
396
  }
458
- function attachEvent(obj, eventNameWithoutOn, handlerRef, useCapture) {
459
- if (useCapture === void 0) { useCapture = false; }
460
- var result = false;
461
- if (!isNullOrUndefined(obj)) {
462
- try {
463
- if (!isNullOrUndefined(obj[strAddEventHelper])) {
464
- obj[strAddEventHelper](eventNameWithoutOn, handlerRef, useCapture);
465
- result = true;
466
- }
467
- else if (!isNullOrUndefined(obj[strAttachEvent])) {
468
- obj[strAttachEvent](strOnPrefix + eventNameWithoutOn, handlerRef);
469
- result = true;
470
- }
471
- }
472
- catch (e) {
473
- }
397
+ function normalizeJsName(name) {
398
+ var value = name;
399
+ if (value && isString(value)) {
400
+ value = value.replace(rCamelCase, function (_all, letter) {
401
+ return letter.toUpperCase();
402
+ });
403
+ value = value.replace(rNormalizeInvalid, "_");
404
+ value = value.replace(rLeadingNumeric, function (_all, match) {
405
+ return "_" + match;
406
+ });
474
407
  }
475
- return result;
408
+ return value;
476
409
  }
477
410
  function objForEachKey(target, callbackfn) {
478
411
  if (target) {
@@ -502,6 +435,25 @@
502
435
  function isNumber(value) {
503
436
  return typeof value === "number";
504
437
  }
438
+ function isBoolean(value) {
439
+ return typeof value === "boolean";
440
+ }
441
+ function isPlainObject(value) {
442
+ var result = false;
443
+ if (value && typeof value === "object") {
444
+ var proto = _objGetPrototypeOf ? _objGetPrototypeOf(value) : _getObjProto(value);
445
+ if (!proto) {
446
+ result = true;
447
+ }
448
+ else {
449
+ if (proto[strConstructor] && ObjHasOwnProperty.call(proto, strConstructor)) {
450
+ proto = proto[strConstructor];
451
+ }
452
+ result = typeof proto === strShimFunction && _fnToString.call(proto) === _objFunctionString;
453
+ }
454
+ }
455
+ return result;
456
+ }
505
457
  function toISOString(date) {
506
458
  if (date) {
507
459
  return _dataToISOString ? date[strToISOString]() : _toISOStringPoly(date);
@@ -621,7 +573,7 @@
621
573
  return result;
622
574
  }
623
575
  function objDefineAccessors(target, prop, getProp, setProp) {
624
- if (_objDefineProperty) {
576
+ if (_objDefineProperty$1) {
625
577
  try {
626
578
  var descriptor = {
627
579
  enumerable: true,
@@ -633,7 +585,7 @@
633
585
  if (setProp) {
634
586
  descriptor.set = setProp;
635
587
  }
636
- _objDefineProperty(target, prop, descriptor);
588
+ _objDefineProperty$1(target, prop, descriptor);
637
589
  return true;
638
590
  }
639
591
  catch (e) {
@@ -641,6 +593,10 @@
641
593
  }
642
594
  return false;
643
595
  }
596
+ function _doNothing(value) {
597
+ return value;
598
+ }
599
+ var objFreeze = _objFreeze || _doNothing;
644
600
  function dateNow() {
645
601
  var dt = Date;
646
602
  return dt.now ? dt.now() : new dt().getTime();
@@ -649,7 +605,7 @@
649
605
  if (isError(object)) {
650
606
  return object.name;
651
607
  }
652
- return "";
608
+ return strEmpty$1;
653
609
  }
654
610
  function setValue(target, field, value, valChk, srcChk) {
655
611
  var theValue = value;
@@ -668,6 +624,33 @@
668
624
  function throwError(message) {
669
625
  throw new Error(message);
670
626
  }
627
+ function _createProxyFunction(source, funcName) {
628
+ var srcFunc = null;
629
+ var src = null;
630
+ if (isFunction(source)) {
631
+ srcFunc = source;
632
+ }
633
+ else {
634
+ src = source;
635
+ }
636
+ return function () {
637
+ var originalArguments = arguments;
638
+ if (srcFunc) {
639
+ src = srcFunc();
640
+ }
641
+ if (src) {
642
+ return src[funcName].apply(src, originalArguments);
643
+ }
644
+ };
645
+ }
646
+ function proxyFunctionAs(target, name, source, theFunc, overwriteTarget) {
647
+ if (overwriteTarget === void 0) { overwriteTarget = true; }
648
+ if (target && name && source) {
649
+ if (overwriteTarget || isUndefined(target[name])) {
650
+ target[name] = _createProxyFunction(source, theFunc);
651
+ }
652
+ }
653
+ }
671
654
  function createClassFromInterface(defaults) {
672
655
  return /** @class */ (function () {
673
656
  function class_1() {
@@ -681,12 +664,67 @@
681
664
  return class_1;
682
665
  }());
683
666
  }
667
+ function createEnumStyle(values) {
668
+ var enumClass = {};
669
+ objForEachKey(values, function (field, value) {
670
+ enumClass[field] = value;
671
+ if (!isUndefined(enumClass[value])) {
672
+ throwError("[" + value + "] exists for " + field);
673
+ }
674
+ enumClass[value] = field;
675
+ });
676
+ return objFreeze(enumClass);
677
+ }
684
678
  function optimizeObject(theObject) {
685
679
  if (theObject && ObjAssign) {
686
680
  theObject = ObjClass(ObjAssign({}, theObject));
687
681
  }
688
682
  return theObject;
689
683
  }
684
+ function objExtend(obj1, obj2, obj3, obj4, obj5, obj6) {
685
+ var theArgs = arguments;
686
+ var extended = theArgs[0] || {};
687
+ var argLen = theArgs.length;
688
+ var deep = false;
689
+ var idx = 1;
690
+ if (argLen > 0 && isBoolean(extended)) {
691
+ deep = extended;
692
+ extended = theArgs[idx] || {};
693
+ idx++;
694
+ }
695
+ if (!isObject(extended)) {
696
+ extended = {};
697
+ }
698
+ for (; idx < argLen; idx++) {
699
+ var arg = theArgs[idx];
700
+ var isArgArray = isArray(arg);
701
+ var isArgObj = isObject(arg);
702
+ for (var prop in arg) {
703
+ var propOk = (isArgArray && (prop in arg)) || (isArgObj && (ObjHasOwnProperty.call(arg, prop)));
704
+ if (!propOk) {
705
+ continue;
706
+ }
707
+ var newValue = arg[prop];
708
+ var isNewArray = void 0;
709
+ if (deep && newValue && ((isNewArray = isArray(newValue)) || isPlainObject(newValue))) {
710
+ var clone = extended[prop];
711
+ if (isNewArray) {
712
+ if (!isArray(clone)) {
713
+ clone = [];
714
+ }
715
+ }
716
+ else if (!isPlainObject(clone)) {
717
+ clone = {};
718
+ }
719
+ newValue = objExtend(deep, clone, newValue);
720
+ }
721
+ if (newValue !== undefined) {
722
+ extended[prop] = newValue;
723
+ }
724
+ }
725
+ }
726
+ return extended;
727
+ }
690
728
 
691
729
  var strWindow = "window";
692
730
  var strDocument = "document";
@@ -694,8 +732,13 @@
694
732
  var strNavigator = "navigator";
695
733
  var strConsole = "console";
696
734
  var strJSON = "JSON";
735
+ var strCrypto = "crypto";
736
+ var strMsCrypto = "msCrypto";
697
737
  var strMsie = "msie";
698
738
  var strTrident = "trident/";
739
+ var strXMLHttpRequest = "XMLHttpRequest";
740
+ var _isTrident = null;
741
+ var _navUserAgentCheck = null;
699
742
  var _useXDomainRequest = null;
700
743
  var _beaconsSupported = null;
701
744
  function _hasProperty(theClass, property) {
@@ -775,13 +818,28 @@
775
818
  }
776
819
  return null;
777
820
  }
821
+ function getCrypto() {
822
+ return getGlobalInst(strCrypto);
823
+ }
824
+ function getMsCrypto() {
825
+ return getGlobalInst(strMsCrypto);
826
+ }
827
+ function isIE() {
828
+ var nav = getNavigator();
829
+ if (nav && (nav.userAgent !== _navUserAgentCheck || _isTrident === null)) {
830
+ _navUserAgentCheck = nav.userAgent;
831
+ var userAgent = (_navUserAgentCheck || strEmpty$1).toLowerCase();
832
+ _isTrident = (strContains(userAgent, strMsie) || strContains(userAgent, strTrident));
833
+ }
834
+ return _isTrident;
835
+ }
778
836
  function getIEVersion(userAgentStr) {
779
837
  if (userAgentStr === void 0) { userAgentStr = null; }
780
838
  if (!userAgentStr) {
781
839
  var navigator_1 = getNavigator() || {};
782
- userAgentStr = navigator_1 ? (navigator_1.userAgent || "").toLowerCase() : "";
840
+ userAgentStr = navigator_1 ? (navigator_1.userAgent || strEmpty$1).toLowerCase() : strEmpty$1;
783
841
  }
784
- var ua = (userAgentStr || "").toLowerCase();
842
+ var ua = (userAgentStr || strEmpty$1).toLowerCase();
785
843
  if (strContains(ua, strMsie)) {
786
844
  var doc = getDocument() || {};
787
845
  return Math.max(parseInt(ua.split(strMsie)[1]), (doc[strDocumentMode] || 0));
@@ -796,7 +854,7 @@
796
854
  }
797
855
  function dumpObj(object) {
798
856
  var objectTypeDump = Object[strShimPrototype].toString.call(object);
799
- var propertyValueDump = "";
857
+ var propertyValueDump = strEmpty$1;
800
858
  if (objectTypeDump === "[object Error]") {
801
859
  propertyValueDump = "{ stack: '" + object.stack + "', message: '" + object.message + "', name: '" + object.name + "'";
802
860
  }
@@ -814,8 +872,7 @@
814
872
  function isFetchSupported(withKeepAlive) {
815
873
  var isSupported = false;
816
874
  try {
817
- var fetchApi = getGlobalInst("fetch");
818
- isSupported = !!fetchApi;
875
+ isSupported = !!getGlobalInst("fetch");
819
876
  var request = getGlobalInst("Request");
820
877
  if (isSupported && withKeepAlive && request) {
821
878
  isSupported = _hasProperty(request, "keepalive");
@@ -827,9 +884,9 @@
827
884
  }
828
885
  function useXDomainRequest() {
829
886
  if (_useXDomainRequest === null) {
830
- _useXDomainRequest = (typeof XDomainRequest !== "undefined");
887
+ _useXDomainRequest = (typeof XDomainRequest !== strShimUndefined);
831
888
  if (_useXDomainRequest && isXhrSupported()) {
832
- _useXDomainRequest = _useXDomainRequest && !_hasProperty(getGlobalInst("XMLHttpRequest"), "withCredentials");
889
+ _useXDomainRequest = _useXDomainRequest && !_hasProperty(getGlobalInst(strXMLHttpRequest), "withCredentials");
833
890
  }
834
891
  }
835
892
  return _useXDomainRequest;
@@ -837,7 +894,7 @@
837
894
  function isXhrSupported() {
838
895
  var isSupported = false;
839
896
  try {
840
- var xmlHttpRequest = getGlobalInst("XMLHttpRequest");
897
+ var xmlHttpRequest = getGlobalInst(strXMLHttpRequest);
841
898
  isSupported = !!xmlHttpRequest;
842
899
  }
843
900
  catch (e) {
@@ -868,9 +925,9 @@
868
925
  var strWarnToConsole = "warnToConsole";
869
926
  function _sanitizeDiagnosticText(text) {
870
927
  if (text) {
871
- return "\"" + text.replace(/\"/g, "") + "\"";
928
+ return "\"" + text.replace(/\"/g, strEmpty$1) + "\"";
872
929
  }
873
- return "";
930
+ return strEmpty$1;
874
931
  }
875
932
  function _logToConsole(func, message) {
876
933
  var theConsole = getConsole();
@@ -892,12 +949,12 @@
892
949
  _self.message =
893
950
  (isUserAct ? AiUserActionablePrefix : AiNonUserActionablePrefix) +
894
951
  msgId;
895
- var strProps = "";
952
+ var strProps = strEmpty$1;
896
953
  if (hasJSON()) {
897
954
  strProps = getJSON().stringify(properties);
898
955
  }
899
- var diagnosticText = (msg ? " message:" + _sanitizeDiagnosticText(msg) : "") +
900
- (properties ? " props:" + _sanitizeDiagnosticText(strProps) : "");
956
+ var diagnosticText = (msg ? " message:" + _sanitizeDiagnosticText(msg) : strEmpty$1) +
957
+ (properties ? " props:" + _sanitizeDiagnosticText(strProps) : strEmpty$1);
901
958
  _self.message += diagnosticText;
902
959
  }
903
960
  _InternalLogMessage.dataType = "MessageData";
@@ -927,7 +984,7 @@
927
984
  throw message;
928
985
  }
929
986
  else {
930
- var logFunc = severity === LoggingSeverity.CRITICAL ? strErrorToConsole : strWarnToConsole;
987
+ var logFunc = severity === 1 ? strErrorToConsole : strWarnToConsole;
931
988
  if (!isUndefined(message.message)) {
932
989
  var logLevel = _self.consoleLoggingLevel();
933
990
  if (isUserAct) {
@@ -945,7 +1002,7 @@
945
1002
  _self.logInternalMessage(severity, message);
946
1003
  }
947
1004
  else {
948
- _debugExtMsg("throw" + (severity === LoggingSeverity.CRITICAL ? "Critical" : "Warning"), message);
1005
+ _debugExtMsg("throw" + (severity === 1 ? "Critical" : "Warning"), message);
949
1006
  }
950
1007
  }
951
1008
  };
@@ -977,13 +1034,13 @@
977
1034
  if (severity <= _self.telemetryLoggingLevel()) {
978
1035
  _self.queue.push(message);
979
1036
  _messageCount++;
980
- _debugExtMsg((severity === LoggingSeverity.CRITICAL ? "error" : "warn"), message);
1037
+ _debugExtMsg((severity === 1 ? "error" : "warn"), message);
981
1038
  }
982
1039
  if (_messageCount === _self.maxInternalMessageLimit()) {
983
1040
  var throttleLimitMessage = "Internal events throttle limit per PageView reached for this app.";
984
- var throttleMessage = new _InternalLogMessage(_InternalMessageId.MessageLimitPerPVExceeded, throttleLimitMessage, false);
1041
+ var throttleMessage = new _InternalLogMessage(23 , throttleLimitMessage, false);
985
1042
  _self.queue.push(throttleMessage);
986
- if (severity === LoggingSeverity.CRITICAL) {
1043
+ if (severity === 1 ) {
987
1044
  _self.errorToConsole(throttleLimitMessage);
988
1045
  }
989
1046
  else {
@@ -1012,6 +1069,10 @@
1012
1069
  }
1013
1070
  return DiagnosticLogger;
1014
1071
  }());
1072
+ function _throwInternal(logger, severity, msgId, msg, properties, isUserAct) {
1073
+ if (isUserAct === void 0) { isUserAct = false; }
1074
+ (logger || new DiagnosticLogger()).throwInternal(severity, msgId, msg, properties, isUserAct);
1075
+ }
1015
1076
 
1016
1077
  var strExecutionContextKey = "ctx";
1017
1078
  var PerfEvent = /** @class */ (function () {
@@ -1125,207 +1186,616 @@
1125
1186
  return func();
1126
1187
  }
1127
1188
 
1128
- var TelemetryPluginChain = /** @class */ (function () {
1129
- function TelemetryPluginChain(plugin, defItemCtx) {
1130
- var _self = this;
1131
- var _nextProxy = null;
1132
- var _hasProcessTelemetry = isFunction(plugin.processTelemetry);
1133
- var _hasSetNext = isFunction(plugin.setNextPlugin);
1134
- _self._hasRun = false;
1135
- _self.getPlugin = function () {
1136
- return plugin;
1137
- };
1138
- _self.getNext = function () {
1139
- return _nextProxy;
1140
- };
1141
- _self.setNext = function (nextPlugin) {
1142
- _nextProxy = nextPlugin;
1143
- };
1144
- _self.processTelemetry = function (env, itemCtx) {
1145
- if (!itemCtx) {
1146
- itemCtx = defItemCtx;
1189
+ var UInt32Mask = 0x100000000;
1190
+ var MaxUInt32 = 0xffffffff;
1191
+ var _mwcSeeded = false;
1192
+ var _mwcW = 123456789;
1193
+ var _mwcZ = 987654321;
1194
+ function _mwcSeed(seedValue) {
1195
+ if (seedValue < 0) {
1196
+ seedValue >>>= 0;
1197
+ }
1198
+ _mwcW = (123456789 + seedValue) & MaxUInt32;
1199
+ _mwcZ = (987654321 - seedValue) & MaxUInt32;
1200
+ _mwcSeeded = true;
1201
+ }
1202
+ function _autoSeedMwc() {
1203
+ try {
1204
+ var now = dateNow() & 0x7fffffff;
1205
+ _mwcSeed(((Math.random() * UInt32Mask) ^ now) + now);
1206
+ }
1207
+ catch (e) {
1208
+ }
1209
+ }
1210
+ function random32(signed) {
1211
+ var value = 0;
1212
+ var c = getCrypto() || getMsCrypto();
1213
+ if (c && c.getRandomValues) {
1214
+ value = c.getRandomValues(new Uint32Array(1))[0] & MaxUInt32;
1215
+ }
1216
+ if (value === 0 && isIE()) {
1217
+ if (!_mwcSeeded) {
1218
+ _autoSeedMwc();
1219
+ }
1220
+ value = mwcRandom32() & MaxUInt32;
1221
+ }
1222
+ if (value === 0) {
1223
+ value = Math.floor((UInt32Mask * Math.random()) | 0);
1224
+ }
1225
+ if (!signed) {
1226
+ value >>>= 0;
1227
+ }
1228
+ return value;
1229
+ }
1230
+ function mwcRandom32(signed) {
1231
+ _mwcZ = (36969 * (_mwcZ & 0xFFFF) + (_mwcZ >> 16)) & MaxUInt32;
1232
+ _mwcW = (18000 * (_mwcW & 0xFFFF) + (_mwcW >> 16)) & MaxUInt32;
1233
+ var value = (((_mwcZ << 16) + (_mwcW & 0xFFFF)) >>> 0) & MaxUInt32 | 0;
1234
+ if (!signed) {
1235
+ value >>>= 0;
1236
+ }
1237
+ return value;
1238
+ }
1239
+ function newId(maxLength) {
1240
+ if (maxLength === void 0) { maxLength = 22; }
1241
+ var base64chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
1242
+ var number = random32() >>> 0;
1243
+ var chars = 0;
1244
+ var result = strEmpty$1;
1245
+ while (result.length < maxLength) {
1246
+ chars++;
1247
+ result += base64chars.charAt(number & 0x3F);
1248
+ number >>>= 6;
1249
+ if (chars === 5) {
1250
+ number = (((random32() << 2) & 0xFFFFFFFF) | (number & 0x03)) >>> 0;
1251
+ chars = 0;
1252
+ }
1253
+ }
1254
+ return result;
1255
+ }
1256
+
1257
+ var _objDefineProperty = ObjDefineProperty;
1258
+ var version = "2.7.5-nightly.2203-03";
1259
+ var instanceName = "." + newId(6);
1260
+ var _dataUid = 0;
1261
+ function _createAccessor(target, prop, value) {
1262
+ if (_objDefineProperty) {
1263
+ try {
1264
+ _objDefineProperty(target, prop, {
1265
+ value: value,
1266
+ enumerable: false,
1267
+ configurable: true
1268
+ });
1269
+ return true;
1270
+ }
1271
+ catch (e) {
1272
+ }
1273
+ }
1274
+ return false;
1275
+ }
1276
+ function _canAcceptData(target) {
1277
+ return target.nodeType === 1 || target.nodeType === 9 || !(+target.nodeType);
1278
+ }
1279
+ function _getCache(data, target) {
1280
+ var theCache = target[data.id];
1281
+ if (!theCache) {
1282
+ theCache = {};
1283
+ try {
1284
+ if (_canAcceptData(target)) {
1285
+ if (!_createAccessor(target, data.id, theCache)) {
1286
+ target[data.id] = theCache;
1287
+ }
1147
1288
  }
1148
- var identifier = plugin ? plugin.identifier : "TelemetryPluginChain";
1149
- doPerf(itemCtx ? itemCtx.core() : null, function () { return identifier + ":processTelemetry"; }, function () {
1150
- if (plugin && _hasProcessTelemetry) {
1151
- _self._hasRun = true;
1152
- try {
1153
- itemCtx.setNext(_nextProxy);
1154
- if (_hasSetNext) {
1155
- plugin.setNextPlugin(_nextProxy);
1156
- }
1157
- _nextProxy && (_nextProxy._hasRun = false);
1158
- plugin.processTelemetry(env, itemCtx);
1159
- }
1160
- catch (error) {
1161
- var hasRun = _nextProxy && _nextProxy._hasRun;
1162
- if (!_nextProxy || !hasRun) {
1163
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.PluginException, "Plugin [" + plugin.identifier + "] failed during processTelemetry - " + dumpObj(error));
1164
- }
1165
- if (_nextProxy && !hasRun) {
1166
- _nextProxy.processTelemetry(env, itemCtx);
1167
- }
1168
- }
1289
+ }
1290
+ catch (e) {
1291
+ }
1292
+ }
1293
+ return theCache;
1294
+ }
1295
+ function createUniqueNamespace(name, includeVersion) {
1296
+ if (includeVersion === void 0) { includeVersion = false; }
1297
+ return normalizeJsName(name + (_dataUid++) + (includeVersion ? "." + version : "") + instanceName);
1298
+ }
1299
+ function createElmNodeData(name) {
1300
+ var data = {
1301
+ id: createUniqueNamespace("_aiData-" + (name || "") + "." + version),
1302
+ accept: function (target) {
1303
+ return _canAcceptData(target);
1304
+ },
1305
+ get: function (target, name, defValue, addDefault) {
1306
+ var theCache = target[data.id];
1307
+ if (!theCache) {
1308
+ if (addDefault) {
1309
+ theCache = _getCache(data, target);
1310
+ theCache[normalizeJsName(name)] = defValue;
1169
1311
  }
1170
- else if (_nextProxy) {
1171
- _self._hasRun = true;
1172
- _nextProxy.processTelemetry(env, itemCtx);
1312
+ return defValue;
1313
+ }
1314
+ return theCache[normalizeJsName(name)];
1315
+ },
1316
+ kill: function (target, name) {
1317
+ if (target && target[name]) {
1318
+ try {
1319
+ delete target[name];
1173
1320
  }
1174
- }, function () { return ({ item: env }); }, !(env.sync));
1175
- };
1176
- }
1177
- return TelemetryPluginChain;
1178
- }());
1179
-
1180
- function _createProxyChain(plugins, itemCtx) {
1181
- var proxies = [];
1182
- if (plugins && plugins.length > 0) {
1183
- var lastProxy = null;
1184
- for (var idx = 0; idx < plugins.length; idx++) {
1185
- var thePlugin = plugins[idx];
1186
- if (thePlugin && isFunction(thePlugin.processTelemetry)) {
1187
- var newProxy = new TelemetryPluginChain(thePlugin, itemCtx);
1188
- proxies.push(newProxy);
1189
- if (lastProxy) {
1190
- lastProxy.setNext(newProxy);
1321
+ catch (e) {
1191
1322
  }
1192
- lastProxy = newProxy;
1193
1323
  }
1194
1324
  }
1325
+ };
1326
+ return data;
1327
+ }
1328
+
1329
+ var pluginStateData = createElmNodeData("plugin");
1330
+ function _getPluginState(plugin) {
1331
+ return pluginStateData.get(plugin, "state", {}, true);
1332
+ }
1333
+
1334
+ var strTelemetryPluginChain = "TelemetryPluginChain";
1335
+ var strHasRunFlags = "_hasRun";
1336
+ var strGetTelCtx = "_getTelCtx";
1337
+ var _chainId = 0;
1338
+ function _getNextProxyStart(proxy, config, core, startAt) {
1339
+ while (proxy) {
1340
+ if (proxy.getPlugin() === startAt) {
1341
+ return proxy;
1342
+ }
1343
+ proxy = proxy.getNext();
1195
1344
  }
1196
- return proxies.length > 0 ? proxies[0] : null;
1345
+ return createTelemetryProxyChain([startAt], config, core);
1197
1346
  }
1198
- function _copyProxyChain(proxy, itemCtx, startAt) {
1199
- var plugins = [];
1200
- var add = startAt ? false : true;
1201
- if (proxy) {
1202
- while (proxy) {
1203
- var thePlugin = proxy.getPlugin();
1204
- if (add || thePlugin === startAt) {
1205
- add = true;
1206
- plugins.push(thePlugin);
1347
+ function _createInternalContext(telemetryChain, config, core, startAt) {
1348
+ var _nextProxy = null;
1349
+ var _onComplete = [];
1350
+ if (startAt !== null) {
1351
+ _nextProxy = startAt ? _getNextProxyStart(telemetryChain, config, core, startAt) : telemetryChain;
1352
+ }
1353
+ var context = {
1354
+ _next: _moveNext,
1355
+ ctx: {
1356
+ core: function () {
1357
+ return core;
1358
+ },
1359
+ diagLog: function () {
1360
+ return safeGetLogger(core, config);
1361
+ },
1362
+ getCfg: function () {
1363
+ return config;
1364
+ },
1365
+ getExtCfg: _getExtCfg,
1366
+ getConfig: _getConfig,
1367
+ hasNext: function () {
1368
+ return !!_nextProxy;
1369
+ },
1370
+ getNext: function () {
1371
+ return _nextProxy;
1372
+ },
1373
+ setNext: function (nextPlugin) {
1374
+ _nextProxy = nextPlugin;
1375
+ },
1376
+ iterate: _iterateChain,
1377
+ onComplete: _addOnComplete
1378
+ }
1379
+ };
1380
+ function _addOnComplete(onComplete, that) {
1381
+ var args = [];
1382
+ for (var _i = 2; _i < arguments.length; _i++) {
1383
+ args[_i - 2] = arguments[_i];
1384
+ }
1385
+ if (onComplete) {
1386
+ _onComplete.push({
1387
+ func: onComplete,
1388
+ self: !isUndefined(that) ? that : context.ctx,
1389
+ args: args
1390
+ });
1391
+ }
1392
+ }
1393
+ function _moveNext() {
1394
+ var nextProxy = _nextProxy;
1395
+ _nextProxy = nextProxy ? nextProxy.getNext() : null;
1396
+ if (!nextProxy) {
1397
+ var onComplete = _onComplete;
1398
+ if (onComplete && onComplete.length > 0) {
1399
+ arrForEach(onComplete, function (completeDetails) {
1400
+ try {
1401
+ completeDetails.func.call(completeDetails.self, completeDetails.args);
1402
+ }
1403
+ catch (e) {
1404
+ _throwInternal(core.logger, 2 , 73 , "Unexpected Exception during onComplete - " + dumpObj(e));
1405
+ }
1406
+ });
1407
+ _onComplete = [];
1408
+ }
1409
+ }
1410
+ return nextProxy;
1411
+ }
1412
+ function _getExtCfg(identifier, defaultValue, mergeDefault) {
1413
+ if (defaultValue === void 0) { defaultValue = {}; }
1414
+ if (mergeDefault === void 0) { mergeDefault = 0 ; }
1415
+ var theConfig;
1416
+ if (config) {
1417
+ var extConfig = config.extensionConfig;
1418
+ if (extConfig && identifier) {
1419
+ theConfig = extConfig[identifier];
1420
+ }
1421
+ }
1422
+ if (!theConfig) {
1423
+ theConfig = defaultValue;
1424
+ }
1425
+ else if (isObject(defaultValue)) {
1426
+ if (mergeDefault !== 0 ) {
1427
+ var newConfig_1 = objExtend(true, defaultValue, theConfig);
1428
+ if (config && mergeDefault === 2 ) {
1429
+ objForEachKey(defaultValue, function (field) {
1430
+ if (isNullOrUndefined(newConfig_1[field])) {
1431
+ var cfgValue = config[field];
1432
+ if (!isNullOrUndefined(cfgValue)) {
1433
+ newConfig_1[field] = cfgValue;
1434
+ }
1435
+ }
1436
+ });
1437
+ }
1438
+ }
1439
+ }
1440
+ return theConfig;
1441
+ }
1442
+ function _getConfig(identifier, field, defaultValue) {
1443
+ if (defaultValue === void 0) { defaultValue = false; }
1444
+ var theValue;
1445
+ var extConfig = _getExtCfg(identifier, null);
1446
+ if (extConfig && !isNullOrUndefined(extConfig[field])) {
1447
+ theValue = extConfig[field];
1448
+ }
1449
+ else if (config && !isNullOrUndefined(config[field])) {
1450
+ theValue = config[field];
1451
+ }
1452
+ return !isNullOrUndefined(theValue) ? theValue : defaultValue;
1453
+ }
1454
+ function _iterateChain(cb) {
1455
+ var nextPlugin;
1456
+ while (!!(nextPlugin = context._next())) {
1457
+ var plugin = nextPlugin.getPlugin();
1458
+ if (plugin) {
1459
+ cb(plugin);
1207
1460
  }
1208
- proxy = proxy.getNext();
1209
1461
  }
1210
1462
  }
1211
- if (!add) {
1212
- plugins.push(startAt);
1463
+ return context;
1464
+ }
1465
+ function createProcessTelemetryContext(telemetryChain, config, core, startAt) {
1466
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1467
+ var context = internalContext.ctx;
1468
+ function _processNext(env) {
1469
+ var nextPlugin = internalContext._next();
1470
+ nextPlugin && nextPlugin.processTelemetry(env, context);
1471
+ return !nextPlugin;
1472
+ }
1473
+ function _createNew(plugins, startAt) {
1474
+ if (plugins === void 0) { plugins = null; }
1475
+ if (isArray(plugins)) {
1476
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1477
+ }
1478
+ return createProcessTelemetryContext(plugins || context.getNext(), config, core, startAt);
1213
1479
  }
1214
- return _createProxyChain(plugins, itemCtx);
1480
+ context.processNext = _processNext;
1481
+ context.createNew = _createNew;
1482
+ return context;
1215
1483
  }
1216
- function _copyPluginChain(srcPlugins, itemCtx, startAt) {
1217
- var plugins = srcPlugins;
1218
- var add = false;
1219
- if (startAt && srcPlugins) {
1220
- plugins = [];
1221
- arrForEach(srcPlugins, function (thePlugin) {
1222
- if (add || thePlugin === startAt) {
1223
- add = true;
1224
- plugins.push(thePlugin);
1484
+ function createProcessTelemetryUnloadContext(telemetryChain, config, core, startAt) {
1485
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1486
+ var context = internalContext.ctx;
1487
+ function _processNext(unloadState) {
1488
+ var nextPlugin = internalContext._next();
1489
+ nextPlugin && nextPlugin.unload(context, unloadState);
1490
+ return !nextPlugin;
1491
+ }
1492
+ function _createNew(plugins, startAt) {
1493
+ if (plugins === void 0) { plugins = null; }
1494
+ if (isArray(plugins)) {
1495
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1496
+ }
1497
+ return createProcessTelemetryUnloadContext(plugins || context.getNext(), config, core, startAt);
1498
+ }
1499
+ context.processNext = _processNext;
1500
+ context.createNew = _createNew;
1501
+ return context;
1502
+ }
1503
+ function createProcessTelemetryUpdateContext(telemetryChain, config, core, startAt) {
1504
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1505
+ var context = internalContext.ctx;
1506
+ function _processNext(updateState) {
1507
+ return context.iterate(function (plugin) {
1508
+ if (isFunction(plugin[strUpdate])) {
1509
+ plugin[strUpdate](context, updateState);
1225
1510
  }
1226
1511
  });
1227
1512
  }
1228
- if (startAt && !add) {
1229
- if (!plugins) {
1230
- plugins = [];
1513
+ function _createNew(plugins, startAt) {
1514
+ if (plugins === void 0) { plugins = null; }
1515
+ if (isArray(plugins)) {
1516
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1231
1517
  }
1232
- plugins.push(startAt);
1518
+ return createProcessTelemetryUpdateContext(plugins || context.getNext(), config, core, startAt);
1233
1519
  }
1234
- return _createProxyChain(plugins, itemCtx);
1520
+ context.processNext = _processNext;
1521
+ context.createNew = _createNew;
1522
+ return context;
1235
1523
  }
1236
- var ProcessTelemetryContext = /** @class */ (function () {
1237
- function ProcessTelemetryContext(plugins, config, core, startAt) {
1238
- var _self = this;
1239
- var _nextProxy = null;
1240
- if (startAt !== null) {
1241
- if (plugins && isFunction(plugins.getPlugin)) {
1242
- _nextProxy = _copyProxyChain(plugins, _self, startAt || plugins.getPlugin());
1524
+ function createTelemetryProxyChain(plugins, config, core, startAt) {
1525
+ var firstProxy = null;
1526
+ var add = startAt ? false : true;
1527
+ if (isArray(plugins) && plugins.length > 0) {
1528
+ var lastProxy_1 = null;
1529
+ arrForEach(plugins, function (thePlugin) {
1530
+ if (!add && startAt === thePlugin) {
1531
+ add = true;
1243
1532
  }
1244
- else {
1245
- if (startAt) {
1246
- _nextProxy = _copyPluginChain(plugins, _self, startAt);
1533
+ if (add && thePlugin && isFunction(thePlugin.processTelemetry)) {
1534
+ var newProxy = createTelemetryPluginProxy(thePlugin, config, core);
1535
+ if (!firstProxy) {
1536
+ firstProxy = newProxy;
1247
1537
  }
1248
- else if (isUndefined(startAt)) {
1249
- _nextProxy = _createProxyChain(plugins, _self);
1538
+ if (lastProxy_1) {
1539
+ lastProxy_1._setNext(newProxy);
1250
1540
  }
1541
+ lastProxy_1 = newProxy;
1251
1542
  }
1543
+ });
1544
+ }
1545
+ if (startAt && !firstProxy) {
1546
+ return createTelemetryProxyChain([startAt], config, core);
1547
+ }
1548
+ return firstProxy;
1549
+ }
1550
+ function createTelemetryPluginProxy(plugin, config, core) {
1551
+ var nextProxy = null;
1552
+ var hasProcessTelemetry = isFunction(plugin.processTelemetry);
1553
+ var hasSetNext = isFunction(plugin.setNextPlugin);
1554
+ var chainId;
1555
+ if (plugin) {
1556
+ chainId = plugin.identifier + "-" + plugin.priority + "-" + _chainId++;
1557
+ }
1558
+ else {
1559
+ chainId = "Unknown-0-" + _chainId++;
1560
+ }
1561
+ var proxyChain = {
1562
+ getPlugin: function () {
1563
+ return plugin;
1564
+ },
1565
+ getNext: function () {
1566
+ return nextProxy;
1567
+ },
1568
+ processTelemetry: _processTelemetry,
1569
+ unload: _unloadPlugin,
1570
+ update: _updatePlugin,
1571
+ _id: chainId,
1572
+ _setNext: function (nextPlugin) {
1573
+ nextProxy = nextPlugin;
1252
1574
  }
1253
- _self.core = function () {
1254
- return core;
1255
- };
1256
- _self.diagLog = function () {
1257
- return safeGetLogger(core, config);
1258
- };
1259
- _self.getCfg = function () {
1260
- return config;
1261
- };
1262
- _self.getExtCfg = function (identifier, defaultValue) {
1263
- if (defaultValue === void 0) { defaultValue = {}; }
1264
- var theConfig;
1265
- if (config) {
1266
- var extConfig = config.extensionConfig;
1267
- if (extConfig && identifier) {
1268
- theConfig = extConfig[identifier];
1575
+ };
1576
+ function _getTelCtx() {
1577
+ var itemCtx;
1578
+ if (plugin && isFunction(plugin[strGetTelCtx])) {
1579
+ itemCtx = plugin[strGetTelCtx]();
1580
+ }
1581
+ if (!itemCtx) {
1582
+ itemCtx = createProcessTelemetryContext(proxyChain, config, core);
1583
+ }
1584
+ return itemCtx;
1585
+ }
1586
+ function _processChain(itemCtx, processPluginFn, name, details, isAsync) {
1587
+ var hasRun = false;
1588
+ var identifier = plugin ? plugin.identifier : strTelemetryPluginChain;
1589
+ var hasRunContext = itemCtx[strHasRunFlags];
1590
+ if (!hasRunContext) {
1591
+ hasRunContext = itemCtx[strHasRunFlags] = {};
1592
+ }
1593
+ itemCtx.setNext(nextProxy);
1594
+ if (plugin) {
1595
+ doPerf(itemCtx[strCore](), function () { return identifier + ":" + name; }, function () {
1596
+ hasRunContext[chainId] = true;
1597
+ try {
1598
+ var nextId = nextProxy ? nextProxy._id : strEmpty$1;
1599
+ if (nextId) {
1600
+ hasRunContext[nextId] = false;
1601
+ }
1602
+ hasRun = processPluginFn(itemCtx);
1603
+ }
1604
+ catch (error) {
1605
+ var hasNextRun = nextProxy ? hasRunContext[nextProxy._id] : true;
1606
+ if (hasNextRun) {
1607
+ hasRun = true;
1608
+ }
1609
+ if (!nextProxy || !hasNextRun) {
1610
+ _throwInternal(itemCtx.diagLog(), 1 , 73 , "Plugin [" + plugin.identifier + "] failed during " + name + " - " + dumpObj(error) + ", run flags: " + dumpObj(hasRunContext));
1611
+ }
1269
1612
  }
1613
+ }, details, isAsync);
1614
+ }
1615
+ return hasRun;
1616
+ }
1617
+ function _processTelemetry(env, itemCtx) {
1618
+ itemCtx = itemCtx || _getTelCtx();
1619
+ function _callProcessTelemetry(itemCtx) {
1620
+ if (!plugin || !hasProcessTelemetry) {
1621
+ return false;
1270
1622
  }
1271
- return (theConfig ? theConfig : defaultValue);
1272
- };
1273
- _self.getConfig = function (identifier, field, defaultValue) {
1274
- if (defaultValue === void 0) { defaultValue = false; }
1275
- var theValue;
1276
- var extConfig = _self.getExtCfg(identifier, null);
1277
- if (extConfig && !isNullOrUndefined(extConfig[field])) {
1278
- theValue = extConfig[field];
1623
+ var pluginState = _getPluginState(plugin);
1624
+ if (pluginState[strTeardown] || pluginState[strDisabled]) {
1625
+ return false;
1279
1626
  }
1280
- else if (config && !isNullOrUndefined(config[field])) {
1281
- theValue = config[field];
1627
+ if (hasSetNext) {
1628
+ plugin.setNextPlugin(nextProxy);
1282
1629
  }
1283
- return !isNullOrUndefined(theValue) ? theValue : defaultValue;
1284
- };
1285
- _self.hasNext = function () {
1286
- return _nextProxy != null;
1287
- };
1288
- _self.getNext = function () {
1289
- return _nextProxy;
1290
- };
1291
- _self.setNext = function (nextPlugin) {
1292
- _nextProxy = nextPlugin;
1293
- };
1294
- _self.processNext = function (env) {
1295
- var nextPlugin = _nextProxy;
1296
- if (nextPlugin) {
1297
- _nextProxy = nextPlugin.getNext();
1298
- nextPlugin.processTelemetry(env, _self);
1630
+ plugin.processTelemetry(env, itemCtx);
1631
+ return true;
1632
+ }
1633
+ if (!_processChain(itemCtx, _callProcessTelemetry, "processTelemetry", function () { return ({ item: env }); }, !(env.sync))) {
1634
+ itemCtx.processNext(env);
1635
+ }
1636
+ }
1637
+ function _unloadPlugin(unloadCtx, unloadState) {
1638
+ function _callTeardown() {
1639
+ var hasRun = false;
1640
+ if (plugin) {
1641
+ var pluginState = _getPluginState(plugin);
1642
+ var pluginCore = plugin[strCore] || pluginState.core;
1643
+ if (plugin && (!pluginCore || pluginCore === unloadCtx[strCore]()) && !pluginState[strTeardown]) {
1644
+ pluginState[strCore] = null;
1645
+ pluginState[strTeardown] = true;
1646
+ pluginState[strIsInitialized] = false;
1647
+ if (plugin[strTeardown] && plugin[strTeardown](unloadCtx, unloadState) === true) {
1648
+ hasRun = true;
1649
+ }
1650
+ }
1299
1651
  }
1300
- };
1301
- _self.createNew = function (plugins, startAt) {
1302
- if (plugins === void 0) { plugins = null; }
1303
- return new ProcessTelemetryContext(plugins || _nextProxy, config, core, startAt);
1304
- };
1652
+ return hasRun;
1653
+ }
1654
+ if (!_processChain(unloadCtx, _callTeardown, "unload", function () { }, unloadState.isAsync)) {
1655
+ unloadCtx.processNext(unloadState);
1656
+ }
1305
1657
  }
1306
- return ProcessTelemetryContext;
1307
- }());
1658
+ function _updatePlugin(updateCtx, updateState) {
1659
+ function _callUpdate() {
1660
+ var hasRun = false;
1661
+ if (plugin) {
1662
+ var pluginState = _getPluginState(plugin);
1663
+ var pluginCore = plugin[strCore] || pluginState.core;
1664
+ if (plugin && (!pluginCore || pluginCore === updateCtx[strCore]()) && !pluginState[strTeardown]) {
1665
+ if (plugin[strUpdate] && plugin[strUpdate](updateCtx, updateState) === true) {
1666
+ hasRun = true;
1667
+ }
1668
+ }
1669
+ }
1670
+ return hasRun;
1671
+ }
1672
+ if (!_processChain(updateCtx, _callUpdate, "update", function () { }, false)) {
1673
+ updateCtx.processNext(updateState);
1674
+ }
1675
+ }
1676
+ return objFreeze(proxyChain);
1677
+ }
1308
1678
 
1309
1679
  var strExtensionConfig = "extensionConfig";
1310
1680
 
1681
+ function createUnloadHandlerContainer() {
1682
+ var handlers = [];
1683
+ function _addHandler(handler) {
1684
+ if (handler) {
1685
+ handlers.push(handler);
1686
+ }
1687
+ }
1688
+ function _runHandlers(unloadCtx, unloadState) {
1689
+ arrForEach(handlers, function (handler) {
1690
+ try {
1691
+ handler(unloadCtx, unloadState);
1692
+ }
1693
+ catch (e) {
1694
+ _throwInternal(unloadCtx.diagLog(), 2 , 73 , "Unexpected error calling unload handler - " + dumpObj(e));
1695
+ }
1696
+ });
1697
+ handlers = [];
1698
+ }
1699
+ return {
1700
+ add: _addHandler,
1701
+ run: _runHandlers
1702
+ };
1703
+ }
1704
+
1311
1705
  var strGetPlugin = "getPlugin";
1312
1706
  var BaseTelemetryPlugin = /** @class */ (function () {
1313
1707
  function BaseTelemetryPlugin() {
1314
1708
  var _self = this;
1315
- var _isinitialized = false;
1316
- var _rootCtx = null;
1317
- var _nextPlugin = null;
1318
- _self.core = null;
1709
+ var _isinitialized;
1710
+ var _rootCtx;
1711
+ var _nextPlugin;
1712
+ var _unloadHandlerContainer;
1713
+ var _hooks;
1714
+ _initDefaults();
1715
+ dynamicProto(BaseTelemetryPlugin, _self, function (_self) {
1716
+ _self.initialize = function (config, core, extensions, pluginChain) {
1717
+ _setDefaults(config, core, pluginChain);
1718
+ _isinitialized = true;
1719
+ };
1720
+ _self.teardown = function (unloadCtx, unloadState) {
1721
+ if (!_self.core || (unloadCtx && _self.core !== unloadCtx.core())) {
1722
+ return;
1723
+ }
1724
+ var result;
1725
+ var unloadDone = false;
1726
+ var theUnloadCtx = unloadCtx || createProcessTelemetryUnloadContext(null, {}, _self.core, _nextPlugin && _nextPlugin[strGetPlugin] ? _nextPlugin[strGetPlugin]() : _nextPlugin);
1727
+ var theUnloadState = unloadState || {
1728
+ reason: 0 ,
1729
+ isAsync: false
1730
+ };
1731
+ function _unloadCallback() {
1732
+ if (!unloadDone) {
1733
+ unloadDone = true;
1734
+ _unloadHandlerContainer.run(theUnloadCtx, unloadState);
1735
+ arrForEach(_hooks, function (fn) {
1736
+ fn.rm();
1737
+ });
1738
+ _hooks = [];
1739
+ if (result === true) {
1740
+ theUnloadCtx.processNext(theUnloadState);
1741
+ }
1742
+ _initDefaults();
1743
+ }
1744
+ }
1745
+ if (!_self[strDoTeardown] || _self[strDoTeardown](theUnloadCtx, theUnloadState, _unloadCallback) !== true) {
1746
+ _unloadCallback();
1747
+ }
1748
+ else {
1749
+ result = true;
1750
+ }
1751
+ return result;
1752
+ };
1753
+ _self.update = function (updateCtx, updateState) {
1754
+ if (!_self.core || (updateCtx && _self.core !== updateCtx.core())) {
1755
+ return;
1756
+ }
1757
+ var result;
1758
+ var updateDone = false;
1759
+ var theUpdateCtx = updateCtx || createProcessTelemetryUpdateContext(null, {}, _self.core, _nextPlugin && _nextPlugin[strGetPlugin] ? _nextPlugin[strGetPlugin]() : _nextPlugin);
1760
+ var theUpdateState = updateState || {
1761
+ reason: 0
1762
+ };
1763
+ function _updateCallback() {
1764
+ if (!updateDone) {
1765
+ updateDone = true;
1766
+ _setDefaults(theUpdateCtx.getCfg(), theUpdateCtx.core(), theUpdateCtx.getNext());
1767
+ }
1768
+ }
1769
+ if (!_self._doUpdate || _self._doUpdate(theUpdateCtx, theUpdateState, _updateCallback) !== true) {
1770
+ _updateCallback();
1771
+ }
1772
+ else {
1773
+ result = true;
1774
+ }
1775
+ return result;
1776
+ };
1777
+ _self._addHook = function (hooks) {
1778
+ if (hooks) {
1779
+ if (isArray(hooks)) {
1780
+ _hooks = _hooks.concat(hooks);
1781
+ }
1782
+ else {
1783
+ _hooks.push(hooks);
1784
+ }
1785
+ }
1786
+ };
1787
+ proxyFunctionAs(_self, "_addUnloadCb", function () { return _unloadHandlerContainer; }, "add");
1788
+ });
1319
1789
  _self.diagLog = function (itemCtx) {
1320
- return _self._getTelCtx(itemCtx).diagLog();
1790
+ return _getTelCtx(itemCtx).diagLog();
1321
1791
  };
1322
- _self.isInitialized = function () {
1792
+ _self[strIsInitialized] = function () {
1323
1793
  return _isinitialized;
1324
1794
  };
1325
1795
  _self.setInitialized = function (isInitialized) {
1326
1796
  _isinitialized = isInitialized;
1327
1797
  };
1328
- _self.setNextPlugin = function (next) {
1798
+ _self[strSetNextPlugin] = function (next) {
1329
1799
  _nextPlugin = next;
1330
1800
  };
1331
1801
  _self.processNext = function (env, itemCtx) {
@@ -1336,11 +1806,12 @@
1336
1806
  _nextPlugin.processTelemetry(env, null);
1337
1807
  }
1338
1808
  };
1339
- _self._getTelCtx = function (currentCtx) {
1809
+ _self._getTelCtx = _getTelCtx;
1810
+ function _getTelCtx(currentCtx) {
1340
1811
  if (currentCtx === void 0) { currentCtx = null; }
1341
1812
  var itemCtx = currentCtx;
1342
1813
  if (!itemCtx) {
1343
- var rootCtx = _rootCtx || new ProcessTelemetryContext(null, {}, _self.core);
1814
+ var rootCtx = _rootCtx || createProcessTelemetryContext(null, {}, _self.core);
1344
1815
  if (_nextPlugin && _nextPlugin[strGetPlugin]) {
1345
1816
  itemCtx = rootCtx.createNew(null, _nextPlugin[strGetPlugin]);
1346
1817
  }
@@ -1349,8 +1820,8 @@
1349
1820
  }
1350
1821
  }
1351
1822
  return itemCtx;
1352
- };
1353
- _self._baseTelInit = function (config, core, extensions, pluginChain) {
1823
+ }
1824
+ function _setDefaults(config, core, pluginChain) {
1354
1825
  if (config) {
1355
1826
  setValue(config, strExtensionConfig, [], null, isNullOrUndefined);
1356
1827
  }
@@ -1362,16 +1833,280 @@
1362
1833
  nextPlugin = _nextPlugin[strGetPlugin]();
1363
1834
  }
1364
1835
  _self.core = core;
1365
- _rootCtx = new ProcessTelemetryContext(pluginChain, config, core, nextPlugin);
1366
- _isinitialized = true;
1367
- };
1836
+ _rootCtx = createProcessTelemetryContext(pluginChain, config, core, nextPlugin);
1837
+ }
1838
+ function _initDefaults() {
1839
+ _isinitialized = false;
1840
+ _self.core = null;
1841
+ _rootCtx = null;
1842
+ _nextPlugin = null;
1843
+ _hooks = [];
1844
+ _unloadHandlerContainer = createUnloadHandlerContainer();
1845
+ }
1368
1846
  }
1369
- BaseTelemetryPlugin.prototype.initialize = function (config, core, extensions, pluginChain) {
1370
- this._baseTelInit(config, core, extensions, pluginChain);
1371
- };
1372
1847
  return BaseTelemetryPlugin;
1373
1848
  }());
1374
1849
 
1850
+ var strOnPrefix = "on";
1851
+ var strAttachEvent = "attachEvent";
1852
+ var strAddEventHelper = "addEventListener";
1853
+ var strDetachEvent = "detachEvent";
1854
+ var strRemoveEventListener = "removeEventListener";
1855
+ var strEvents = "events";
1856
+ createUniqueNamespace("aiEvtPageHide");
1857
+ createUniqueNamespace("aiEvtPageShow");
1858
+ var rRemoveEmptyNs = /\.[\.]+/g;
1859
+ var rRemoveTrailingEmptyNs = /[\.]+$/;
1860
+ var _guid = 1;
1861
+ var elmNodeData = createElmNodeData("events");
1862
+ var eventNamespace = /^([^.]*)(?:\.(.+)|)/;
1863
+ function _normalizeNamespace(name) {
1864
+ if (name && name.replace) {
1865
+ return name.replace(/^\s*\.*|\.*\s*$/g, "");
1866
+ }
1867
+ return name;
1868
+ }
1869
+ function _getEvtNamespace(eventName, evtNamespace) {
1870
+ if (evtNamespace) {
1871
+ var theNamespace_1 = "";
1872
+ if (isArray(evtNamespace)) {
1873
+ theNamespace_1 = "";
1874
+ arrForEach(evtNamespace, function (name) {
1875
+ name = _normalizeNamespace(name);
1876
+ if (name) {
1877
+ if (name[0] !== ".") {
1878
+ name = "." + name;
1879
+ }
1880
+ theNamespace_1 += name;
1881
+ }
1882
+ });
1883
+ }
1884
+ else {
1885
+ theNamespace_1 = _normalizeNamespace(evtNamespace);
1886
+ }
1887
+ if (theNamespace_1) {
1888
+ if (theNamespace_1[0] !== ".") {
1889
+ theNamespace_1 = "." + theNamespace_1;
1890
+ }
1891
+ eventName = (eventName || "") + theNamespace_1;
1892
+ }
1893
+ }
1894
+ var parsedEvent = (eventNamespace.exec(eventName || "") || []);
1895
+ return {
1896
+ type: parsedEvent[1],
1897
+ ns: ((parsedEvent[2] || "").replace(rRemoveEmptyNs, ".").replace(rRemoveTrailingEmptyNs, "").split(".").sort()).join(".")
1898
+ };
1899
+ }
1900
+ function _getRegisteredEvents(target, evtName, addDefault) {
1901
+ if (addDefault === void 0) { addDefault = true; }
1902
+ var aiEvts = elmNodeData.get(target, strEvents, {}, addDefault);
1903
+ var registeredEvents = aiEvts[evtName];
1904
+ if (!registeredEvents) {
1905
+ registeredEvents = aiEvts[evtName] = [];
1906
+ }
1907
+ return registeredEvents;
1908
+ }
1909
+ function _doDetach(obj, evtName, handlerRef, useCapture) {
1910
+ if (obj && evtName && evtName.type) {
1911
+ if (obj[strRemoveEventListener]) {
1912
+ obj[strRemoveEventListener](evtName.type, handlerRef, useCapture);
1913
+ }
1914
+ else if (obj[strDetachEvent]) {
1915
+ obj[strDetachEvent](strOnPrefix + evtName.type, handlerRef);
1916
+ }
1917
+ }
1918
+ }
1919
+ function _doAttach(obj, evtName, handlerRef, useCapture) {
1920
+ var result = false;
1921
+ if (obj && evtName && evtName.type && handlerRef) {
1922
+ if (obj[strAddEventHelper]) {
1923
+ obj[strAddEventHelper](evtName.type, handlerRef, useCapture);
1924
+ result = true;
1925
+ }
1926
+ else if (obj[strAttachEvent]) {
1927
+ obj[strAttachEvent](strOnPrefix + evtName.type, handlerRef);
1928
+ result = true;
1929
+ }
1930
+ }
1931
+ return result;
1932
+ }
1933
+ function _doUnregister(target, events, evtName, unRegFn) {
1934
+ var idx = events.length;
1935
+ while (idx--) {
1936
+ var theEvent = events[idx];
1937
+ if (theEvent) {
1938
+ if (!evtName.ns || evtName.ns === theEvent.evtName.ns) {
1939
+ if (!unRegFn || unRegFn(theEvent)) {
1940
+ _doDetach(target, theEvent.evtName, theEvent.handler, theEvent.capture);
1941
+ events.splice(idx, 1);
1942
+ }
1943
+ }
1944
+ }
1945
+ }
1946
+ }
1947
+ function _unregisterEvents(target, evtName, unRegFn) {
1948
+ if (evtName.type) {
1949
+ _doUnregister(target, _getRegisteredEvents(target, evtName.type), evtName, unRegFn);
1950
+ }
1951
+ else {
1952
+ var eventCache = elmNodeData.get(target, strEvents, {});
1953
+ objForEachKey(eventCache, function (evtType, events) {
1954
+ _doUnregister(target, events, evtName, unRegFn);
1955
+ });
1956
+ if (objKeys(eventCache).length === 0) {
1957
+ elmNodeData.kill(target, strEvents);
1958
+ }
1959
+ }
1960
+ }
1961
+ function mergeEvtNamespace(theNamespace, namespaces) {
1962
+ var newNamespaces;
1963
+ if (namespaces) {
1964
+ if (isArray(namespaces)) {
1965
+ newNamespaces = [theNamespace].concat(namespaces);
1966
+ }
1967
+ else {
1968
+ newNamespaces = [theNamespace, namespaces];
1969
+ }
1970
+ newNamespaces = (_getEvtNamespace("xx", newNamespaces).ns).split(".");
1971
+ }
1972
+ else {
1973
+ newNamespaces = theNamespace;
1974
+ }
1975
+ return newNamespaces;
1976
+ }
1977
+ function eventOn(target, eventName, handlerRef, evtNamespace, useCapture) {
1978
+ if (useCapture === void 0) { useCapture = false; }
1979
+ var result = false;
1980
+ if (target) {
1981
+ try {
1982
+ var evtName = _getEvtNamespace(eventName, evtNamespace);
1983
+ result = _doAttach(target, evtName, handlerRef, useCapture);
1984
+ if (result && elmNodeData.accept(target)) {
1985
+ var registeredEvent = {
1986
+ guid: _guid++,
1987
+ evtName: evtName,
1988
+ handler: handlerRef,
1989
+ capture: useCapture
1990
+ };
1991
+ _getRegisteredEvents(target, evtName.type).push(registeredEvent);
1992
+ }
1993
+ }
1994
+ catch (e) {
1995
+ }
1996
+ }
1997
+ return result;
1998
+ }
1999
+ function eventOff(target, eventName, handlerRef, evtNamespace, useCapture) {
2000
+ if (useCapture === void 0) { useCapture = false; }
2001
+ if (target) {
2002
+ try {
2003
+ var evtName_1 = _getEvtNamespace(eventName, evtNamespace);
2004
+ var found_1 = false;
2005
+ _unregisterEvents(target, evtName_1, function (regEvent) {
2006
+ if ((evtName_1.ns && !handlerRef) || regEvent.handler === handlerRef) {
2007
+ found_1 = true;
2008
+ return true;
2009
+ }
2010
+ return false;
2011
+ });
2012
+ if (!found_1) {
2013
+ _doDetach(target, evtName_1, handlerRef, useCapture);
2014
+ }
2015
+ }
2016
+ catch (e) {
2017
+ }
2018
+ }
2019
+ }
2020
+
2021
+ var LoggingSeverity = createEnumStyle({
2022
+ CRITICAL: 1 ,
2023
+ WARNING: 2
2024
+ });
2025
+ var _InternalMessageId = createEnumStyle({
2026
+ BrowserDoesNotSupportLocalStorage: 0 ,
2027
+ BrowserCannotReadLocalStorage: 1 ,
2028
+ BrowserCannotReadSessionStorage: 2 ,
2029
+ BrowserCannotWriteLocalStorage: 3 ,
2030
+ BrowserCannotWriteSessionStorage: 4 ,
2031
+ BrowserFailedRemovalFromLocalStorage: 5 ,
2032
+ BrowserFailedRemovalFromSessionStorage: 6 ,
2033
+ CannotSendEmptyTelemetry: 7 ,
2034
+ ClientPerformanceMathError: 8 ,
2035
+ ErrorParsingAISessionCookie: 9 ,
2036
+ ErrorPVCalc: 10 ,
2037
+ ExceptionWhileLoggingError: 11 ,
2038
+ FailedAddingTelemetryToBuffer: 12 ,
2039
+ FailedMonitorAjaxAbort: 13 ,
2040
+ FailedMonitorAjaxDur: 14 ,
2041
+ FailedMonitorAjaxOpen: 15 ,
2042
+ FailedMonitorAjaxRSC: 16 ,
2043
+ FailedMonitorAjaxSend: 17 ,
2044
+ FailedMonitorAjaxGetCorrelationHeader: 18 ,
2045
+ FailedToAddHandlerForOnBeforeUnload: 19 ,
2046
+ FailedToSendQueuedTelemetry: 20 ,
2047
+ FailedToReportDataLoss: 21 ,
2048
+ FlushFailed: 22 ,
2049
+ MessageLimitPerPVExceeded: 23 ,
2050
+ MissingRequiredFieldSpecification: 24 ,
2051
+ NavigationTimingNotSupported: 25 ,
2052
+ OnError: 26 ,
2053
+ SessionRenewalDateIsZero: 27 ,
2054
+ SenderNotInitialized: 28 ,
2055
+ StartTrackEventFailed: 29 ,
2056
+ StopTrackEventFailed: 30 ,
2057
+ StartTrackFailed: 31 ,
2058
+ StopTrackFailed: 32 ,
2059
+ TelemetrySampledAndNotSent: 33 ,
2060
+ TrackEventFailed: 34 ,
2061
+ TrackExceptionFailed: 35 ,
2062
+ TrackMetricFailed: 36 ,
2063
+ TrackPVFailed: 37 ,
2064
+ TrackPVFailedCalc: 38 ,
2065
+ TrackTraceFailed: 39 ,
2066
+ TransmissionFailed: 40 ,
2067
+ FailedToSetStorageBuffer: 41 ,
2068
+ FailedToRestoreStorageBuffer: 42 ,
2069
+ InvalidBackendResponse: 43 ,
2070
+ FailedToFixDepricatedValues: 44 ,
2071
+ InvalidDurationValue: 45 ,
2072
+ TelemetryEnvelopeInvalid: 46 ,
2073
+ CreateEnvelopeError: 47 ,
2074
+ CannotSerializeObject: 48 ,
2075
+ CannotSerializeObjectNonSerializable: 49 ,
2076
+ CircularReferenceDetected: 50 ,
2077
+ ClearAuthContextFailed: 51 ,
2078
+ ExceptionTruncated: 52 ,
2079
+ IllegalCharsInName: 53 ,
2080
+ ItemNotInArray: 54 ,
2081
+ MaxAjaxPerPVExceeded: 55 ,
2082
+ MessageTruncated: 56 ,
2083
+ NameTooLong: 57 ,
2084
+ SampleRateOutOfRange: 58 ,
2085
+ SetAuthContextFailed: 59 ,
2086
+ SetAuthContextFailedAccountName: 60 ,
2087
+ StringValueTooLong: 61 ,
2088
+ StartCalledMoreThanOnce: 62 ,
2089
+ StopCalledWithoutStart: 63 ,
2090
+ TelemetryInitializerFailed: 64 ,
2091
+ TrackArgumentsNotSpecified: 65 ,
2092
+ UrlTooLong: 66 ,
2093
+ SessionStorageBufferFull: 67 ,
2094
+ CannotAccessCookie: 68 ,
2095
+ IdTooLong: 69 ,
2096
+ InvalidEvent: 70 ,
2097
+ FailedMonitorAjaxSetRequestHeader: 71 ,
2098
+ SendBrowserInfoOnUserInit: 72 ,
2099
+ PluginException: 73 ,
2100
+ NotificationException: 74 ,
2101
+ SnippetScriptLoadFailure: 99 ,
2102
+ InvalidInstrumentationKey: 100 ,
2103
+ CannotParseAiBlobValue: 101 ,
2104
+ InvalidContentBlob: 102 ,
2105
+ TrackPageActionEventFailed: 103 ,
2106
+ FailedAddingCustomDefinedRequestContext: 104 ,
2107
+ InMemoryStorageBufferFull: 105
2108
+ });
2109
+
1375
2110
  var RequestHeaders = {
1376
2111
  requestContextHeader: "Request-Context",
1377
2112
  requestContextTargetKey: "appId",
@@ -1404,7 +2139,7 @@
1404
2139
  name = strTrim(name.toString());
1405
2140
  if (name.length > 150 ) {
1406
2141
  nameTrunc = name.substring(0, 150 );
1407
- logger && logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.NameTooLong, "name is too long. It has been truncated to " + 150 + " characters.", { name: name }, true);
2142
+ _throwInternal(logger, 2 , _InternalMessageId.NameTooLong, "name is too long. It has been truncated to " + 150 + " characters.", { name: name }, true);
1408
2143
  }
1409
2144
  }
1410
2145
  return nameTrunc || name;
@@ -1417,7 +2152,7 @@
1417
2152
  value = strTrim(value);
1418
2153
  if (value.toString().length > maxLength) {
1419
2154
  valueTrunc = value.toString().substring(0, maxLength);
1420
- logger && logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.StringValueTooLong, "string value is too long. It has been truncated to " + maxLength + " characters.", { value: value }, true);
2155
+ _throwInternal(logger, 2 , _InternalMessageId.StringValueTooLong, "string value is too long. It has been truncated to " + maxLength + " characters.", { value: value }, true);
1421
2156
  }
1422
2157
  }
1423
2158
  return valueTrunc || value;
@@ -1430,7 +2165,7 @@
1430
2165
  if (message) {
1431
2166
  if (message.length > 32768 ) {
1432
2167
  messageTrunc = message.substring(0, 32768 );
1433
- logger && logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.MessageTruncated, "message is too long, it has been truncated to " + 32768 + " characters.", { message: message }, true);
2168
+ _throwInternal(logger, 2 , _InternalMessageId.MessageTruncated, "message is too long, it has been truncated to " + 32768 + " characters.", { message: message }, true);
1434
2169
  }
1435
2170
  }
1436
2171
  return messageTrunc || message;
@@ -1441,7 +2176,7 @@
1441
2176
  var value = "" + exception;
1442
2177
  if (value.length > 32768 ) {
1443
2178
  exceptionTrunc = value.substring(0, 32768 );
1444
- logger && logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.ExceptionTruncated, "exception is too long, it has been truncated to " + 32768 + " characters.", { exception: exception }, true);
2179
+ _throwInternal(logger, 2 , _InternalMessageId.ExceptionTruncated, "exception is too long, it has been truncated to " + 32768 + " characters.", { exception: exception }, true);
1445
2180
  }
1446
2181
  }
1447
2182
  return exceptionTrunc || exception;
@@ -1455,7 +2190,7 @@
1455
2190
  value = getJSON().stringify(value);
1456
2191
  }
1457
2192
  catch (e) {
1458
- logger && logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.CannotSerializeObjectNonSerializable, "custom property is not valid", { exception: e }, true);
2193
+ _throwInternal(logger, 2 , _InternalMessageId.CannotSerializeObjectNonSerializable, "custom property is not valid", { exception: e }, true);
1459
2194
  }
1460
2195
  }
1461
2196
  value = dataSanitizeString(logger, value, 8192 );
@@ -1486,7 +2221,7 @@
1486
2221
  input = strTrim(input);
1487
2222
  if (input.length > maxLength) {
1488
2223
  inputTrunc = input.substring(0, maxLength);
1489
- logger && logger.throwInternal(LoggingSeverity.WARNING, _msgId, "input is too long, it has been truncated to " + maxLength + " characters.", { data: input }, true);
2224
+ _throwInternal(logger, 2 , _msgId, "input is too long, it has been truncated to " + maxLength + " characters.", { data: input }, true);
1490
2225
  }
1491
2226
  }
1492
2227
  return inputTrunc || input;
@@ -1496,21 +2231,22 @@
1496
2231
  return s.substr(s.length - 3);
1497
2232
  }
1498
2233
 
2234
+ var strEmpty = "";
1499
2235
  function msToTimeSpan(totalms) {
1500
2236
  if (isNaN(totalms) || totalms < 0) {
1501
2237
  totalms = 0;
1502
2238
  }
1503
2239
  totalms = Math.round(totalms);
1504
- var ms = "" + totalms % 1000;
1505
- var sec = "" + Math.floor(totalms / 1000) % 60;
1506
- var min = "" + Math.floor(totalms / (1000 * 60)) % 60;
1507
- var hour = "" + Math.floor(totalms / (1000 * 60 * 60)) % 24;
2240
+ var ms = strEmpty + totalms % 1000;
2241
+ var sec = strEmpty + Math.floor(totalms / 1000) % 60;
2242
+ var min = strEmpty + Math.floor(totalms / (1000 * 60)) % 60;
2243
+ var hour = strEmpty + Math.floor(totalms / (1000 * 60 * 60)) % 24;
1508
2244
  var days = Math.floor(totalms / (1000 * 60 * 60 * 24));
1509
2245
  ms = ms.length === 1 ? "00" + ms : ms.length === 2 ? "0" + ms : ms;
1510
2246
  sec = sec.length < 2 ? "0" + sec : sec;
1511
2247
  min = min.length < 2 ? "0" + min : min;
1512
2248
  hour = hour.length < 2 ? "0" + hour : hour;
1513
- return (days > 0 ? days + "." : "") + hour + ":" + min + ":" + sec + "." + ms;
2249
+ return (days > 0 ? days + "." : strEmpty) + hour + ":" + min + ":" + sec + "." + ms;
1514
2250
  }
1515
2251
 
1516
2252
  var DisabledPropertyName = "Microsoft_ApplicationInsights_BypassAjaxInstrumentation";
@@ -1519,17 +2255,15 @@
1519
2255
  var HttpMethod = "http.method";
1520
2256
  var strNotSpecified = "not_specified";
1521
2257
 
1522
- var StorageType;
1523
- (function (StorageType) {
1524
- StorageType[StorageType["LocalStorage"] = 0] = "LocalStorage";
1525
- StorageType[StorageType["SessionStorage"] = 1] = "SessionStorage";
1526
- })(StorageType || (StorageType = {}));
1527
- var DistributedTracingModes;
1528
- (function (DistributedTracingModes) {
1529
- DistributedTracingModes[DistributedTracingModes["AI"] = 0] = "AI";
1530
- DistributedTracingModes[DistributedTracingModes["AI_AND_W3C"] = 1] = "AI_AND_W3C";
1531
- DistributedTracingModes[DistributedTracingModes["W3C"] = 2] = "W3C";
1532
- })(DistributedTracingModes || (DistributedTracingModes = {}));
2258
+ var StorageType = createEnumStyle({
2259
+ LocalStorage: 0 ,
2260
+ SessionStorage: 1
2261
+ });
2262
+ createEnumStyle({
2263
+ AI: 0 ,
2264
+ AI_AND_W3C: 1 ,
2265
+ W3C: 2
2266
+ });
1533
2267
 
1534
2268
  var _canUseSessionStorage = undefined;
1535
2269
  function _getVerifiedStorageObject(storageType) {
@@ -1556,8 +2290,8 @@
1556
2290
  }
1557
2291
  return null;
1558
2292
  }
1559
- function utlCanUseSessionStorage() {
1560
- if (_canUseSessionStorage === undefined) {
2293
+ function utlCanUseSessionStorage(reset) {
2294
+ if (reset || _canUseSessionStorage === undefined) {
1561
2295
  _canUseSessionStorage = !!_getVerifiedStorageObject(StorageType.SessionStorage);
1562
2296
  }
1563
2297
  return _canUseSessionStorage;
@@ -1570,7 +2304,7 @@
1570
2304
  }
1571
2305
  catch (e) {
1572
2306
  _canUseSessionStorage = false;
1573
- logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.BrowserCannotReadSessionStorage, "Browser failed read of session storage. " + getExceptionName(e), { exception: dumpObj(e) });
2307
+ _throwInternal(logger, 2 , _InternalMessageId.BrowserCannotReadSessionStorage, "Browser failed read of session storage. " + getExceptionName(e), { exception: dumpObj(e) });
1574
2308
  }
1575
2309
  }
1576
2310
  return null;
@@ -1584,7 +2318,7 @@
1584
2318
  }
1585
2319
  catch (e) {
1586
2320
  _canUseSessionStorage = false;
1587
- logger.throwInternal(LoggingSeverity.WARNING, _InternalMessageId.BrowserCannotWriteSessionStorage, "Browser failed write to session storage. " + getExceptionName(e), { exception: dumpObj(e) });
2321
+ _throwInternal(logger, 2 , _InternalMessageId.BrowserCannotWriteSessionStorage, "Browser failed write to session storage. " + getExceptionName(e), { exception: dumpObj(e) });
1588
2322
  }
1589
2323
  }
1590
2324
  return false;
@@ -2861,7 +3595,7 @@
2861
3595
  }
2862
3596
  }
2863
3597
  var EnvelopeCreator = {
2864
- Version: "2.7.5-nightly.2203-02"
3598
+ Version: "2.7.5-nightly.2203-03"
2865
3599
  };
2866
3600
  function DependencyEnvelopeCreator(logger, telemetryItem, customUndefinedValue) {
2867
3601
  EnvelopeCreatorInit(logger, telemetryItem);
@@ -3156,65 +3890,81 @@
3156
3890
  return Serializer;
3157
3891
  }());
3158
3892
 
3159
- var OfflineListener = /** @class */ (function () {
3160
- function OfflineListener() {
3161
- var _window = getWindow();
3162
- var _document = getDocument();
3163
- var isListening = false;
3164
- var _onlineStatus = true;
3165
- dynamicProto(OfflineListener, this, function (_self) {
3166
- try {
3167
- if (_window) {
3168
- if (attachEvent(_window, "online", _setOnline)) {
3169
- attachEvent(_window, "offline", _setOffline);
3170
- isListening = true;
3171
- }
3172
- }
3173
- if (_document) {
3174
- var target = _document.body || _document;
3175
- if (!isUndefined(target.ononline)) {
3176
- target.ononline = _setOnline;
3177
- target.onoffline = _setOffline;
3178
- isListening = true;
3179
- }
3180
- }
3181
- if (isListening) {
3182
- var _navigator = getNavigator();
3183
- if (_navigator && !isNullOrUndefined(_navigator.onLine)) {
3184
- _onlineStatus = _navigator.onLine;
3185
- }
3893
+ function _disableEvents(target, evtNamespace) {
3894
+ eventOff(target, null, null, evtNamespace);
3895
+ }
3896
+ function createOfflineListener(parentEvtNamespace) {
3897
+ var _document = getDocument();
3898
+ var _navigator = getNavigator();
3899
+ var _isListening = false;
3900
+ var _onlineStatus = true;
3901
+ var _evtNamespace = mergeEvtNamespace(createUniqueNamespace("OfflineListener"), parentEvtNamespace);
3902
+ try {
3903
+ if (_enableEvents(getWindow())) {
3904
+ _isListening = true;
3905
+ }
3906
+ if (_document) {
3907
+ var target = _document.body || _document;
3908
+ if (target.ononline) {
3909
+ if (_enableEvents(target)) {
3910
+ _isListening = true;
3186
3911
  }
3187
3912
  }
3188
- catch (e) {
3189
- isListening = false;
3913
+ }
3914
+ if (_isListening) {
3915
+ if (_navigator && !isNullOrUndefined(_navigator.onLine)) {
3916
+ _onlineStatus = _navigator.onLine;
3190
3917
  }
3191
- _self.isListening = isListening;
3192
- _self.isOnline = function () {
3193
- var result = true;
3194
- var _navigator = getNavigator();
3195
- if (isListening) {
3196
- result = _onlineStatus;
3197
- }
3198
- else if (_navigator && !isNullOrUndefined(_navigator.onLine)) {
3199
- result = _navigator.onLine;
3200
- }
3201
- return result;
3202
- };
3203
- _self.isOffline = function () {
3204
- return !_self.isOnline();
3205
- };
3206
- function _setOnline() {
3207
- _onlineStatus = true;
3918
+ }
3919
+ }
3920
+ catch (e) {
3921
+ _isListening = false;
3922
+ }
3923
+ function _enableEvents(target) {
3924
+ var enabled = false;
3925
+ if (target) {
3926
+ enabled = eventOn(target, "online", _setOnline, _evtNamespace);
3927
+ if (enabled) {
3928
+ eventOn(target, "offline", _setOffline, _evtNamespace);
3208
3929
  }
3209
- function _setOffline() {
3210
- _onlineStatus = false;
3930
+ }
3931
+ return enabled;
3932
+ }
3933
+ function _setOnline() {
3934
+ _onlineStatus = true;
3935
+ }
3936
+ function _setOffline() {
3937
+ _onlineStatus = false;
3938
+ }
3939
+ function _isOnline() {
3940
+ var result = true;
3941
+ if (_isListening) {
3942
+ result = _onlineStatus;
3943
+ }
3944
+ else if (_navigator && !isNullOrUndefined(_navigator.onLine)) {
3945
+ result = _navigator.onLine;
3946
+ }
3947
+ return result;
3948
+ }
3949
+ function _unload() {
3950
+ var win = getWindow();
3951
+ if (win && _isListening) {
3952
+ _disableEvents(win, _evtNamespace);
3953
+ if (_document) {
3954
+ var target = _document.body || _document;
3955
+ if (!isUndefined(target.ononline)) {
3956
+ _disableEvents(target, _evtNamespace);
3957
+ }
3211
3958
  }
3212
- });
3959
+ _isListening = false;
3960
+ }
3213
3961
  }
3214
- OfflineListener.Offline = new OfflineListener;
3215
- return OfflineListener;
3216
- }());
3217
- var Offline = OfflineListener.Offline;
3962
+ return {
3963
+ isOnline: _isOnline,
3964
+ isListening: function () { return _isListening; },
3965
+ unload: _unload
3966
+ };
3967
+ }
3218
3968
 
3219
3969
  var MIN_INPUT_LENGTH = 8;
3220
3970
  var HashCodeScoreGenerator = /** @class */ (function () {
@@ -3342,22 +4092,22 @@
3342
4092
  var _this = _super.call(this) || this;
3343
4093
  _this.priority = 1001;
3344
4094
  _this.identifier = BreezeChannelIdentifier;
4095
+ _this._senderConfig = _getDefaultAppInsightsChannelConfig();
3345
4096
  var _consecutiveErrors;
3346
4097
  var _retryAt;
3347
4098
  var _lastSend;
3348
- var _paused = false;
4099
+ var _paused;
3349
4100
  var _timeoutHandle;
3350
4101
  var _serializer;
3351
4102
  var _stamp_specific_redirects;
3352
- var _headers = {};
4103
+ var _headers;
3353
4104
  var _syncFetchPayload = 0;
3354
4105
  var _fallbackSender;
3355
4106
  var _syncUnloadSender;
3356
- _this._senderConfig = _getDefaultAppInsightsChannelConfig();
4107
+ var _offlineListener;
4108
+ var _evtNamespace;
3357
4109
  dynamicProto(Sender, _this, function (_self, _base) {
3358
- function _notImplemented() {
3359
- throwError("Method not implemented.");
3360
- }
4110
+ _initDefaults();
3361
4111
  _self.pause = function () {
3362
4112
  _clearScheduledTimer();
3363
4113
  _paused = true;
@@ -3372,14 +4122,15 @@
3372
4122
  _setupTimer();
3373
4123
  }
3374
4124
  };
3375
- _self.flush = function () {
4125
+ _self.flush = function (isAsync, callBack, sendReason) {
4126
+ if (isAsync === void 0) { isAsync = true; }
3376
4127
  if (!_paused) {
3377
4128
  _clearScheduledTimer();
3378
4129
  try {
3379
- _self.triggerSend(true, null, 1 );
4130
+ _self.triggerSend(isAsync, null, sendReason || 1 );
3380
4131
  }
3381
4132
  catch (e) {
3382
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.FlushFailed, "flush failed, telemetry will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
4133
+ _throwInternal(_self.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.FlushFailed, "flush failed, telemetry will not be collected: " + getExceptionName(e), { exception: dumpObj(e) });
3383
4134
  }
3384
4135
  }
3385
4136
  };
@@ -3390,7 +4141,7 @@
3390
4141
  _self.triggerSend(true, _doUnloadSend, 2 );
3391
4142
  }
3392
4143
  catch (e) {
3393
- _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) });
4144
+ _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) });
3394
4145
  }
3395
4146
  }
3396
4147
  else {
@@ -3398,11 +4149,13 @@
3398
4149
  }
3399
4150
  }
3400
4151
  };
3401
- _self.teardown = _notImplemented;
3402
4152
  _self.addHeader = function (name, value) {
3403
4153
  _headers[name] = value;
3404
4154
  };
3405
4155
  _self.initialize = function (config, core, extensions, pluginChain) {
4156
+ if (_self.isInitialized()) {
4157
+ _throwInternal(_self.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.SenderNotInitialized, "Sender is already initialized");
4158
+ }
3406
4159
  _base.initialize(config, core, extensions, pluginChain);
3407
4160
  var ctx = _self._getTelCtx();
3408
4161
  var identifier = _self.identifier;
@@ -3413,6 +4166,8 @@
3413
4166
  _self._sender = null;
3414
4167
  _stamp_specific_redirects = 0;
3415
4168
  var diagLog = _self.diagLog();
4169
+ _evtNamespace = mergeEvtNamespace(createUniqueNamespace("Sender"), core.evtNamespace && core.evtNamespace());
4170
+ _offlineListener = createOfflineListener(_evtNamespace);
3416
4171
  var defaultConfig = _getDefaultAppInsightsChannelConfig();
3417
4172
  objForEachKey(defaultConfig, function (field, value) {
3418
4173
  _self._senderConfig[field] = function () { return ctx.getConfig(identifier, field, value()); };
@@ -3421,7 +4176,7 @@
3421
4176
  ? new SessionStorageSendBuffer(diagLog, _self._senderConfig) : new ArraySendBuffer(diagLog, _self._senderConfig);
3422
4177
  _self._sample = new Sample(_self._senderConfig.samplingPercentage(), diagLog);
3423
4178
  if (!_validateInstrumentationKey(config)) {
3424
- diagLog.throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.InvalidInstrumentationKey, "Invalid Instrumentation key " + config.instrumentationKey);
4179
+ _throwInternal(diagLog, LoggingSeverity.CRITICAL, _InternalMessageId.InvalidInstrumentationKey, "Invalid Instrumentation key " + config.instrumentationKey);
3425
4180
  }
3426
4181
  if (!isInternalApplicationInsightsEndpoint(_self._senderConfig.endpointUrl()) && _self._senderConfig.customHeaders() && _self._senderConfig.customHeaders().length > 0) {
3427
4182
  arrForEach(_self._senderConfig.customHeaders(), function (customHeader) {
@@ -3467,22 +4222,22 @@
3467
4222
  return;
3468
4223
  }
3469
4224
  if (!telemetryItem) {
3470
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.CannotSendEmptyTelemetry, "Cannot send empty telemetry");
4225
+ _throwInternal(itemCtx.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.CannotSendEmptyTelemetry, "Cannot send empty telemetry");
3471
4226
  return;
3472
4227
  }
3473
4228
  if (telemetryItem.baseData && !telemetryItem.baseType) {
3474
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.InvalidEvent, "Cannot send telemetry without baseData and baseType");
4229
+ _throwInternal(itemCtx.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.InvalidEvent, "Cannot send telemetry without baseData and baseType");
3475
4230
  return;
3476
4231
  }
3477
4232
  if (!telemetryItem.baseType) {
3478
4233
  telemetryItem.baseType = "EventData";
3479
4234
  }
3480
4235
  if (!_self._sender) {
3481
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.SenderNotInitialized, "Sender was not initialized");
4236
+ _throwInternal(itemCtx.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.SenderNotInitialized, "Sender was not initialized");
3482
4237
  return;
3483
4238
  }
3484
4239
  if (!_isSampledIn(telemetryItem)) {
3485
- itemCtx.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TelemetrySampledAndNotSent, "Telemetry item was sampled out and not sent", { SampleRate: _self._sample.sampleRate });
4240
+ _throwInternal(itemCtx.diagLog(), LoggingSeverity.WARNING, _InternalMessageId.TelemetrySampledAndNotSent, "Telemetry item was sampled out and not sent", { SampleRate: _self._sample.sampleRate });
3486
4241
  return;
3487
4242
  }
3488
4243
  else {
@@ -3492,7 +4247,7 @@
3492
4247
  var defaultEnvelopeIkey = telemetryItem.iKey || _self._senderConfig.instrumentationKey();
3493
4248
  var aiEnvelope_1 = Sender.constructEnvelope(telemetryItem, defaultEnvelopeIkey, itemCtx.diagLog(), convertUndefined);
3494
4249
  if (!aiEnvelope_1) {
3495
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.CreateEnvelopeError, "Unable to create an AppInsights envelope");
4250
+ _throwInternal(itemCtx.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.CreateEnvelopeError, "Unable to create an AppInsights envelope");
3496
4251
  return;
3497
4252
  }
3498
4253
  var doNotSendItem_1 = false;
@@ -3505,7 +4260,7 @@
3505
4260
  }
3506
4261
  }
3507
4262
  catch (e) {
3508
- itemCtx.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TelemetryInitializerFailed, "One of telemetry initializers failed, telemetry item will not be sent: " + getExceptionName(e), { exception: dumpObj(e) }, true);
4263
+ _throwInternal(itemCtx.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.TelemetryInitializerFailed, "One of telemetry initializers failed, telemetry item will not be sent: " + getExceptionName(e), { exception: dumpObj(e) }, true);
3509
4264
  }
3510
4265
  });
3511
4266
  delete telemetryItem.tags[ProcessLegacy];
@@ -3523,7 +4278,7 @@
3523
4278
  _setupTimer();
3524
4279
  }
3525
4280
  catch (e) {
3526
- 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) });
4281
+ _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) });
3527
4282
  }
3528
4283
  _self.processNext(telemetryItem, itemCtx);
3529
4284
  };
@@ -3558,13 +4313,18 @@
3558
4313
  catch (e) {
3559
4314
  var ieVer = getIEVersion();
3560
4315
  if (!ieVer || ieVer > 9) {
3561
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.TransmissionFailed, "Telemetry transmission failed, some telemetry will be lost: " + getExceptionName(e), { exception: dumpObj(e) });
4316
+ _throwInternal(_self.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.TransmissionFailed, "Telemetry transmission failed, some telemetry will be lost: " + getExceptionName(e), { exception: dumpObj(e) });
3562
4317
  }
3563
4318
  }
3564
4319
  }
3565
4320
  };
4321
+ _self._doTeardown = function (unloadCtx, unloadState) {
4322
+ _self.onunloadFlush();
4323
+ _offlineListener.unload();
4324
+ _initDefaults();
4325
+ };
3566
4326
  _self._onError = function (payload, message, event) {
3567
- _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.OnError, "Failed to send telemetry.", { message: message });
4327
+ _throwInternal(_self.diagLog(), LoggingSeverity.WARNING, _InternalMessageId.OnError, "Failed to send telemetry.", { message: message });
3568
4328
  _self._buffer.clearSent(payload);
3569
4329
  };
3570
4330
  _self._onPartialSuccess = function (payload, results) {
@@ -3589,7 +4349,7 @@
3589
4349
  }
3590
4350
  if (retry.length > 0) {
3591
4351
  _resendPayload(retry);
3592
- _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, "Partial success. " +
4352
+ _throwInternal(_self.diagLog(), LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, "Partial success. " +
3593
4353
  "Delivered: " + payload.length + ", Failed: " + failed.length +
3594
4354
  ". Will retry to send " + retry.length + " our of " + results.itemsReceived + " items");
3595
4355
  }
@@ -3634,18 +4394,18 @@
3634
4394
  }
3635
4395
  if (!_self._senderConfig.isRetryDisabled() && _isRetriable(status)) {
3636
4396
  _resendPayload(payload);
3637
- _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " +
4397
+ _throwInternal(_self.diagLog(), LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " +
3638
4398
  "Response code " + status + ". Will retry to send " + payload.length + " items.");
3639
4399
  }
3640
4400
  else {
3641
4401
  _self._onError(payload, errorMessage);
3642
4402
  }
3643
4403
  }
3644
- else if (Offline.isOffline()) {
4404
+ else if (_offlineListener && !_offlineListener.isOnline()) {
3645
4405
  if (!_self._senderConfig.isRetryDisabled()) {
3646
4406
  var offlineBackOffMultiplier = 10;
3647
4407
  _resendPayload(payload, offlineBackOffMultiplier);
3648
- _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."));
4408
+ _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."));
3649
4409
  }
3650
4410
  }
3651
4411
  else {
@@ -3712,8 +4472,8 @@
3712
4472
  }
3713
4473
  }
3714
4474
  if (droppedPayload.length > 0) {
3715
- _fallbackSender(droppedPayload, true);
3716
- _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " + "Failed to send telemetry with Beacon API, retried with normal sender.");
4475
+ _fallbackSender && _fallbackSender(droppedPayload, true);
4476
+ _throwInternal(_self.diagLog(), LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " + "Failed to send telemetry with Beacon API, retried with normal sender.");
3717
4477
  }
3718
4478
  }
3719
4479
  }
@@ -3754,7 +4514,7 @@
3754
4514
  }
3755
4515
  else {
3756
4516
  _fallbackSender && _fallbackSender(payload, true);
3757
- _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " + "Failed to send telemetry with Beacon API, retried with xhrSender.");
4517
+ _throwInternal(_self.diagLog(), LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " + "Failed to send telemetry with Beacon API, retried with xhrSender.");
3758
4518
  }
3759
4519
  }
3760
4520
  }
@@ -3845,7 +4605,7 @@
3845
4605
  }
3846
4606
  }
3847
4607
  catch (e) {
3848
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.InvalidBackendResponse, "Cannot parse the response. " + getExceptionName(e), {
4608
+ _throwInternal(_self.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.InvalidBackendResponse, "Cannot parse the response. " + getExceptionName(e), {
3849
4609
  response: response
3850
4610
  });
3851
4611
  }
@@ -3916,7 +4676,7 @@
3916
4676
  xdr.onerror = function (event) { return _self._onError(payload, _formatErrorMessageXdr(xdr), event); };
3917
4677
  var hostingProtocol = _window && _window.location && _window.location.protocol || "";
3918
4678
  if (_self._senderConfig.endpointUrl().lastIndexOf(hostingProtocol, 0) !== 0) {
3919
- _self.diagLog().throwInternal(LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " +
4679
+ _throwInternal(_self.diagLog(), LoggingSeverity.WARNING, _InternalMessageId.TransmissionFailed, ". " +
3920
4680
  "Cannot send XDomain request. The endpoint URL protocol doesn't match the hosting page protocol.");
3921
4681
  buffer.clear();
3922
4682
  return;
@@ -3947,7 +4707,7 @@
3947
4707
  manager.eventsSendRequest(sendRequest, isAsync);
3948
4708
  }
3949
4709
  catch (e) {
3950
- _self.diagLog().throwInternal(LoggingSeverity.CRITICAL, _InternalMessageId.NotificationException, "send request notification failed: " + getExceptionName(e), { exception: dumpObj(e) });
4710
+ _throwInternal(_self.diagLog(), LoggingSeverity.CRITICAL, _InternalMessageId.NotificationException, "send request notification failed: " + getExceptionName(e), { exception: dumpObj(e) });
3951
4711
  }
3952
4712
  }
3953
4713
  }
@@ -3960,6 +4720,25 @@
3960
4720
  var regexp = new RegExp(UUID_Regex);
3961
4721
  return regexp.test(config.instrumentationKey);
3962
4722
  }
4723
+ function _initDefaults() {
4724
+ _self._sender = null;
4725
+ _self._buffer = null;
4726
+ _self._appId = null;
4727
+ _self._sample = null;
4728
+ _headers = {};
4729
+ _offlineListener = null;
4730
+ _consecutiveErrors = 0;
4731
+ _retryAt = null;
4732
+ _lastSend = null;
4733
+ _paused = false;
4734
+ _timeoutHandle = null;
4735
+ _serializer = null;
4736
+ _stamp_specific_redirects = 0;
4737
+ _syncFetchPayload = 0;
4738
+ _fallbackSender = null;
4739
+ _syncUnloadSender = null;
4740
+ _evtNamespace = null;
4741
+ }
3963
4742
  });
3964
4743
  return _this;
3965
4744
  }