@microsoft/applicationinsights-web-basic 2.8.4-nightly.2205-08 → 2.8.4

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.4-nightly.2205-08
2
+ * Application Insights JavaScript Web SDK - Basic, 2.8.4
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
  (function (global, factory) {
@@ -1482,7 +1482,7 @@
1482
1482
  }
1483
1483
 
1484
1484
  var _objDefineProperty = ObjDefineProperty;
1485
- var version = "2.8.4-nightly.2205-08";
1485
+ var version = "2.8.4";
1486
1486
  var instanceName = "." + newId(6);
1487
1487
  var _dataUid = 0;
1488
1488
  function _createAccessor(target, prop, value) {
@@ -1553,662 +1553,1006 @@
1553
1553
  return data;
1554
1554
  }
1555
1555
 
1556
- var pluginStateData = createElmNodeData("plugin");
1557
- function _getPluginState(plugin) {
1558
- return pluginStateData.get(plugin, "state", {}, true);
1556
+ var strToGMTString = "toGMTString";
1557
+ var strToUTCString = "toUTCString";
1558
+ var strCookie = "cookie";
1559
+ var strExpires = "expires";
1560
+ var strEnabled = "enabled";
1561
+ var strIsCookieUseDisabled = "isCookieUseDisabled";
1562
+ var strDisableCookiesUsage = "disableCookiesUsage";
1563
+ var strConfigCookieMgr = "_ckMgr";
1564
+ var _supportsCookies = null;
1565
+ var _allowUaSameSite = null;
1566
+ var _parsedCookieValue = null;
1567
+ var _doc = getDocument();
1568
+ var _cookieCache = {};
1569
+ var _globalCookieConfig = {};
1570
+ function _gblCookieMgr(config, logger) {
1571
+ var inst = createCookieMgr[strConfigCookieMgr] || _globalCookieConfig[strConfigCookieMgr];
1572
+ if (!inst) {
1573
+ inst = createCookieMgr[strConfigCookieMgr] = createCookieMgr(config, logger);
1574
+ _globalCookieConfig[strConfigCookieMgr] = inst;
1575
+ }
1576
+ return inst;
1559
1577
  }
1560
- function initializePlugins(processContext, extensions) {
1561
- var initPlugins = [];
1562
- var lastPlugin = null;
1563
- var proxy = processContext.getNext();
1564
- var pluginState;
1565
- while (proxy) {
1566
- var thePlugin = proxy.getPlugin();
1567
- if (thePlugin) {
1568
- if (lastPlugin &&
1569
- isFunction(lastPlugin[strSetNextPlugin]) &&
1570
- isFunction(thePlugin[strProcessTelemetry])) {
1571
- lastPlugin[strSetNextPlugin](thePlugin);
1578
+ function _isMgrEnabled(cookieMgr) {
1579
+ if (cookieMgr) {
1580
+ return cookieMgr.isEnabled();
1581
+ }
1582
+ return true;
1583
+ }
1584
+ function _createCookieMgrConfig(rootConfig) {
1585
+ var cookieMgrCfg = rootConfig.cookieCfg = rootConfig.cookieCfg || {};
1586
+ setValue(cookieMgrCfg, "domain", rootConfig.cookieDomain, isNotNullOrUndefined, isNullOrUndefined);
1587
+ setValue(cookieMgrCfg, "path", rootConfig.cookiePath || "/", null, isNullOrUndefined);
1588
+ if (isNullOrUndefined(cookieMgrCfg[strEnabled])) {
1589
+ var cookieEnabled = void 0;
1590
+ if (!isUndefined(rootConfig[strIsCookieUseDisabled])) {
1591
+ cookieEnabled = !rootConfig[strIsCookieUseDisabled];
1592
+ }
1593
+ if (!isUndefined(rootConfig[strDisableCookiesUsage])) {
1594
+ cookieEnabled = !rootConfig[strDisableCookiesUsage];
1595
+ }
1596
+ cookieMgrCfg[strEnabled] = cookieEnabled;
1597
+ }
1598
+ return cookieMgrCfg;
1599
+ }
1600
+ function createCookieMgr(rootConfig, logger) {
1601
+ var cookieMgrConfig = _createCookieMgrConfig(rootConfig || _globalCookieConfig);
1602
+ var _path = cookieMgrConfig.path || "/";
1603
+ var _domain = cookieMgrConfig.domain;
1604
+ var _enabled = cookieMgrConfig[strEnabled] !== false;
1605
+ var cookieMgr = {
1606
+ isEnabled: function () {
1607
+ var enabled = _enabled && areCookiesSupported(logger);
1608
+ var gblManager = _globalCookieConfig[strConfigCookieMgr];
1609
+ if (enabled && gblManager && cookieMgr !== gblManager) {
1610
+ enabled = _isMgrEnabled(gblManager);
1572
1611
  }
1573
- var isInitialized = false;
1574
- if (isFunction(thePlugin[strIsInitialized])) {
1575
- isInitialized = thePlugin[strIsInitialized]();
1612
+ return enabled;
1613
+ },
1614
+ setEnabled: function (value) {
1615
+ _enabled = value !== false;
1616
+ },
1617
+ set: function (name, value, maxAgeSec, domain, path) {
1618
+ var result = false;
1619
+ if (_isMgrEnabled(cookieMgr)) {
1620
+ var values = {};
1621
+ var theValue = strTrim(value || strEmpty$1);
1622
+ var idx = theValue.indexOf(";");
1623
+ if (idx !== -1) {
1624
+ theValue = strTrim(value.substring(0, idx));
1625
+ values = _extractParts(value.substring(idx + 1));
1626
+ }
1627
+ setValue(values, "domain", domain || _domain, isTruthy, isUndefined);
1628
+ if (!isNullOrUndefined(maxAgeSec)) {
1629
+ var _isIE = isIE();
1630
+ if (isUndefined(values[strExpires])) {
1631
+ var nowMs = dateNow();
1632
+ var expireMs = nowMs + (maxAgeSec * 1000);
1633
+ if (expireMs > 0) {
1634
+ var expiry = new Date();
1635
+ expiry.setTime(expireMs);
1636
+ setValue(values, strExpires, _formatDate(expiry, !_isIE ? strToUTCString : strToGMTString) || _formatDate(expiry, _isIE ? strToGMTString : strToUTCString) || strEmpty$1, isTruthy);
1637
+ }
1638
+ }
1639
+ if (!_isIE) {
1640
+ setValue(values, "max-age", strEmpty$1 + maxAgeSec, null, isUndefined);
1641
+ }
1642
+ }
1643
+ var location_1 = getLocation();
1644
+ if (location_1 && location_1.protocol === "https:") {
1645
+ setValue(values, "secure", null, null, isUndefined);
1646
+ if (_allowUaSameSite === null) {
1647
+ _allowUaSameSite = !uaDisallowsSameSiteNone((getNavigator() || {}).userAgent);
1648
+ }
1649
+ if (_allowUaSameSite) {
1650
+ setValue(values, "SameSite", "None", null, isUndefined);
1651
+ }
1652
+ }
1653
+ setValue(values, "path", path || _path, null, isUndefined);
1654
+ var setCookieFn = cookieMgrConfig.setCookie || _setCookieValue;
1655
+ setCookieFn(name, _formatCookieValue(theValue, values));
1656
+ result = true;
1576
1657
  }
1577
- else {
1578
- pluginState = _getPluginState(thePlugin);
1579
- isInitialized = pluginState[strIsInitialized];
1658
+ return result;
1659
+ },
1660
+ get: function (name) {
1661
+ var value = strEmpty$1;
1662
+ if (_isMgrEnabled(cookieMgr)) {
1663
+ value = (cookieMgrConfig.getCookie || _getCookieValue)(name);
1580
1664
  }
1581
- if (!isInitialized) {
1582
- initPlugins.push(thePlugin);
1665
+ return value;
1666
+ },
1667
+ del: function (name, path) {
1668
+ var result = false;
1669
+ if (_isMgrEnabled(cookieMgr)) {
1670
+ result = cookieMgr.purge(name, path);
1583
1671
  }
1584
- lastPlugin = thePlugin;
1585
- proxy = proxy.getNext();
1586
- }
1587
- }
1588
- arrForEach(initPlugins, function (thePlugin) {
1589
- var core = processContext.core();
1590
- thePlugin.initialize(processContext.getCfg(), core, extensions, processContext.getNext());
1591
- pluginState = _getPluginState(thePlugin);
1592
- if (!thePlugin[strCore] && !pluginState[strCore]) {
1593
- pluginState[strCore] = core;
1672
+ return result;
1673
+ },
1674
+ purge: function (name, path) {
1675
+ var _a;
1676
+ var result = false;
1677
+ if (areCookiesSupported(logger)) {
1678
+ var values = (_a = {},
1679
+ _a["path"] = path ? path : "/",
1680
+ _a[strExpires] = "Thu, 01 Jan 1970 00:00:01 GMT",
1681
+ _a);
1682
+ if (!isIE()) {
1683
+ values["max-age"] = "0";
1684
+ }
1685
+ var delCookie = cookieMgrConfig.delCookie || _setCookieValue;
1686
+ delCookie(name, _formatCookieValue(strEmpty$1, values));
1687
+ result = true;
1688
+ }
1689
+ return result;
1594
1690
  }
1595
- pluginState[strIsInitialized] = true;
1596
- delete pluginState[strTeardown];
1597
- });
1691
+ };
1692
+ cookieMgr[strConfigCookieMgr] = cookieMgr;
1693
+ return cookieMgr;
1598
1694
  }
1599
- function sortPlugins(plugins) {
1600
- return plugins.sort(function (extA, extB) {
1601
- var result = 0;
1602
- var bHasProcess = isFunction(extB[strProcessTelemetry]);
1603
- if (isFunction(extA[strProcessTelemetry])) {
1604
- result = bHasProcess ? extA[strPriority] - extB[strPriority] : 1;
1695
+ function areCookiesSupported(logger) {
1696
+ if (_supportsCookies === null) {
1697
+ _supportsCookies = false;
1698
+ try {
1699
+ var doc = _doc || {};
1700
+ _supportsCookies = doc[strCookie] !== undefined;
1605
1701
  }
1606
- else if (bHasProcess) {
1607
- result = -1;
1702
+ catch (e) {
1703
+ _throwInternal(logger, 2 , 68 , "Cannot access document.cookie - " + getExceptionName(e), { exception: dumpObj(e) });
1608
1704
  }
1609
- return result;
1705
+ }
1706
+ return _supportsCookies;
1707
+ }
1708
+ function _extractParts(theValue) {
1709
+ var values = {};
1710
+ if (theValue && theValue.length) {
1711
+ var parts = strTrim(theValue).split(";");
1712
+ arrForEach(parts, function (thePart) {
1713
+ thePart = strTrim(thePart || strEmpty$1);
1714
+ if (thePart) {
1715
+ var idx = thePart.indexOf("=");
1716
+ if (idx === -1) {
1717
+ values[thePart] = null;
1718
+ }
1719
+ else {
1720
+ values[strTrim(thePart.substring(0, idx))] = strTrim(thePart.substring(idx + 1));
1721
+ }
1722
+ }
1723
+ });
1724
+ }
1725
+ return values;
1726
+ }
1727
+ function _formatDate(theDate, func) {
1728
+ if (isFunction(theDate[func])) {
1729
+ return theDate[func]();
1730
+ }
1731
+ return null;
1732
+ }
1733
+ function _formatCookieValue(value, values) {
1734
+ var cookieValue = value || strEmpty$1;
1735
+ objForEachKey(values, function (name, theValue) {
1736
+ cookieValue += "; " + name + (!isNullOrUndefined(theValue) ? "=" + theValue : strEmpty$1);
1610
1737
  });
1738
+ return cookieValue;
1611
1739
  }
1612
-
1613
- var strTelemetryPluginChain = "TelemetryPluginChain";
1614
- var strHasRunFlags = "_hasRun";
1615
- var strGetTelCtx = "_getTelCtx";
1616
- var _chainId = 0;
1617
- function _getNextProxyStart(proxy, core, startAt) {
1618
- while (proxy) {
1619
- if (proxy.getPlugin() === startAt) {
1620
- return proxy;
1740
+ function _getCookieValue(name) {
1741
+ var cookieValue = strEmpty$1;
1742
+ if (_doc) {
1743
+ var theCookie = _doc[strCookie] || strEmpty$1;
1744
+ if (_parsedCookieValue !== theCookie) {
1745
+ _cookieCache = _extractParts(theCookie);
1746
+ _parsedCookieValue = theCookie;
1621
1747
  }
1622
- proxy = proxy.getNext();
1748
+ cookieValue = strTrim(_cookieCache[name] || strEmpty$1);
1623
1749
  }
1624
- return createTelemetryProxyChain([startAt], core.config || {}, core);
1750
+ return cookieValue;
1625
1751
  }
1626
- function _createInternalContext(telemetryChain, config, core, startAt) {
1627
- var _nextProxy = null;
1628
- var _onComplete = [];
1629
- if (startAt !== null) {
1630
- _nextProxy = startAt ? _getNextProxyStart(telemetryChain, core, startAt) : telemetryChain;
1752
+ function _setCookieValue(name, cookieValue) {
1753
+ if (_doc) {
1754
+ _doc[strCookie] = name + "=" + cookieValue;
1631
1755
  }
1632
- var context = {
1633
- _next: _moveNext,
1634
- ctx: {
1635
- core: function () {
1636
- return core;
1637
- },
1638
- diagLog: function () {
1639
- return safeGetLogger(core, config);
1640
- },
1641
- getCfg: function () {
1642
- return config;
1643
- },
1644
- getExtCfg: _getExtCfg,
1645
- getConfig: _getConfig,
1646
- hasNext: function () {
1647
- return !!_nextProxy;
1648
- },
1649
- getNext: function () {
1650
- return _nextProxy;
1651
- },
1652
- setNext: function (nextPlugin) {
1653
- _nextProxy = nextPlugin;
1654
- },
1655
- iterate: _iterateChain,
1656
- onComplete: _addOnComplete
1657
- }
1658
- };
1659
- function _addOnComplete(onComplete, that) {
1660
- var args = [];
1661
- for (var _i = 2; _i < arguments.length; _i++) {
1662
- args[_i - 2] = arguments[_i];
1663
- }
1664
- if (onComplete) {
1665
- _onComplete.push({
1666
- func: onComplete,
1667
- self: !isUndefined(that) ? that : context.ctx,
1668
- args: args
1669
- });
1670
- }
1756
+ }
1757
+ function uaDisallowsSameSiteNone(userAgent) {
1758
+ if (!isString(userAgent)) {
1759
+ return false;
1671
1760
  }
1672
- function _moveNext() {
1673
- var nextProxy = _nextProxy;
1674
- _nextProxy = nextProxy ? nextProxy.getNext() : null;
1675
- if (!nextProxy) {
1676
- var onComplete = _onComplete;
1677
- if (onComplete && onComplete.length > 0) {
1678
- arrForEach(onComplete, function (completeDetails) {
1679
- try {
1680
- completeDetails.func.call(completeDetails.self, completeDetails.args);
1681
- }
1682
- catch (e) {
1683
- _throwInternal(core.logger, 2 , 73 , "Unexpected Exception during onComplete - " + dumpObj(e));
1761
+ if (strContains(userAgent, "CPU iPhone OS 12") || strContains(userAgent, "iPad; CPU OS 12")) {
1762
+ return true;
1763
+ }
1764
+ if (strContains(userAgent, "Macintosh; Intel Mac OS X 10_14") && strContains(userAgent, "Version/") && strContains(userAgent, "Safari")) {
1765
+ return true;
1766
+ }
1767
+ if (strContains(userAgent, "Macintosh; Intel Mac OS X 10_14") && strEndsWith(userAgent, "AppleWebKit/605.1.15 (KHTML, like Gecko)")) {
1768
+ return true;
1769
+ }
1770
+ if (strContains(userAgent, "Chrome/5") || strContains(userAgent, "Chrome/6")) {
1771
+ return true;
1772
+ }
1773
+ if (strContains(userAgent, "UnrealEngine") && !strContains(userAgent, "Chrome")) {
1774
+ return true;
1775
+ }
1776
+ if (strContains(userAgent, "UCBrowser/12") || strContains(userAgent, "UCBrowser/11")) {
1777
+ return true;
1778
+ }
1779
+ return false;
1780
+ }
1781
+
1782
+ var strOnPrefix = "on";
1783
+ var strAttachEvent = "attachEvent";
1784
+ var strAddEventHelper = "addEventListener";
1785
+ var strDetachEvent = "detachEvent";
1786
+ var strRemoveEventListener = "removeEventListener";
1787
+ var strEvents = "events";
1788
+ createUniqueNamespace("aiEvtPageHide");
1789
+ createUniqueNamespace("aiEvtPageShow");
1790
+ var rRemoveEmptyNs = /\.[\.]+/g;
1791
+ var rRemoveTrailingEmptyNs = /[\.]+$/;
1792
+ var _guid = 1;
1793
+ var elmNodeData = createElmNodeData("events");
1794
+ var eventNamespace = /^([^.]*)(?:\.(.+)|)/;
1795
+ function _normalizeNamespace(name) {
1796
+ if (name && name.replace) {
1797
+ return name.replace(/^\s*\.*|\.*\s*$/g, "");
1798
+ }
1799
+ return name;
1800
+ }
1801
+ function _getEvtNamespace(eventName, evtNamespace) {
1802
+ if (evtNamespace) {
1803
+ var theNamespace_1 = "";
1804
+ if (isArray(evtNamespace)) {
1805
+ theNamespace_1 = "";
1806
+ arrForEach(evtNamespace, function (name) {
1807
+ name = _normalizeNamespace(name);
1808
+ if (name) {
1809
+ if (name[0] !== ".") {
1810
+ name = "." + name;
1684
1811
  }
1685
- });
1686
- _onComplete = [];
1687
- }
1812
+ theNamespace_1 += name;
1813
+ }
1814
+ });
1688
1815
  }
1689
- return nextProxy;
1690
- }
1691
- function _getExtCfg(identifier, defaultValue, mergeDefault) {
1692
- if (defaultValue === void 0) { defaultValue = {}; }
1693
- if (mergeDefault === void 0) { mergeDefault = 0 ; }
1694
- var theConfig;
1695
- if (config) {
1696
- var extConfig = config.extensionConfig;
1697
- if (extConfig && identifier) {
1698
- theConfig = extConfig[identifier];
1816
+ else {
1817
+ theNamespace_1 = _normalizeNamespace(evtNamespace);
1818
+ }
1819
+ if (theNamespace_1) {
1820
+ if (theNamespace_1[0] !== ".") {
1821
+ theNamespace_1 = "." + theNamespace_1;
1699
1822
  }
1823
+ eventName = (eventName || "") + theNamespace_1;
1700
1824
  }
1701
- if (!theConfig) {
1702
- theConfig = defaultValue;
1825
+ }
1826
+ var parsedEvent = (eventNamespace.exec(eventName || "") || []);
1827
+ return {
1828
+ type: parsedEvent[1],
1829
+ ns: ((parsedEvent[2] || "").replace(rRemoveEmptyNs, ".").replace(rRemoveTrailingEmptyNs, "").split(".").sort()).join(".")
1830
+ };
1831
+ }
1832
+ function _getRegisteredEvents(target, evtName, addDefault) {
1833
+ if (addDefault === void 0) { addDefault = true; }
1834
+ var aiEvts = elmNodeData.get(target, strEvents, {}, addDefault);
1835
+ var registeredEvents = aiEvts[evtName];
1836
+ if (!registeredEvents) {
1837
+ registeredEvents = aiEvts[evtName] = [];
1838
+ }
1839
+ return registeredEvents;
1840
+ }
1841
+ function _doDetach(obj, evtName, handlerRef, useCapture) {
1842
+ if (obj && evtName && evtName.type) {
1843
+ if (obj[strRemoveEventListener]) {
1844
+ obj[strRemoveEventListener](evtName.type, handlerRef, useCapture);
1703
1845
  }
1704
- else if (isObject(defaultValue)) {
1705
- if (mergeDefault !== 0 ) {
1706
- var newConfig_1 = objExtend(true, defaultValue, theConfig);
1707
- if (config && mergeDefault === 2 ) {
1708
- objForEachKey(defaultValue, function (field) {
1709
- if (isNullOrUndefined(newConfig_1[field])) {
1710
- var cfgValue = config[field];
1711
- if (!isNullOrUndefined(cfgValue)) {
1712
- newConfig_1[field] = cfgValue;
1713
- }
1714
- }
1715
- });
1716
- }
1717
- theConfig = newConfig_1;
1718
- }
1846
+ else if (obj[strDetachEvent]) {
1847
+ obj[strDetachEvent](strOnPrefix + evtName.type, handlerRef);
1719
1848
  }
1720
- return theConfig;
1721
1849
  }
1722
- function _getConfig(identifier, field, defaultValue) {
1723
- if (defaultValue === void 0) { defaultValue = false; }
1724
- var theValue;
1725
- var extConfig = _getExtCfg(identifier, null);
1726
- if (extConfig && !isNullOrUndefined(extConfig[field])) {
1727
- theValue = extConfig[field];
1850
+ }
1851
+ function _doAttach(obj, evtName, handlerRef, useCapture) {
1852
+ var result = false;
1853
+ if (obj && evtName && evtName.type && handlerRef) {
1854
+ if (obj[strAddEventHelper]) {
1855
+ obj[strAddEventHelper](evtName.type, handlerRef, useCapture);
1856
+ result = true;
1728
1857
  }
1729
- else if (config && !isNullOrUndefined(config[field])) {
1730
- theValue = config[field];
1858
+ else if (obj[strAttachEvent]) {
1859
+ obj[strAttachEvent](strOnPrefix + evtName.type, handlerRef);
1860
+ result = true;
1731
1861
  }
1732
- return !isNullOrUndefined(theValue) ? theValue : defaultValue;
1733
1862
  }
1734
- function _iterateChain(cb) {
1735
- var nextPlugin;
1736
- while (!!(nextPlugin = context._next())) {
1737
- var plugin = nextPlugin.getPlugin();
1738
- if (plugin) {
1739
- cb(plugin);
1863
+ return result;
1864
+ }
1865
+ function _doUnregister(target, events, evtName, unRegFn) {
1866
+ var idx = events.length;
1867
+ while (idx--) {
1868
+ var theEvent = events[idx];
1869
+ if (theEvent) {
1870
+ if (!evtName.ns || evtName.ns === theEvent.evtName.ns) {
1871
+ if (!unRegFn || unRegFn(theEvent)) {
1872
+ _doDetach(target, theEvent.evtName, theEvent.handler, theEvent.capture);
1873
+ events.splice(idx, 1);
1874
+ }
1740
1875
  }
1741
1876
  }
1742
1877
  }
1743
- return context;
1744
1878
  }
1745
- function createProcessTelemetryContext(telemetryChain, config, core, startAt) {
1746
- var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1747
- var context = internalContext.ctx;
1748
- function _processNext(env) {
1749
- var nextPlugin = internalContext._next();
1750
- nextPlugin && nextPlugin.processTelemetry(env, context);
1751
- return !nextPlugin;
1879
+ function _unregisterEvents(target, evtName, unRegFn) {
1880
+ if (evtName.type) {
1881
+ _doUnregister(target, _getRegisteredEvents(target, evtName.type), evtName, unRegFn);
1752
1882
  }
1753
- function _createNew(plugins, startAt) {
1754
- if (plugins === void 0) { plugins = null; }
1755
- if (isArray(plugins)) {
1756
- plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1883
+ else {
1884
+ var eventCache = elmNodeData.get(target, strEvents, {});
1885
+ objForEachKey(eventCache, function (evtType, events) {
1886
+ _doUnregister(target, events, evtName, unRegFn);
1887
+ });
1888
+ if (objKeys(eventCache).length === 0) {
1889
+ elmNodeData.kill(target, strEvents);
1757
1890
  }
1758
- return createProcessTelemetryContext(plugins || context.getNext(), config, core, startAt);
1759
1891
  }
1760
- context.processNext = _processNext;
1761
- context.createNew = _createNew;
1762
- return context;
1763
1892
  }
1764
- function createProcessTelemetryUnloadContext(telemetryChain, core, startAt) {
1765
- var config = core.config || {};
1766
- var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1767
- var context = internalContext.ctx;
1768
- function _processNext(unloadState) {
1769
- var nextPlugin = internalContext._next();
1770
- nextPlugin && nextPlugin.unload(context, unloadState);
1771
- return !nextPlugin;
1772
- }
1773
- function _createNew(plugins, startAt) {
1774
- if (plugins === void 0) { plugins = null; }
1775
- if (isArray(plugins)) {
1776
- plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1893
+ function mergeEvtNamespace(theNamespace, namespaces) {
1894
+ var newNamespaces;
1895
+ if (namespaces) {
1896
+ if (isArray(namespaces)) {
1897
+ newNamespaces = [theNamespace].concat(namespaces);
1777
1898
  }
1778
- return createProcessTelemetryUnloadContext(plugins || context.getNext(), core, startAt);
1899
+ else {
1900
+ newNamespaces = [theNamespace, namespaces];
1901
+ }
1902
+ newNamespaces = (_getEvtNamespace("xx", newNamespaces).ns).split(".");
1779
1903
  }
1780
- context.processNext = _processNext;
1781
- context.createNew = _createNew;
1782
- return context;
1783
- }
1784
- function createProcessTelemetryUpdateContext(telemetryChain, core, startAt) {
1785
- var config = core.config || {};
1786
- var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
1787
- var context = internalContext.ctx;
1788
- function _processNext(updateState) {
1789
- return context.iterate(function (plugin) {
1790
- if (isFunction(plugin.update)) {
1791
- plugin.update(context, updateState);
1792
- }
1793
- });
1904
+ else {
1905
+ newNamespaces = theNamespace;
1794
1906
  }
1795
- function _createNew(plugins, startAt) {
1796
- if (plugins === void 0) { plugins = null; }
1797
- if (isArray(plugins)) {
1798
- plugins = createTelemetryProxyChain(plugins, config, core, startAt);
1799
- }
1800
- return createProcessTelemetryUpdateContext(plugins || context.getNext(), core, startAt);
1801
- }
1802
- context.processNext = _processNext;
1803
- context.createNew = _createNew;
1804
- return context;
1907
+ return newNamespaces;
1805
1908
  }
1806
- function createTelemetryProxyChain(plugins, config, core, startAt) {
1807
- var firstProxy = null;
1808
- var add = startAt ? false : true;
1809
- if (isArray(plugins) && plugins.length > 0) {
1810
- var lastProxy_1 = null;
1811
- arrForEach(plugins, function (thePlugin) {
1812
- if (!add && startAt === thePlugin) {
1813
- add = true;
1814
- }
1815
- if (add && thePlugin && isFunction(thePlugin.processTelemetry)) {
1816
- var newProxy = createTelemetryPluginProxy(thePlugin, config, core);
1817
- if (!firstProxy) {
1818
- firstProxy = newProxy;
1819
- }
1820
- if (lastProxy_1) {
1821
- lastProxy_1._setNext(newProxy);
1822
- }
1823
- lastProxy_1 = newProxy;
1909
+ function eventOn(target, eventName, handlerRef, evtNamespace, useCapture) {
1910
+ if (useCapture === void 0) { useCapture = false; }
1911
+ var result = false;
1912
+ if (target) {
1913
+ try {
1914
+ var evtName = _getEvtNamespace(eventName, evtNamespace);
1915
+ result = _doAttach(target, evtName, handlerRef, useCapture);
1916
+ if (result && elmNodeData.accept(target)) {
1917
+ var registeredEvent = {
1918
+ guid: _guid++,
1919
+ evtName: evtName,
1920
+ handler: handlerRef,
1921
+ capture: useCapture
1922
+ };
1923
+ _getRegisteredEvents(target, evtName.type).push(registeredEvent);
1824
1924
  }
1825
- });
1826
- }
1827
- if (startAt && !firstProxy) {
1828
- return createTelemetryProxyChain([startAt], config, core);
1829
- }
1830
- return firstProxy;
1831
- }
1832
- function createTelemetryPluginProxy(plugin, config, core) {
1833
- var nextProxy = null;
1834
- var hasProcessTelemetry = isFunction(plugin.processTelemetry);
1835
- var hasSetNext = isFunction(plugin.setNextPlugin);
1836
- var chainId;
1837
- if (plugin) {
1838
- chainId = plugin.identifier + "-" + plugin.priority + "-" + _chainId++;
1839
- }
1840
- else {
1841
- chainId = "Unknown-0-" + _chainId++;
1842
- }
1843
- var proxyChain = {
1844
- getPlugin: function () {
1845
- return plugin;
1846
- },
1847
- getNext: function () {
1848
- return nextProxy;
1849
- },
1850
- processTelemetry: _processTelemetry,
1851
- unload: _unloadPlugin,
1852
- update: _updatePlugin,
1853
- _id: chainId,
1854
- _setNext: function (nextPlugin) {
1855
- nextProxy = nextPlugin;
1856
- }
1857
- };
1858
- function _getTelCtx() {
1859
- var itemCtx;
1860
- if (plugin && isFunction(plugin[strGetTelCtx])) {
1861
- itemCtx = plugin[strGetTelCtx]();
1862
1925
  }
1863
- if (!itemCtx) {
1864
- itemCtx = createProcessTelemetryContext(proxyChain, config, core);
1926
+ catch (e) {
1865
1927
  }
1866
- return itemCtx;
1867
1928
  }
1868
- function _processChain(itemCtx, processPluginFn, name, details, isAsync) {
1869
- var hasRun = false;
1870
- var identifier = plugin ? plugin.identifier : strTelemetryPluginChain;
1871
- var hasRunContext = itemCtx[strHasRunFlags];
1872
- if (!hasRunContext) {
1873
- hasRunContext = itemCtx[strHasRunFlags] = {};
1874
- }
1875
- itemCtx.setNext(nextProxy);
1876
- if (plugin) {
1877
- doPerf(itemCtx[strCore](), function () { return identifier + ":" + name; }, function () {
1878
- hasRunContext[chainId] = true;
1879
- try {
1880
- var nextId = nextProxy ? nextProxy._id : strEmpty$1;
1881
- if (nextId) {
1882
- hasRunContext[nextId] = false;
1883
- }
1884
- hasRun = processPluginFn(itemCtx);
1885
- }
1886
- catch (error) {
1887
- var hasNextRun = nextProxy ? hasRunContext[nextProxy._id] : true;
1888
- if (hasNextRun) {
1889
- hasRun = true;
1890
- }
1891
- if (!nextProxy || !hasNextRun) {
1892
- _throwInternal(itemCtx.diagLog(), 1 , 73 , "Plugin [" + identifier + "] failed during " + name + " - " + dumpObj(error) + ", run flags: " + dumpObj(hasRunContext));
1893
- }
1929
+ return result;
1930
+ }
1931
+ function eventOff(target, eventName, handlerRef, evtNamespace, useCapture) {
1932
+ if (useCapture === void 0) { useCapture = false; }
1933
+ if (target) {
1934
+ try {
1935
+ var evtName_1 = _getEvtNamespace(eventName, evtNamespace);
1936
+ var found_1 = false;
1937
+ _unregisterEvents(target, evtName_1, function (regEvent) {
1938
+ if ((evtName_1.ns && !handlerRef) || regEvent.handler === handlerRef) {
1939
+ found_1 = true;
1940
+ return true;
1894
1941
  }
1895
- }, details, isAsync);
1896
- }
1897
- return hasRun;
1898
- }
1899
- function _processTelemetry(env, itemCtx) {
1900
- itemCtx = itemCtx || _getTelCtx();
1901
- function _callProcessTelemetry(itemCtx) {
1902
- if (!plugin || !hasProcessTelemetry) {
1903
- return false;
1904
- }
1905
- var pluginState = _getPluginState(plugin);
1906
- if (pluginState.teardown || pluginState[strDisabled]) {
1907
1942
  return false;
1943
+ });
1944
+ if (!found_1) {
1945
+ _doDetach(target, evtName_1, handlerRef, useCapture);
1908
1946
  }
1909
- if (hasSetNext) {
1910
- plugin.setNextPlugin(nextProxy);
1911
- }
1912
- plugin.processTelemetry(env, itemCtx);
1913
- return true;
1914
1947
  }
1915
- if (!_processChain(itemCtx, _callProcessTelemetry, "processTelemetry", function () { return ({ item: env }); }, !(env.sync))) {
1916
- itemCtx.processNext(env);
1948
+ catch (e) {
1917
1949
  }
1918
1950
  }
1919
- function _unloadPlugin(unloadCtx, unloadState) {
1920
- function _callTeardown() {
1921
- var hasRun = false;
1922
- if (plugin) {
1923
- var pluginState = _getPluginState(plugin);
1924
- var pluginCore = plugin[strCore] || pluginState.core;
1925
- if (plugin && (!pluginCore || pluginCore === unloadCtx[strCore]()) && !pluginState[strTeardown]) {
1926
- pluginState[strCore] = null;
1927
- pluginState[strTeardown] = true;
1928
- pluginState[strIsInitialized] = false;
1929
- if (plugin[strTeardown] && plugin[strTeardown](unloadCtx, unloadState) === true) {
1930
- hasRun = true;
1931
- }
1932
- }
1933
- }
1934
- return hasRun;
1935
- }
1936
- if (!_processChain(unloadCtx, _callTeardown, "unload", function () { }, unloadState.isAsync)) {
1937
- unloadCtx.processNext(unloadState);
1938
- }
1951
+ }
1952
+ function addEventHandler(eventName, callback, evtNamespace) {
1953
+ var result = false;
1954
+ var w = getWindow();
1955
+ if (w) {
1956
+ result = eventOn(w, eventName, callback, evtNamespace);
1957
+ result = eventOn(w["body"], eventName, callback, evtNamespace) || result;
1939
1958
  }
1940
- function _updatePlugin(updateCtx, updateState) {
1941
- function _callUpdate() {
1942
- var hasRun = false;
1943
- if (plugin) {
1944
- var pluginState = _getPluginState(plugin);
1945
- var pluginCore = plugin[strCore] || pluginState.core;
1946
- if (plugin && (!pluginCore || pluginCore === updateCtx[strCore]()) && !pluginState[strTeardown]) {
1947
- if (plugin[strUpdate] && plugin[strUpdate](updateCtx, updateState) === true) {
1948
- hasRun = true;
1949
- }
1950
- }
1951
- }
1952
- return hasRun;
1953
- }
1954
- if (!_processChain(updateCtx, _callUpdate, "update", function () { }, false)) {
1955
- updateCtx.processNext(updateState);
1956
- }
1959
+ var doc = getDocument();
1960
+ if (doc) {
1961
+ result = eventOn(doc, eventName, callback, evtNamespace) || result;
1957
1962
  }
1958
- return objFreeze(proxyChain);
1963
+ return result;
1959
1964
  }
1960
1965
 
1961
- var strToGMTString = "toGMTString";
1962
- var strToUTCString = "toUTCString";
1963
- var strCookie = "cookie";
1964
- var strExpires = "expires";
1965
- var strEnabled = "enabled";
1966
- var strIsCookieUseDisabled = "isCookieUseDisabled";
1967
- var strDisableCookiesUsage = "disableCookiesUsage";
1968
- var strConfigCookieMgr = "_ckMgr";
1969
- var _supportsCookies = null;
1970
- var _allowUaSameSite = null;
1971
- var _parsedCookieValue = null;
1972
- var _doc = getDocument();
1973
- var _cookieCache = {};
1974
- var _globalCookieConfig = {};
1975
- function _gblCookieMgr(config, logger) {
1976
- var inst = createCookieMgr[strConfigCookieMgr] || _globalCookieConfig[strConfigCookieMgr];
1977
- if (!inst) {
1978
- inst = createCookieMgr[strConfigCookieMgr] = createCookieMgr(config, logger);
1979
- _globalCookieConfig[strConfigCookieMgr] = inst;
1980
- }
1981
- return inst;
1982
- }
1983
- function _isMgrEnabled(cookieMgr) {
1984
- if (cookieMgr) {
1985
- return cookieMgr.isEnabled();
1966
+ var _cookieMgrs = null;
1967
+ var _canUseCookies;
1968
+ function newGuid() {
1969
+ function randomHexDigit() {
1970
+ return randomValue(15);
1986
1971
  }
1987
- return true;
1972
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(GuidRegex, function (c) {
1973
+ var r = (randomHexDigit() | 0), v = (c === "x" ? r : r & 0x3 | 0x8);
1974
+ return v.toString(16);
1975
+ });
1988
1976
  }
1989
- function _createCookieMgrConfig(rootConfig) {
1990
- var cookieMgrCfg = rootConfig.cookieCfg = rootConfig.cookieCfg || {};
1991
- setValue(cookieMgrCfg, "domain", rootConfig.cookieDomain, isNotNullOrUndefined, isNullOrUndefined);
1992
- setValue(cookieMgrCfg, "path", rootConfig.cookiePath || "/", null, isNullOrUndefined);
1993
- if (isNullOrUndefined(cookieMgrCfg[strEnabled])) {
1994
- var cookieEnabled = void 0;
1995
- if (!isUndefined(rootConfig[strIsCookieUseDisabled])) {
1996
- cookieEnabled = !rootConfig[strIsCookieUseDisabled];
1997
- }
1998
- if (!isUndefined(rootConfig[strDisableCookiesUsage])) {
1999
- cookieEnabled = !rootConfig[strDisableCookiesUsage];
2000
- }
2001
- cookieMgrCfg[strEnabled] = cookieEnabled;
1977
+ function perfNow() {
1978
+ var perf = getPerformance();
1979
+ if (perf && perf.now) {
1980
+ return perf.now();
2002
1981
  }
2003
- return cookieMgrCfg;
1982
+ return dateNow();
2004
1983
  }
2005
- function createCookieMgr(rootConfig, logger) {
2006
- var cookieMgrConfig = _createCookieMgrConfig(rootConfig || _globalCookieConfig);
2007
- var _path = cookieMgrConfig.path || "/";
2008
- var _domain = cookieMgrConfig.domain;
2009
- var _enabled = cookieMgrConfig[strEnabled] !== false;
2010
- var cookieMgr = {
2011
- isEnabled: function () {
2012
- var enabled = _enabled && areCookiesSupported(logger);
2013
- var gblManager = _globalCookieConfig[strConfigCookieMgr];
2014
- if (enabled && gblManager && cookieMgr !== gblManager) {
2015
- enabled = _isMgrEnabled(gblManager);
1984
+ function generateW3CId() {
1985
+ var hexValues = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"];
1986
+ var oct = strEmpty$1, tmp;
1987
+ for (var a = 0; a < 4; a++) {
1988
+ tmp = random32();
1989
+ oct +=
1990
+ hexValues[tmp & 0xF] +
1991
+ hexValues[tmp >> 4 & 0xF] +
1992
+ hexValues[tmp >> 8 & 0xF] +
1993
+ hexValues[tmp >> 12 & 0xF] +
1994
+ hexValues[tmp >> 16 & 0xF] +
1995
+ hexValues[tmp >> 20 & 0xF] +
1996
+ hexValues[tmp >> 24 & 0xF] +
1997
+ hexValues[tmp >> 28 & 0xF];
1998
+ }
1999
+ var clockSequenceHi = hexValues[8 + (random32() & 0x03) | 0];
2000
+ return oct.substr(0, 8) + oct.substr(9, 4) + "4" + oct.substr(13, 3) + clockSequenceHi + oct.substr(16, 3) + oct.substr(19, 12);
2001
+ }
2002
+ var CoreUtils = {
2003
+ _canUseCookies: undefined,
2004
+ isTypeof: isTypeof,
2005
+ isUndefined: isUndefined,
2006
+ isNullOrUndefined: isNullOrUndefined,
2007
+ hasOwnProperty: hasOwnProperty,
2008
+ isFunction: isFunction,
2009
+ isObject: isObject,
2010
+ isDate: isDate,
2011
+ isArray: isArray,
2012
+ isError: isError,
2013
+ isString: isString,
2014
+ isNumber: isNumber,
2015
+ isBoolean: isBoolean,
2016
+ toISOString: toISOString,
2017
+ arrForEach: arrForEach,
2018
+ arrIndexOf: arrIndexOf,
2019
+ arrMap: arrMap,
2020
+ arrReduce: arrReduce,
2021
+ strTrim: strTrim,
2022
+ objCreate: objCreateFn,
2023
+ objKeys: objKeys,
2024
+ objDefineAccessors: objDefineAccessors,
2025
+ addEventHandler: addEventHandler,
2026
+ dateNow: dateNow,
2027
+ isIE: isIE,
2028
+ disableCookies: disableCookies,
2029
+ newGuid: newGuid,
2030
+ perfNow: perfNow,
2031
+ newId: newId,
2032
+ randomValue: randomValue,
2033
+ random32: random32,
2034
+ mwcRandomSeed: mwcRandomSeed,
2035
+ mwcRandom32: mwcRandom32,
2036
+ generateW3CId: generateW3CId
2037
+ };
2038
+ var GuidRegex = /[xy]/g;
2039
+ function _legacyCookieMgr(config, logger) {
2040
+ var cookieMgr = _gblCookieMgr(config, logger);
2041
+ var legacyCanUseCookies = CoreUtils._canUseCookies;
2042
+ if (_cookieMgrs === null) {
2043
+ _cookieMgrs = [];
2044
+ _canUseCookies = legacyCanUseCookies;
2045
+ objDefineAccessors(CoreUtils, "_canUseCookies", function () {
2046
+ return _canUseCookies;
2047
+ }, function (value) {
2048
+ _canUseCookies = value;
2049
+ arrForEach(_cookieMgrs, function (mgr) {
2050
+ mgr.setEnabled(value);
2051
+ });
2052
+ });
2053
+ }
2054
+ if (arrIndexOf(_cookieMgrs, cookieMgr) === -1) {
2055
+ _cookieMgrs.push(cookieMgr);
2056
+ }
2057
+ if (isBoolean(legacyCanUseCookies)) {
2058
+ cookieMgr.setEnabled(legacyCanUseCookies);
2059
+ }
2060
+ if (isBoolean(_canUseCookies)) {
2061
+ cookieMgr.setEnabled(_canUseCookies);
2062
+ }
2063
+ return cookieMgr;
2064
+ }
2065
+ function disableCookies() {
2066
+ _legacyCookieMgr().setEnabled(false);
2067
+ }
2068
+
2069
+ var INVALID_TRACE_ID = "00000000000000000000000000000000";
2070
+ var INVALID_SPAN_ID = "0000000000000000";
2071
+ function _isValid(value, len, invalidValue) {
2072
+ if (value && value.length === len && value !== invalidValue) {
2073
+ return !!value.match(/^[\da-f]*$/);
2074
+ }
2075
+ return false;
2076
+ }
2077
+ function isValidTraceId(value) {
2078
+ return _isValid(value, 32, INVALID_TRACE_ID);
2079
+ }
2080
+ function isValidSpanId(value) {
2081
+ return _isValid(value, 16, INVALID_SPAN_ID);
2082
+ }
2083
+
2084
+ var pluginStateData = createElmNodeData("plugin");
2085
+ function _getPluginState(plugin) {
2086
+ return pluginStateData.get(plugin, "state", {}, true);
2087
+ }
2088
+ function initializePlugins(processContext, extensions) {
2089
+ var initPlugins = [];
2090
+ var lastPlugin = null;
2091
+ var proxy = processContext.getNext();
2092
+ var pluginState;
2093
+ while (proxy) {
2094
+ var thePlugin = proxy.getPlugin();
2095
+ if (thePlugin) {
2096
+ if (lastPlugin &&
2097
+ isFunction(lastPlugin[strSetNextPlugin]) &&
2098
+ isFunction(thePlugin[strProcessTelemetry])) {
2099
+ lastPlugin[strSetNextPlugin](thePlugin);
2016
2100
  }
2017
- return enabled;
2101
+ var isInitialized = false;
2102
+ if (isFunction(thePlugin[strIsInitialized])) {
2103
+ isInitialized = thePlugin[strIsInitialized]();
2104
+ }
2105
+ else {
2106
+ pluginState = _getPluginState(thePlugin);
2107
+ isInitialized = pluginState[strIsInitialized];
2108
+ }
2109
+ if (!isInitialized) {
2110
+ initPlugins.push(thePlugin);
2111
+ }
2112
+ lastPlugin = thePlugin;
2113
+ proxy = proxy.getNext();
2114
+ }
2115
+ }
2116
+ arrForEach(initPlugins, function (thePlugin) {
2117
+ var core = processContext.core();
2118
+ thePlugin.initialize(processContext.getCfg(), core, extensions, processContext.getNext());
2119
+ pluginState = _getPluginState(thePlugin);
2120
+ if (!thePlugin[strCore] && !pluginState[strCore]) {
2121
+ pluginState[strCore] = core;
2122
+ }
2123
+ pluginState[strIsInitialized] = true;
2124
+ delete pluginState[strTeardown];
2125
+ });
2126
+ }
2127
+ function sortPlugins(plugins) {
2128
+ return plugins.sort(function (extA, extB) {
2129
+ var result = 0;
2130
+ if (extB) {
2131
+ var bHasProcess = isFunction(extB[strProcessTelemetry]);
2132
+ if (isFunction(extA[strProcessTelemetry])) {
2133
+ result = bHasProcess ? extA[strPriority] - extB[strPriority] : 1;
2134
+ }
2135
+ else if (bHasProcess) {
2136
+ result = -1;
2137
+ }
2138
+ }
2139
+ else {
2140
+ result = extA ? 1 : -1;
2141
+ }
2142
+ return result;
2143
+ });
2144
+ }
2145
+ function createDistributedTraceContext(parentCtx) {
2146
+ var trace = {};
2147
+ return {
2148
+ getName: function () {
2149
+ return trace.name;
2018
2150
  },
2019
- setEnabled: function (value) {
2020
- _enabled = value !== false;
2151
+ setName: function (newValue) {
2152
+ parentCtx && parentCtx.setName(newValue);
2153
+ trace.name = newValue;
2021
2154
  },
2022
- set: function (name, value, maxAgeSec, domain, path) {
2023
- var result = false;
2024
- if (_isMgrEnabled(cookieMgr)) {
2025
- var values = {};
2026
- var theValue = strTrim(value || strEmpty$1);
2027
- var idx = theValue.indexOf(";");
2028
- if (idx !== -1) {
2029
- theValue = strTrim(value.substring(0, idx));
2030
- values = _extractParts(value.substring(idx + 1));
2031
- }
2032
- setValue(values, "domain", domain || _domain, isTruthy, isUndefined);
2033
- if (!isNullOrUndefined(maxAgeSec)) {
2034
- var _isIE = isIE();
2035
- if (isUndefined(values[strExpires])) {
2036
- var nowMs = dateNow();
2037
- var expireMs = nowMs + (maxAgeSec * 1000);
2038
- if (expireMs > 0) {
2039
- var expiry = new Date();
2040
- expiry.setTime(expireMs);
2041
- setValue(values, strExpires, _formatDate(expiry, !_isIE ? strToUTCString : strToGMTString) || _formatDate(expiry, _isIE ? strToGMTString : strToUTCString) || strEmpty$1, isTruthy);
2042
- }
2043
- }
2044
- if (!_isIE) {
2045
- setValue(values, "max-age", strEmpty$1 + maxAgeSec, null, isUndefined);
2046
- }
2047
- }
2048
- var location_1 = getLocation();
2049
- if (location_1 && location_1.protocol === "https:") {
2050
- setValue(values, "secure", null, null, isUndefined);
2051
- if (_allowUaSameSite === null) {
2052
- _allowUaSameSite = !uaDisallowsSameSiteNone((getNavigator() || {}).userAgent);
2053
- }
2054
- if (_allowUaSameSite) {
2055
- setValue(values, "SameSite", "None", null, isUndefined);
2056
- }
2057
- }
2058
- setValue(values, "path", path || _path, null, isUndefined);
2059
- var setCookieFn = cookieMgrConfig.setCookie || _setCookieValue;
2060
- setCookieFn(name, _formatCookieValue(theValue, values));
2061
- result = true;
2062
- }
2063
- return result;
2155
+ getTraceId: function () {
2156
+ return trace.traceId;
2064
2157
  },
2065
- get: function (name) {
2066
- var value = strEmpty$1;
2067
- if (_isMgrEnabled(cookieMgr)) {
2068
- value = (cookieMgrConfig.getCookie || _getCookieValue)(name);
2158
+ setTraceId: function (newValue) {
2159
+ parentCtx && parentCtx.setTraceId(newValue);
2160
+ if (isValidTraceId(newValue)) {
2161
+ trace.traceId = newValue;
2069
2162
  }
2070
- return value;
2071
2163
  },
2072
- del: function (name, path) {
2073
- var result = false;
2074
- if (_isMgrEnabled(cookieMgr)) {
2075
- result = cookieMgr.purge(name, path);
2076
- }
2077
- return result;
2164
+ getSpanId: function () {
2165
+ return trace.spanId;
2078
2166
  },
2079
- purge: function (name, path) {
2080
- var _a;
2081
- var result = false;
2082
- if (areCookiesSupported(logger)) {
2083
- var values = (_a = {},
2084
- _a["path"] = path ? path : "/",
2085
- _a[strExpires] = "Thu, 01 Jan 1970 00:00:01 GMT",
2086
- _a);
2087
- if (!isIE()) {
2088
- values["max-age"] = "0";
2089
- }
2090
- var delCookie = cookieMgrConfig.delCookie || _setCookieValue;
2091
- delCookie(name, _formatCookieValue(strEmpty$1, values));
2092
- result = true;
2167
+ setSpanId: function (newValue) {
2168
+ parentCtx && parentCtx.setSpanId(newValue);
2169
+ if (isValidSpanId(newValue)) {
2170
+ trace.spanId = newValue;
2093
2171
  }
2094
- return result;
2172
+ },
2173
+ getTraceFlags: function () {
2174
+ return trace.traceFlags;
2175
+ },
2176
+ setTraceFlags: function (newTraceFlags) {
2177
+ parentCtx && parentCtx.setTraceFlags(newTraceFlags);
2178
+ trace.traceFlags = newTraceFlags;
2095
2179
  }
2096
2180
  };
2097
- cookieMgr[strConfigCookieMgr] = cookieMgr;
2098
- return cookieMgr;
2099
2181
  }
2100
- function areCookiesSupported(logger) {
2101
- if (_supportsCookies === null) {
2102
- _supportsCookies = false;
2103
- try {
2104
- var doc = _doc || {};
2105
- _supportsCookies = doc[strCookie] !== undefined;
2106
- }
2107
- catch (e) {
2108
- _throwInternal(logger, 2 , 68 , "Cannot access document.cookie - " + getExceptionName(e), { exception: dumpObj(e) });
2182
+
2183
+ var strTelemetryPluginChain = "TelemetryPluginChain";
2184
+ var strHasRunFlags = "_hasRun";
2185
+ var strGetTelCtx = "_getTelCtx";
2186
+ var _chainId = 0;
2187
+ function _getNextProxyStart(proxy, core, startAt) {
2188
+ while (proxy) {
2189
+ if (proxy.getPlugin() === startAt) {
2190
+ return proxy;
2109
2191
  }
2192
+ proxy = proxy.getNext();
2110
2193
  }
2111
- return _supportsCookies;
2194
+ return createTelemetryProxyChain([startAt], core.config || {}, core);
2112
2195
  }
2113
- function _extractParts(theValue) {
2114
- var values = {};
2115
- if (theValue && theValue.length) {
2116
- var parts = strTrim(theValue).split(";");
2117
- arrForEach(parts, function (thePart) {
2118
- thePart = strTrim(thePart || strEmpty$1);
2119
- if (thePart) {
2120
- var idx = thePart.indexOf("=");
2121
- if (idx === -1) {
2122
- values[thePart] = null;
2123
- }
2124
- else {
2125
- values[strTrim(thePart.substring(0, idx))] = strTrim(thePart.substring(idx + 1));
2126
- }
2196
+ function _createInternalContext(telemetryChain, config, core, startAt) {
2197
+ var _nextProxy = null;
2198
+ var _onComplete = [];
2199
+ if (startAt !== null) {
2200
+ _nextProxy = startAt ? _getNextProxyStart(telemetryChain, core, startAt) : telemetryChain;
2201
+ }
2202
+ var context = {
2203
+ _next: _moveNext,
2204
+ ctx: {
2205
+ core: function () {
2206
+ return core;
2207
+ },
2208
+ diagLog: function () {
2209
+ return safeGetLogger(core, config);
2210
+ },
2211
+ getCfg: function () {
2212
+ return config;
2213
+ },
2214
+ getExtCfg: _getExtCfg,
2215
+ getConfig: _getConfig,
2216
+ hasNext: function () {
2217
+ return !!_nextProxy;
2218
+ },
2219
+ getNext: function () {
2220
+ return _nextProxy;
2221
+ },
2222
+ setNext: function (nextPlugin) {
2223
+ _nextProxy = nextPlugin;
2224
+ },
2225
+ iterate: _iterateChain,
2226
+ onComplete: _addOnComplete
2227
+ }
2228
+ };
2229
+ function _addOnComplete(onComplete, that) {
2230
+ var args = [];
2231
+ for (var _i = 2; _i < arguments.length; _i++) {
2232
+ args[_i - 2] = arguments[_i];
2233
+ }
2234
+ if (onComplete) {
2235
+ _onComplete.push({
2236
+ func: onComplete,
2237
+ self: !isUndefined(that) ? that : context.ctx,
2238
+ args: args
2239
+ });
2240
+ }
2241
+ }
2242
+ function _moveNext() {
2243
+ var nextProxy = _nextProxy;
2244
+ _nextProxy = nextProxy ? nextProxy.getNext() : null;
2245
+ if (!nextProxy) {
2246
+ var onComplete = _onComplete;
2247
+ if (onComplete && onComplete.length > 0) {
2248
+ arrForEach(onComplete, function (completeDetails) {
2249
+ try {
2250
+ completeDetails.func.call(completeDetails.self, completeDetails.args);
2251
+ }
2252
+ catch (e) {
2253
+ _throwInternal(core.logger, 2 , 73 , "Unexpected Exception during onComplete - " + dumpObj(e));
2254
+ }
2255
+ });
2256
+ _onComplete = [];
2127
2257
  }
2128
- });
2258
+ }
2259
+ return nextProxy;
2129
2260
  }
2130
- return values;
2131
- }
2132
- function _formatDate(theDate, func) {
2133
- if (isFunction(theDate[func])) {
2134
- return theDate[func]();
2261
+ function _getExtCfg(identifier, defaultValue, mergeDefault) {
2262
+ if (defaultValue === void 0) { defaultValue = {}; }
2263
+ if (mergeDefault === void 0) { mergeDefault = 0 ; }
2264
+ var theConfig;
2265
+ if (config) {
2266
+ var extConfig = config.extensionConfig;
2267
+ if (extConfig && identifier) {
2268
+ theConfig = extConfig[identifier];
2269
+ }
2270
+ }
2271
+ if (!theConfig) {
2272
+ theConfig = defaultValue;
2273
+ }
2274
+ else if (isObject(defaultValue)) {
2275
+ if (mergeDefault !== 0 ) {
2276
+ var newConfig_1 = objExtend(true, defaultValue, theConfig);
2277
+ if (config && mergeDefault === 2 ) {
2278
+ objForEachKey(defaultValue, function (field) {
2279
+ if (isNullOrUndefined(newConfig_1[field])) {
2280
+ var cfgValue = config[field];
2281
+ if (!isNullOrUndefined(cfgValue)) {
2282
+ newConfig_1[field] = cfgValue;
2283
+ }
2284
+ }
2285
+ });
2286
+ }
2287
+ theConfig = newConfig_1;
2288
+ }
2289
+ }
2290
+ return theConfig;
2135
2291
  }
2136
- return null;
2137
- }
2138
- function _formatCookieValue(value, values) {
2139
- var cookieValue = value || strEmpty$1;
2140
- objForEachKey(values, function (name, theValue) {
2141
- cookieValue += "; " + name + (!isNullOrUndefined(theValue) ? "=" + theValue : strEmpty$1);
2142
- });
2143
- return cookieValue;
2144
- }
2145
- function _getCookieValue(name) {
2146
- var cookieValue = strEmpty$1;
2147
- if (_doc) {
2148
- var theCookie = _doc[strCookie] || strEmpty$1;
2149
- if (_parsedCookieValue !== theCookie) {
2150
- _cookieCache = _extractParts(theCookie);
2151
- _parsedCookieValue = theCookie;
2292
+ function _getConfig(identifier, field, defaultValue) {
2293
+ if (defaultValue === void 0) { defaultValue = false; }
2294
+ var theValue;
2295
+ var extConfig = _getExtCfg(identifier, null);
2296
+ if (extConfig && !isNullOrUndefined(extConfig[field])) {
2297
+ theValue = extConfig[field];
2152
2298
  }
2153
- cookieValue = strTrim(_cookieCache[name] || strEmpty$1);
2299
+ else if (config && !isNullOrUndefined(config[field])) {
2300
+ theValue = config[field];
2301
+ }
2302
+ return !isNullOrUndefined(theValue) ? theValue : defaultValue;
2154
2303
  }
2155
- return cookieValue;
2156
- }
2157
- function _setCookieValue(name, cookieValue) {
2158
- if (_doc) {
2159
- _doc[strCookie] = name + "=" + cookieValue;
2304
+ function _iterateChain(cb) {
2305
+ var nextPlugin;
2306
+ while (!!(nextPlugin = context._next())) {
2307
+ var plugin = nextPlugin.getPlugin();
2308
+ if (plugin) {
2309
+ cb(plugin);
2310
+ }
2311
+ }
2160
2312
  }
2313
+ return context;
2161
2314
  }
2162
- function uaDisallowsSameSiteNone(userAgent) {
2163
- if (!isString(userAgent)) {
2164
- return false;
2165
- }
2166
- if (strContains(userAgent, "CPU iPhone OS 12") || strContains(userAgent, "iPad; CPU OS 12")) {
2167
- return true;
2315
+ function createProcessTelemetryContext(telemetryChain, config, core, startAt) {
2316
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
2317
+ var context = internalContext.ctx;
2318
+ function _processNext(env) {
2319
+ var nextPlugin = internalContext._next();
2320
+ nextPlugin && nextPlugin.processTelemetry(env, context);
2321
+ return !nextPlugin;
2168
2322
  }
2169
- if (strContains(userAgent, "Macintosh; Intel Mac OS X 10_14") && strContains(userAgent, "Version/") && strContains(userAgent, "Safari")) {
2170
- return true;
2323
+ function _createNew(plugins, startAt) {
2324
+ if (plugins === void 0) { plugins = null; }
2325
+ if (isArray(plugins)) {
2326
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
2327
+ }
2328
+ return createProcessTelemetryContext(plugins || context.getNext(), config, core, startAt);
2171
2329
  }
2172
- if (strContains(userAgent, "Macintosh; Intel Mac OS X 10_14") && strEndsWith(userAgent, "AppleWebKit/605.1.15 (KHTML, like Gecko)")) {
2173
- return true;
2330
+ context.processNext = _processNext;
2331
+ context.createNew = _createNew;
2332
+ return context;
2333
+ }
2334
+ function createProcessTelemetryUnloadContext(telemetryChain, core, startAt) {
2335
+ var config = core.config || {};
2336
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
2337
+ var context = internalContext.ctx;
2338
+ function _processNext(unloadState) {
2339
+ var nextPlugin = internalContext._next();
2340
+ nextPlugin && nextPlugin.unload(context, unloadState);
2341
+ return !nextPlugin;
2174
2342
  }
2175
- if (strContains(userAgent, "Chrome/5") || strContains(userAgent, "Chrome/6")) {
2176
- return true;
2343
+ function _createNew(plugins, startAt) {
2344
+ if (plugins === void 0) { plugins = null; }
2345
+ if (isArray(plugins)) {
2346
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
2347
+ }
2348
+ return createProcessTelemetryUnloadContext(plugins || context.getNext(), core, startAt);
2177
2349
  }
2178
- if (strContains(userAgent, "UnrealEngine") && !strContains(userAgent, "Chrome")) {
2179
- return true;
2350
+ context.processNext = _processNext;
2351
+ context.createNew = _createNew;
2352
+ return context;
2353
+ }
2354
+ function createProcessTelemetryUpdateContext(telemetryChain, core, startAt) {
2355
+ var config = core.config || {};
2356
+ var internalContext = _createInternalContext(telemetryChain, config, core, startAt);
2357
+ var context = internalContext.ctx;
2358
+ function _processNext(updateState) {
2359
+ return context.iterate(function (plugin) {
2360
+ if (isFunction(plugin.update)) {
2361
+ plugin.update(context, updateState);
2362
+ }
2363
+ });
2180
2364
  }
2181
- if (strContains(userAgent, "UCBrowser/12") || strContains(userAgent, "UCBrowser/11")) {
2182
- return true;
2365
+ function _createNew(plugins, startAt) {
2366
+ if (plugins === void 0) { plugins = null; }
2367
+ if (isArray(plugins)) {
2368
+ plugins = createTelemetryProxyChain(plugins, config, core, startAt);
2369
+ }
2370
+ return createProcessTelemetryUpdateContext(plugins || context.getNext(), core, startAt);
2183
2371
  }
2184
- return false;
2372
+ context.processNext = _processNext;
2373
+ context.createNew = _createNew;
2374
+ return context;
2185
2375
  }
2186
-
2187
- var strIKey = "iKey";
2188
- var strExtensionConfig = "extensionConfig";
2189
-
2190
- var ChannelControllerPriority = 500;
2191
- var ChannelValidationMessage = "Channel has invalid priority - ";
2192
- function _addChannelQueue(channelQueue, queue, config, core) {
2193
- if (queue && isArray(queue) && queue.length > 0) {
2194
- queue = queue.sort(function (a, b) {
2195
- return a.priority - b.priority;
2196
- });
2197
- arrForEach(queue, function (queueItem) {
2198
- if (queueItem.priority < ChannelControllerPriority) {
2199
- throwError(ChannelValidationMessage + queueItem.identifier);
2376
+ function createTelemetryProxyChain(plugins, config, core, startAt) {
2377
+ var firstProxy = null;
2378
+ var add = startAt ? false : true;
2379
+ if (isArray(plugins) && plugins.length > 0) {
2380
+ var lastProxy_1 = null;
2381
+ arrForEach(plugins, function (thePlugin) {
2382
+ if (!add && startAt === thePlugin) {
2383
+ add = true;
2384
+ }
2385
+ if (add && thePlugin && isFunction(thePlugin.processTelemetry)) {
2386
+ var newProxy = createTelemetryPluginProxy(thePlugin, config, core);
2387
+ if (!firstProxy) {
2388
+ firstProxy = newProxy;
2389
+ }
2390
+ if (lastProxy_1) {
2391
+ lastProxy_1._setNext(newProxy);
2392
+ }
2393
+ lastProxy_1 = newProxy;
2200
2394
  }
2201
- });
2202
- channelQueue.push({
2203
- queue: objFreeze(queue),
2204
- chain: createTelemetryProxyChain(queue, config, core)
2205
2395
  });
2206
2396
  }
2207
- }
2208
- function createChannelControllerPlugin(channelQueue, core) {
2209
- var _a;
2210
- function _getTelCtx() {
2211
- return createProcessTelemetryContext(null, core.config, core, null);
2397
+ if (startAt && !firstProxy) {
2398
+ return createTelemetryProxyChain([startAt], config, core);
2399
+ }
2400
+ return firstProxy;
2401
+ }
2402
+ function createTelemetryPluginProxy(plugin, config, core) {
2403
+ var nextProxy = null;
2404
+ var hasProcessTelemetry = isFunction(plugin.processTelemetry);
2405
+ var hasSetNext = isFunction(plugin.setNextPlugin);
2406
+ var chainId;
2407
+ if (plugin) {
2408
+ chainId = plugin.identifier + "-" + plugin.priority + "-" + _chainId++;
2409
+ }
2410
+ else {
2411
+ chainId = "Unknown-0-" + _chainId++;
2412
+ }
2413
+ var proxyChain = {
2414
+ getPlugin: function () {
2415
+ return plugin;
2416
+ },
2417
+ getNext: function () {
2418
+ return nextProxy;
2419
+ },
2420
+ processTelemetry: _processTelemetry,
2421
+ unload: _unloadPlugin,
2422
+ update: _updatePlugin,
2423
+ _id: chainId,
2424
+ _setNext: function (nextPlugin) {
2425
+ nextProxy = nextPlugin;
2426
+ }
2427
+ };
2428
+ function _getTelCtx() {
2429
+ var itemCtx;
2430
+ if (plugin && isFunction(plugin[strGetTelCtx])) {
2431
+ itemCtx = plugin[strGetTelCtx]();
2432
+ }
2433
+ if (!itemCtx) {
2434
+ itemCtx = createProcessTelemetryContext(proxyChain, config, core);
2435
+ }
2436
+ return itemCtx;
2437
+ }
2438
+ function _processChain(itemCtx, processPluginFn, name, details, isAsync) {
2439
+ var hasRun = false;
2440
+ var identifier = plugin ? plugin.identifier : strTelemetryPluginChain;
2441
+ var hasRunContext = itemCtx[strHasRunFlags];
2442
+ if (!hasRunContext) {
2443
+ hasRunContext = itemCtx[strHasRunFlags] = {};
2444
+ }
2445
+ itemCtx.setNext(nextProxy);
2446
+ if (plugin) {
2447
+ doPerf(itemCtx[strCore](), function () { return identifier + ":" + name; }, function () {
2448
+ hasRunContext[chainId] = true;
2449
+ try {
2450
+ var nextId = nextProxy ? nextProxy._id : strEmpty$1;
2451
+ if (nextId) {
2452
+ hasRunContext[nextId] = false;
2453
+ }
2454
+ hasRun = processPluginFn(itemCtx);
2455
+ }
2456
+ catch (error) {
2457
+ var hasNextRun = nextProxy ? hasRunContext[nextProxy._id] : true;
2458
+ if (hasNextRun) {
2459
+ hasRun = true;
2460
+ }
2461
+ if (!nextProxy || !hasNextRun) {
2462
+ _throwInternal(itemCtx.diagLog(), 1 , 73 , "Plugin [" + identifier + "] failed during " + name + " - " + dumpObj(error) + ", run flags: " + dumpObj(hasRunContext));
2463
+ }
2464
+ }
2465
+ }, details, isAsync);
2466
+ }
2467
+ return hasRun;
2468
+ }
2469
+ function _processTelemetry(env, itemCtx) {
2470
+ itemCtx = itemCtx || _getTelCtx();
2471
+ function _callProcessTelemetry(itemCtx) {
2472
+ if (!plugin || !hasProcessTelemetry) {
2473
+ return false;
2474
+ }
2475
+ var pluginState = _getPluginState(plugin);
2476
+ if (pluginState.teardown || pluginState[strDisabled]) {
2477
+ return false;
2478
+ }
2479
+ if (hasSetNext) {
2480
+ plugin.setNextPlugin(nextProxy);
2481
+ }
2482
+ plugin.processTelemetry(env, itemCtx);
2483
+ return true;
2484
+ }
2485
+ if (!_processChain(itemCtx, _callProcessTelemetry, "processTelemetry", function () { return ({ item: env }); }, !(env.sync))) {
2486
+ itemCtx.processNext(env);
2487
+ }
2488
+ }
2489
+ function _unloadPlugin(unloadCtx, unloadState) {
2490
+ function _callTeardown() {
2491
+ var hasRun = false;
2492
+ if (plugin) {
2493
+ var pluginState = _getPluginState(plugin);
2494
+ var pluginCore = plugin[strCore] || pluginState.core;
2495
+ if (plugin && (!pluginCore || pluginCore === unloadCtx[strCore]()) && !pluginState[strTeardown]) {
2496
+ pluginState[strCore] = null;
2497
+ pluginState[strTeardown] = true;
2498
+ pluginState[strIsInitialized] = false;
2499
+ if (plugin[strTeardown] && plugin[strTeardown](unloadCtx, unloadState) === true) {
2500
+ hasRun = true;
2501
+ }
2502
+ }
2503
+ }
2504
+ return hasRun;
2505
+ }
2506
+ if (!_processChain(unloadCtx, _callTeardown, "unload", function () { }, unloadState.isAsync)) {
2507
+ unloadCtx.processNext(unloadState);
2508
+ }
2509
+ }
2510
+ function _updatePlugin(updateCtx, updateState) {
2511
+ function _callUpdate() {
2512
+ var hasRun = false;
2513
+ if (plugin) {
2514
+ var pluginState = _getPluginState(plugin);
2515
+ var pluginCore = plugin[strCore] || pluginState.core;
2516
+ if (plugin && (!pluginCore || pluginCore === updateCtx[strCore]()) && !pluginState[strTeardown]) {
2517
+ if (plugin[strUpdate] && plugin[strUpdate](updateCtx, updateState) === true) {
2518
+ hasRun = true;
2519
+ }
2520
+ }
2521
+ }
2522
+ return hasRun;
2523
+ }
2524
+ if (!_processChain(updateCtx, _callUpdate, "update", function () { }, false)) {
2525
+ updateCtx.processNext(updateState);
2526
+ }
2527
+ }
2528
+ return objFreeze(proxyChain);
2529
+ }
2530
+
2531
+ var strIKey = "iKey";
2532
+ var strExtensionConfig = "extensionConfig";
2533
+
2534
+ var ChannelControllerPriority = 500;
2535
+ var ChannelValidationMessage = "Channel has invalid priority - ";
2536
+ function _addChannelQueue(channelQueue, queue, config, core) {
2537
+ if (queue && isArray(queue) && queue.length > 0) {
2538
+ queue = queue.sort(function (a, b) {
2539
+ return a.priority - b.priority;
2540
+ });
2541
+ arrForEach(queue, function (queueItem) {
2542
+ if (queueItem.priority < ChannelControllerPriority) {
2543
+ throwError(ChannelValidationMessage + queueItem.identifier);
2544
+ }
2545
+ });
2546
+ channelQueue.push({
2547
+ queue: objFreeze(queue),
2548
+ chain: createTelemetryProxyChain(queue, config, core)
2549
+ });
2550
+ }
2551
+ }
2552
+ function createChannelControllerPlugin(channelQueue, core) {
2553
+ var _a;
2554
+ function _getTelCtx() {
2555
+ return createProcessTelemetryContext(null, core.config, core, null);
2212
2556
  }
2213
2557
  function _processChannelQueue(theChannels, itemCtx, processFn, onComplete) {
2214
2558
  var waiting = theChannels ? (theChannels.length + 1) : 1;
@@ -2694,6 +3038,7 @@
2694
3038
  var _evtNamespace;
2695
3039
  var _unloadHandlers;
2696
3040
  var _debugListener;
3041
+ var _traceCtx;
2697
3042
  var _internalLogPoller = 0;
2698
3043
  dynamicProto(BaseCore, this, function (_self) {
2699
3044
  _initDefaults();
@@ -2896,6 +3241,15 @@
2896
3241
  return _evtNamespace;
2897
3242
  };
2898
3243
  _self.flush = _flushChannels;
3244
+ _self.getTraceCtx = function (createNew) {
3245
+ if (!_traceCtx) {
3246
+ _traceCtx = createDistributedTraceContext();
3247
+ }
3248
+ return _traceCtx;
3249
+ };
3250
+ _self.setTraceCtx = function (traceCtx) {
3251
+ _traceCtx = traceCtx || null;
3252
+ };
2899
3253
  proxyFunctionAs(_self, "addUnloadCb", function () { return _unloadHandlers; }, "add");
2900
3254
  function _initDefaults() {
2901
3255
  _isInitialized = false;
@@ -2918,6 +3272,7 @@
2918
3272
  _internalLogsEventName = null;
2919
3273
  _evtNamespace = createUniqueNamespace("AIBaseCore", true);
2920
3274
  _unloadHandlers = createUnloadHandlerContainer();
3275
+ _traceCtx = null;
2921
3276
  }
2922
3277
  function _createTelCtx() {
2923
3278
  return createProcessTelemetryContext(_getPluginChain(), _self.config, _self);
@@ -3211,293 +3566,6 @@
3211
3566
  return AppInsightsCore;
3212
3567
  }(BaseCore));
3213
3568
 
3214
- var strOnPrefix = "on";
3215
- var strAttachEvent = "attachEvent";
3216
- var strAddEventHelper = "addEventListener";
3217
- var strDetachEvent = "detachEvent";
3218
- var strRemoveEventListener = "removeEventListener";
3219
- var strEvents = "events";
3220
- createUniqueNamespace("aiEvtPageHide");
3221
- createUniqueNamespace("aiEvtPageShow");
3222
- var rRemoveEmptyNs = /\.[\.]+/g;
3223
- var rRemoveTrailingEmptyNs = /[\.]+$/;
3224
- var _guid = 1;
3225
- var elmNodeData = createElmNodeData("events");
3226
- var eventNamespace = /^([^.]*)(?:\.(.+)|)/;
3227
- function _normalizeNamespace(name) {
3228
- if (name && name.replace) {
3229
- return name.replace(/^\s*\.*|\.*\s*$/g, "");
3230
- }
3231
- return name;
3232
- }
3233
- function _getEvtNamespace(eventName, evtNamespace) {
3234
- if (evtNamespace) {
3235
- var theNamespace_1 = "";
3236
- if (isArray(evtNamespace)) {
3237
- theNamespace_1 = "";
3238
- arrForEach(evtNamespace, function (name) {
3239
- name = _normalizeNamespace(name);
3240
- if (name) {
3241
- if (name[0] !== ".") {
3242
- name = "." + name;
3243
- }
3244
- theNamespace_1 += name;
3245
- }
3246
- });
3247
- }
3248
- else {
3249
- theNamespace_1 = _normalizeNamespace(evtNamespace);
3250
- }
3251
- if (theNamespace_1) {
3252
- if (theNamespace_1[0] !== ".") {
3253
- theNamespace_1 = "." + theNamespace_1;
3254
- }
3255
- eventName = (eventName || "") + theNamespace_1;
3256
- }
3257
- }
3258
- var parsedEvent = (eventNamespace.exec(eventName || "") || []);
3259
- return {
3260
- type: parsedEvent[1],
3261
- ns: ((parsedEvent[2] || "").replace(rRemoveEmptyNs, ".").replace(rRemoveTrailingEmptyNs, "").split(".").sort()).join(".")
3262
- };
3263
- }
3264
- function _getRegisteredEvents(target, evtName, addDefault) {
3265
- if (addDefault === void 0) { addDefault = true; }
3266
- var aiEvts = elmNodeData.get(target, strEvents, {}, addDefault);
3267
- var registeredEvents = aiEvts[evtName];
3268
- if (!registeredEvents) {
3269
- registeredEvents = aiEvts[evtName] = [];
3270
- }
3271
- return registeredEvents;
3272
- }
3273
- function _doDetach(obj, evtName, handlerRef, useCapture) {
3274
- if (obj && evtName && evtName.type) {
3275
- if (obj[strRemoveEventListener]) {
3276
- obj[strRemoveEventListener](evtName.type, handlerRef, useCapture);
3277
- }
3278
- else if (obj[strDetachEvent]) {
3279
- obj[strDetachEvent](strOnPrefix + evtName.type, handlerRef);
3280
- }
3281
- }
3282
- }
3283
- function _doAttach(obj, evtName, handlerRef, useCapture) {
3284
- var result = false;
3285
- if (obj && evtName && evtName.type && handlerRef) {
3286
- if (obj[strAddEventHelper]) {
3287
- obj[strAddEventHelper](evtName.type, handlerRef, useCapture);
3288
- result = true;
3289
- }
3290
- else if (obj[strAttachEvent]) {
3291
- obj[strAttachEvent](strOnPrefix + evtName.type, handlerRef);
3292
- result = true;
3293
- }
3294
- }
3295
- return result;
3296
- }
3297
- function _doUnregister(target, events, evtName, unRegFn) {
3298
- var idx = events.length;
3299
- while (idx--) {
3300
- var theEvent = events[idx];
3301
- if (theEvent) {
3302
- if (!evtName.ns || evtName.ns === theEvent.evtName.ns) {
3303
- if (!unRegFn || unRegFn(theEvent)) {
3304
- _doDetach(target, theEvent.evtName, theEvent.handler, theEvent.capture);
3305
- events.splice(idx, 1);
3306
- }
3307
- }
3308
- }
3309
- }
3310
- }
3311
- function _unregisterEvents(target, evtName, unRegFn) {
3312
- if (evtName.type) {
3313
- _doUnregister(target, _getRegisteredEvents(target, evtName.type), evtName, unRegFn);
3314
- }
3315
- else {
3316
- var eventCache = elmNodeData.get(target, strEvents, {});
3317
- objForEachKey(eventCache, function (evtType, events) {
3318
- _doUnregister(target, events, evtName, unRegFn);
3319
- });
3320
- if (objKeys(eventCache).length === 0) {
3321
- elmNodeData.kill(target, strEvents);
3322
- }
3323
- }
3324
- }
3325
- function mergeEvtNamespace(theNamespace, namespaces) {
3326
- var newNamespaces;
3327
- if (namespaces) {
3328
- if (isArray(namespaces)) {
3329
- newNamespaces = [theNamespace].concat(namespaces);
3330
- }
3331
- else {
3332
- newNamespaces = [theNamespace, namespaces];
3333
- }
3334
- newNamespaces = (_getEvtNamespace("xx", newNamespaces).ns).split(".");
3335
- }
3336
- else {
3337
- newNamespaces = theNamespace;
3338
- }
3339
- return newNamespaces;
3340
- }
3341
- function eventOn(target, eventName, handlerRef, evtNamespace, useCapture) {
3342
- if (useCapture === void 0) { useCapture = false; }
3343
- var result = false;
3344
- if (target) {
3345
- try {
3346
- var evtName = _getEvtNamespace(eventName, evtNamespace);
3347
- result = _doAttach(target, evtName, handlerRef, useCapture);
3348
- if (result && elmNodeData.accept(target)) {
3349
- var registeredEvent = {
3350
- guid: _guid++,
3351
- evtName: evtName,
3352
- handler: handlerRef,
3353
- capture: useCapture
3354
- };
3355
- _getRegisteredEvents(target, evtName.type).push(registeredEvent);
3356
- }
3357
- }
3358
- catch (e) {
3359
- }
3360
- }
3361
- return result;
3362
- }
3363
- function eventOff(target, eventName, handlerRef, evtNamespace, useCapture) {
3364
- if (useCapture === void 0) { useCapture = false; }
3365
- if (target) {
3366
- try {
3367
- var evtName_1 = _getEvtNamespace(eventName, evtNamespace);
3368
- var found_1 = false;
3369
- _unregisterEvents(target, evtName_1, function (regEvent) {
3370
- if ((evtName_1.ns && !handlerRef) || regEvent.handler === handlerRef) {
3371
- found_1 = true;
3372
- return true;
3373
- }
3374
- return false;
3375
- });
3376
- if (!found_1) {
3377
- _doDetach(target, evtName_1, handlerRef, useCapture);
3378
- }
3379
- }
3380
- catch (e) {
3381
- }
3382
- }
3383
- }
3384
- function addEventHandler(eventName, callback, evtNamespace) {
3385
- var result = false;
3386
- var w = getWindow();
3387
- if (w) {
3388
- result = eventOn(w, eventName, callback, evtNamespace);
3389
- result = eventOn(w["body"], eventName, callback, evtNamespace) || result;
3390
- }
3391
- var doc = getDocument();
3392
- if (doc) {
3393
- result = eventOn(doc, eventName, callback, evtNamespace) || result;
3394
- }
3395
- return result;
3396
- }
3397
-
3398
- var _cookieMgrs = null;
3399
- var _canUseCookies;
3400
- function newGuid() {
3401
- function randomHexDigit() {
3402
- return randomValue(15);
3403
- }
3404
- return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(GuidRegex, function (c) {
3405
- var r = (randomHexDigit() | 0), v = (c === "x" ? r : r & 0x3 | 0x8);
3406
- return v.toString(16);
3407
- });
3408
- }
3409
- function perfNow() {
3410
- var perf = getPerformance();
3411
- if (perf && perf.now) {
3412
- return perf.now();
3413
- }
3414
- return dateNow();
3415
- }
3416
- function generateW3CId() {
3417
- var hexValues = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"];
3418
- var oct = strEmpty$1, tmp;
3419
- for (var a = 0; a < 4; a++) {
3420
- tmp = random32();
3421
- oct +=
3422
- hexValues[tmp & 0xF] +
3423
- hexValues[tmp >> 4 & 0xF] +
3424
- hexValues[tmp >> 8 & 0xF] +
3425
- hexValues[tmp >> 12 & 0xF] +
3426
- hexValues[tmp >> 16 & 0xF] +
3427
- hexValues[tmp >> 20 & 0xF] +
3428
- hexValues[tmp >> 24 & 0xF] +
3429
- hexValues[tmp >> 28 & 0xF];
3430
- }
3431
- var clockSequenceHi = hexValues[8 + (random32() & 0x03) | 0];
3432
- return oct.substr(0, 8) + oct.substr(9, 4) + "4" + oct.substr(13, 3) + clockSequenceHi + oct.substr(16, 3) + oct.substr(19, 12);
3433
- }
3434
- var CoreUtils = {
3435
- _canUseCookies: undefined,
3436
- isTypeof: isTypeof,
3437
- isUndefined: isUndefined,
3438
- isNullOrUndefined: isNullOrUndefined,
3439
- hasOwnProperty: hasOwnProperty,
3440
- isFunction: isFunction,
3441
- isObject: isObject,
3442
- isDate: isDate,
3443
- isArray: isArray,
3444
- isError: isError,
3445
- isString: isString,
3446
- isNumber: isNumber,
3447
- isBoolean: isBoolean,
3448
- toISOString: toISOString,
3449
- arrForEach: arrForEach,
3450
- arrIndexOf: arrIndexOf,
3451
- arrMap: arrMap,
3452
- arrReduce: arrReduce,
3453
- strTrim: strTrim,
3454
- objCreate: objCreateFn,
3455
- objKeys: objKeys,
3456
- objDefineAccessors: objDefineAccessors,
3457
- addEventHandler: addEventHandler,
3458
- dateNow: dateNow,
3459
- isIE: isIE,
3460
- disableCookies: disableCookies,
3461
- newGuid: newGuid,
3462
- perfNow: perfNow,
3463
- newId: newId,
3464
- randomValue: randomValue,
3465
- random32: random32,
3466
- mwcRandomSeed: mwcRandomSeed,
3467
- mwcRandom32: mwcRandom32,
3468
- generateW3CId: generateW3CId
3469
- };
3470
- var GuidRegex = /[xy]/g;
3471
- function _legacyCookieMgr(config, logger) {
3472
- var cookieMgr = _gblCookieMgr(config, logger);
3473
- var legacyCanUseCookies = CoreUtils._canUseCookies;
3474
- if (_cookieMgrs === null) {
3475
- _cookieMgrs = [];
3476
- _canUseCookies = legacyCanUseCookies;
3477
- objDefineAccessors(CoreUtils, "_canUseCookies", function () {
3478
- return _canUseCookies;
3479
- }, function (value) {
3480
- _canUseCookies = value;
3481
- arrForEach(_cookieMgrs, function (mgr) {
3482
- mgr.setEnabled(value);
3483
- });
3484
- });
3485
- }
3486
- if (arrIndexOf(_cookieMgrs, cookieMgr) === -1) {
3487
- _cookieMgrs.push(cookieMgr);
3488
- }
3489
- if (isBoolean(legacyCanUseCookies)) {
3490
- cookieMgr.setEnabled(legacyCanUseCookies);
3491
- }
3492
- if (isBoolean(_canUseCookies)) {
3493
- cookieMgr.setEnabled(_canUseCookies);
3494
- }
3495
- return cookieMgr;
3496
- }
3497
- function disableCookies() {
3498
- _legacyCookieMgr().setEnabled(false);
3499
- }
3500
-
3501
3569
  createEnumStyle({
3502
3570
  CRITICAL: 1 ,
3503
3571
  WARNING: 2
@@ -4949,7 +5017,7 @@
4949
5017
  }
4950
5018
  }
4951
5019
  var EnvelopeCreator = {
4952
- Version: "2.8.4-nightly.2205-08"
5020
+ Version: "2.8.4"
4953
5021
  };
4954
5022
  function DependencyEnvelopeCreator(logger, telemetryItem, customUndefinedValue) {
4955
5023
  EnvelopeCreatorInit(logger, telemetryItem);
@@ -5799,7 +5867,7 @@
5799
5867
  _syncUnloadSender(payload, false);
5800
5868
  }
5801
5869
  else {
5802
- _beaconSender(payload);
5870
+ _beaconSender(payload, isAsync);
5803
5871
  }
5804
5872
  }
5805
5873
  function _doBeaconSend(payload) {
@@ -5864,7 +5932,7 @@
5864
5932
  _doFetchSender(payload, false);
5865
5933
  }
5866
5934
  else if (isBeaconsSupported()) {
5867
- _beaconSender(payload);
5935
+ _beaconSender(payload, isAsync);
5868
5936
  }
5869
5937
  else {
5870
5938
  _fallbackSender && _fallbackSender(payload, true);
@@ -6164,4 +6232,4 @@
6164
6232
  (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 });
6165
6233
 
6166
6234
  }));
6167
- //# sourceMappingURL=aib.2.8.4-nightly.2205-08.js.map
6235
+ //# sourceMappingURL=aib.2.8.4.js.map