@paypay/mini-app-js-sdk 2.48.0 → 2.51.0

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.
@@ -197,13 +197,10 @@ const PPFunctionName = {
197
197
  requestInternal: "requestInternal",
198
198
  scanCode: "scanCode",
199
199
  getAuthStatus: "getAuthStatus",
200
- openMiniApp: "openMiniApp",
201
200
  inputAddress: "inputAddress",
202
- checkAccessToken: "checkAccessToken",
203
201
  getCashbackInformation: "getCashbackInformation",
204
202
  request: "request",
205
203
  getDeviceInformation: "getDeviceInformation",
206
- debug: "debug",
207
204
  createOrder: "createOrder",
208
205
  handleMessageFromNative: "handleMessageFromNative",
209
206
  initKycPassport: "initKycPassport",
@@ -263,11 +260,8 @@ const miniAppSupportedFunctions = [
263
260
  "registerUserInfo",
264
261
  "setEnablePullDownRefresh",
265
262
  "registerEmail",
266
- "checkAccessToken",
267
- "debug",
268
263
  "inputAddress",
269
264
  "getDeviceInformation",
270
- "openMiniApp",
271
265
  "request",
272
266
  "requestInternal",
273
267
  "registerPaymentFeatures",
@@ -377,10 +371,11 @@ var MiniAppErrorType = /* @__PURE__ */ ((MiniAppErrorType2) => {
377
371
  MiniAppErrorType2["rateLimitExceeded"] = "RATE_LIMIT_EXCEEDED";
378
372
  MiniAppErrorType2["sdkUpgradeRequired"] = "SDK_UPGRADE_REQUIRED";
379
373
  MiniAppErrorType2["authorizationNeeded"] = "AUTHORIZATION_NEEDED";
374
+ MiniAppErrorType2["invalidVirtualAccount"] = "INVALID_VIRTUAL_ACCOUNT";
380
375
  return MiniAppErrorType2;
381
376
  })(MiniAppErrorType || {});
382
- const JS_SDK_VERSION = "2.48.0";
383
- const REVISION = "765ecbf";
377
+ const JS_SDK_VERSION = "2.51.0";
378
+ const REVISION = "9c03362";
384
379
  const coreBaseUrl = new URL("https://mini-app-sdk-core.paypay.ne.jp/");
385
380
  const CORE_IFRAME_ORIGIN = coreBaseUrl.origin;
386
381
  const CORE_IFRAME_URL = new URL(
@@ -1520,209 +1515,2220 @@ class WindowBridge {
1520
1515
  });
1521
1516
  }
1522
1517
  }
1523
- class LocalStorageProxy {
1524
- constructor() {
1525
- var _a;
1526
- this.useLocalStorage = true;
1527
- this.memoryStorage = {};
1528
- try {
1529
- localStorage.setItem(
1530
- PpLocalStorageKey.initializedAt,
1531
- Date.now().toString()
1532
- );
1533
- for (let i = 0; i < localStorage.length; i++) {
1534
- const key = localStorage.key(i);
1535
- if (key != null) {
1536
- this.memoryStorage[key] = (_a = localStorage.getItem(key)) != null ? _a : "";
1537
- }
1538
- }
1539
- } catch (e) {
1540
- this.useLocalStorage = false;
1518
+ const BROWSER_ALIASES_MAP = {
1519
+ "Amazon Silk": "amazon_silk",
1520
+ "Android Browser": "android",
1521
+ Bada: "bada",
1522
+ BlackBerry: "blackberry",
1523
+ Chrome: "chrome",
1524
+ Chromium: "chromium",
1525
+ Electron: "electron",
1526
+ Epiphany: "epiphany",
1527
+ Firefox: "firefox",
1528
+ Focus: "focus",
1529
+ Generic: "generic",
1530
+ "Google Search": "google_search",
1531
+ Googlebot: "googlebot",
1532
+ "Internet Explorer": "ie",
1533
+ "K-Meleon": "k_meleon",
1534
+ Maxthon: "maxthon",
1535
+ "Microsoft Edge": "edge",
1536
+ "MZ Browser": "mz",
1537
+ "NAVER Whale Browser": "naver",
1538
+ Opera: "opera",
1539
+ "Opera Coast": "opera_coast",
1540
+ PhantomJS: "phantomjs",
1541
+ Puffin: "puffin",
1542
+ QupZilla: "qupzilla",
1543
+ QQ: "qq",
1544
+ QQLite: "qqlite",
1545
+ Safari: "safari",
1546
+ Sailfish: "sailfish",
1547
+ "Samsung Internet for Android": "samsung_internet",
1548
+ SeaMonkey: "seamonkey",
1549
+ Sleipnir: "sleipnir",
1550
+ Swing: "swing",
1551
+ Tizen: "tizen",
1552
+ "UC Browser": "uc",
1553
+ Vivaldi: "vivaldi",
1554
+ "WebOS Browser": "webos",
1555
+ WeChat: "wechat",
1556
+ "Yandex Browser": "yandex",
1557
+ Roku: "roku"
1558
+ };
1559
+ const BROWSER_MAP = {
1560
+ amazon_silk: "Amazon Silk",
1561
+ android: "Android Browser",
1562
+ bada: "Bada",
1563
+ blackberry: "BlackBerry",
1564
+ chrome: "Chrome",
1565
+ chromium: "Chromium",
1566
+ electron: "Electron",
1567
+ epiphany: "Epiphany",
1568
+ firefox: "Firefox",
1569
+ focus: "Focus",
1570
+ generic: "Generic",
1571
+ googlebot: "Googlebot",
1572
+ google_search: "Google Search",
1573
+ ie: "Internet Explorer",
1574
+ k_meleon: "K-Meleon",
1575
+ maxthon: "Maxthon",
1576
+ edge: "Microsoft Edge",
1577
+ mz: "MZ Browser",
1578
+ naver: "NAVER Whale Browser",
1579
+ opera: "Opera",
1580
+ opera_coast: "Opera Coast",
1581
+ phantomjs: "PhantomJS",
1582
+ puffin: "Puffin",
1583
+ qupzilla: "QupZilla",
1584
+ qq: "QQ Browser",
1585
+ qqlite: "QQ Browser Lite",
1586
+ safari: "Safari",
1587
+ sailfish: "Sailfish",
1588
+ samsung_internet: "Samsung Internet for Android",
1589
+ seamonkey: "SeaMonkey",
1590
+ sleipnir: "Sleipnir",
1591
+ swing: "Swing",
1592
+ tizen: "Tizen",
1593
+ uc: "UC Browser",
1594
+ vivaldi: "Vivaldi",
1595
+ webos: "WebOS Browser",
1596
+ wechat: "WeChat",
1597
+ yandex: "Yandex Browser"
1598
+ };
1599
+ const PLATFORMS_MAP = {
1600
+ tablet: "tablet",
1601
+ mobile: "mobile",
1602
+ desktop: "desktop",
1603
+ tv: "tv"
1604
+ };
1605
+ const OS_MAP = {
1606
+ WindowsPhone: "Windows Phone",
1607
+ Windows: "Windows",
1608
+ MacOS: "macOS",
1609
+ iOS: "iOS",
1610
+ Android: "Android",
1611
+ WebOS: "WebOS",
1612
+ BlackBerry: "BlackBerry",
1613
+ Bada: "Bada",
1614
+ Tizen: "Tizen",
1615
+ Linux: "Linux",
1616
+ ChromeOS: "Chrome OS",
1617
+ PlayStation4: "PlayStation 4",
1618
+ Roku: "Roku"
1619
+ };
1620
+ const ENGINE_MAP = {
1621
+ EdgeHTML: "EdgeHTML",
1622
+ Blink: "Blink",
1623
+ Trident: "Trident",
1624
+ Presto: "Presto",
1625
+ Gecko: "Gecko",
1626
+ WebKit: "WebKit"
1627
+ };
1628
+ class Utils {
1629
+ /**
1630
+ * Get first matched item for a string
1631
+ * @param {RegExp} regexp
1632
+ * @param {String} ua
1633
+ * @return {Array|{index: number, input: string}|*|boolean|string}
1634
+ */
1635
+ static getFirstMatch(regexp, ua) {
1636
+ const match = ua.match(regexp);
1637
+ return match && match.length > 0 && match[1] || "";
1638
+ }
1639
+ /**
1640
+ * Get second matched item for a string
1641
+ * @param regexp
1642
+ * @param {String} ua
1643
+ * @return {Array|{index: number, input: string}|*|boolean|string}
1644
+ */
1645
+ static getSecondMatch(regexp, ua) {
1646
+ const match = ua.match(regexp);
1647
+ return match && match.length > 1 && match[2] || "";
1648
+ }
1649
+ /**
1650
+ * Match a regexp and return a constant or undefined
1651
+ * @param {RegExp} regexp
1652
+ * @param {String} ua
1653
+ * @param {*} _const Any const that will be returned if regexp matches the string
1654
+ * @return {*}
1655
+ */
1656
+ static matchAndReturnConst(regexp, ua, _const) {
1657
+ if (regexp.test(ua)) {
1658
+ return _const;
1541
1659
  }
1660
+ return void 0;
1542
1661
  }
1543
- getItem(key) {
1544
- var _a;
1545
- if (this.useLocalStorage) {
1546
- try {
1547
- if (localStorage.getItem(PpLocalStorageKey.initializedAt) != null) {
1548
- return localStorage.getItem(key);
1549
- } else {
1550
- console.debug("local storage value has lost unexpectedly.");
1551
- addBreadcrumbToSentry({
1552
- message: "local storage value has lost unexpectedly.",
1553
- category: "storage"
1554
- });
1555
- }
1556
- } catch (e) {
1557
- }
1662
+ static getWindowsVersionName(version) {
1663
+ switch (version) {
1664
+ case "NT":
1665
+ return "NT";
1666
+ case "XP":
1667
+ return "XP";
1668
+ case "NT 5.0":
1669
+ return "2000";
1670
+ case "NT 5.1":
1671
+ return "XP";
1672
+ case "NT 5.2":
1673
+ return "2003";
1674
+ case "NT 6.0":
1675
+ return "Vista";
1676
+ case "NT 6.1":
1677
+ return "7";
1678
+ case "NT 6.2":
1679
+ return "8";
1680
+ case "NT 6.3":
1681
+ return "8.1";
1682
+ case "NT 10.0":
1683
+ return "10";
1684
+ default:
1685
+ return void 0;
1558
1686
  }
1559
- this.useLocalStorage = false;
1560
- return (_a = this.memoryStorage[key]) != null ? _a : null;
1561
1687
  }
1562
- setItem(key, value) {
1563
- this.memoryStorage[key] = value;
1564
- if (this.useLocalStorage) {
1565
- try {
1566
- localStorage.setItem(key, value);
1567
- } catch (e) {
1568
- this.useLocalStorage = false;
1569
- console.warn("localStorage has become unavailable.");
1570
- }
1688
+ /**
1689
+ * Get macOS version name
1690
+ * 10.5 - Leopard
1691
+ * 10.6 - Snow Leopard
1692
+ * 10.7 - Lion
1693
+ * 10.8 - Mountain Lion
1694
+ * 10.9 - Mavericks
1695
+ * 10.10 - Yosemite
1696
+ * 10.11 - El Capitan
1697
+ * 10.12 - Sierra
1698
+ * 10.13 - High Sierra
1699
+ * 10.14 - Mojave
1700
+ * 10.15 - Catalina
1701
+ *
1702
+ * @example
1703
+ * getMacOSVersionName("10.14") // 'Mojave'
1704
+ *
1705
+ * @param {string} version
1706
+ * @return {string} versionName
1707
+ */
1708
+ static getMacOSVersionName(version) {
1709
+ const v = version.split(".").splice(0, 2).map((s) => parseInt(s, 10) || 0);
1710
+ v.push(0);
1711
+ if (v[0] !== 10) return void 0;
1712
+ switch (v[1]) {
1713
+ case 5:
1714
+ return "Leopard";
1715
+ case 6:
1716
+ return "Snow Leopard";
1717
+ case 7:
1718
+ return "Lion";
1719
+ case 8:
1720
+ return "Mountain Lion";
1721
+ case 9:
1722
+ return "Mavericks";
1723
+ case 10:
1724
+ return "Yosemite";
1725
+ case 11:
1726
+ return "El Capitan";
1727
+ case 12:
1728
+ return "Sierra";
1729
+ case 13:
1730
+ return "High Sierra";
1731
+ case 14:
1732
+ return "Mojave";
1733
+ case 15:
1734
+ return "Catalina";
1735
+ default:
1736
+ return void 0;
1571
1737
  }
1572
1738
  }
1573
- removeItem(key) {
1574
- delete this.memoryStorage[key];
1575
- try {
1576
- localStorage.removeItem(key);
1577
- } catch (e) {
1578
- this.useLocalStorage = false;
1739
+ /**
1740
+ * Get Android version name
1741
+ * 1.5 - Cupcake
1742
+ * 1.6 - Donut
1743
+ * 2.0 - Eclair
1744
+ * 2.1 - Eclair
1745
+ * 2.2 - Froyo
1746
+ * 2.x - Gingerbread
1747
+ * 3.x - Honeycomb
1748
+ * 4.0 - Ice Cream Sandwich
1749
+ * 4.1 - Jelly Bean
1750
+ * 4.4 - KitKat
1751
+ * 5.x - Lollipop
1752
+ * 6.x - Marshmallow
1753
+ * 7.x - Nougat
1754
+ * 8.x - Oreo
1755
+ * 9.x - Pie
1756
+ *
1757
+ * @example
1758
+ * getAndroidVersionName("7.0") // 'Nougat'
1759
+ *
1760
+ * @param {string} version
1761
+ * @return {string} versionName
1762
+ */
1763
+ static getAndroidVersionName(version) {
1764
+ const v = version.split(".").splice(0, 2).map((s) => parseInt(s, 10) || 0);
1765
+ v.push(0);
1766
+ if (v[0] === 1 && v[1] < 5) return void 0;
1767
+ if (v[0] === 1 && v[1] < 6) return "Cupcake";
1768
+ if (v[0] === 1 && v[1] >= 6) return "Donut";
1769
+ if (v[0] === 2 && v[1] < 2) return "Eclair";
1770
+ if (v[0] === 2 && v[1] === 2) return "Froyo";
1771
+ if (v[0] === 2 && v[1] > 2) return "Gingerbread";
1772
+ if (v[0] === 3) return "Honeycomb";
1773
+ if (v[0] === 4 && v[1] < 1) return "Ice Cream Sandwich";
1774
+ if (v[0] === 4 && v[1] < 4) return "Jelly Bean";
1775
+ if (v[0] === 4 && v[1] >= 4) return "KitKat";
1776
+ if (v[0] === 5) return "Lollipop";
1777
+ if (v[0] === 6) return "Marshmallow";
1778
+ if (v[0] === 7) return "Nougat";
1779
+ if (v[0] === 8) return "Oreo";
1780
+ if (v[0] === 9) return "Pie";
1781
+ return void 0;
1782
+ }
1783
+ /**
1784
+ * Get version precisions count
1785
+ *
1786
+ * @example
1787
+ * getVersionPrecision("1.10.3") // 3
1788
+ *
1789
+ * @param {string} version
1790
+ * @return {number}
1791
+ */
1792
+ static getVersionPrecision(version) {
1793
+ return version.split(".").length;
1794
+ }
1795
+ /**
1796
+ * Calculate browser version weight
1797
+ *
1798
+ * @example
1799
+ * compareVersions('1.10.2.1', '1.8.2.1.90') // 1
1800
+ * compareVersions('1.010.2.1', '1.09.2.1.90'); // 1
1801
+ * compareVersions('1.10.2.1', '1.10.2.1'); // 0
1802
+ * compareVersions('1.10.2.1', '1.0800.2'); // -1
1803
+ * compareVersions('1.10.2.1', '1.10', true); // 0
1804
+ *
1805
+ * @param {String} versionA versions versions to compare
1806
+ * @param {String} versionB versions versions to compare
1807
+ * @param {boolean} [isLoose] enable loose comparison
1808
+ * @return {Number} comparison result: -1 when versionA is lower,
1809
+ * 1 when versionA is bigger, 0 when both equal
1810
+ */
1811
+ /* eslint consistent-return: 1 */
1812
+ static compareVersions(versionA, versionB, isLoose = false) {
1813
+ const versionAPrecision = Utils.getVersionPrecision(versionA);
1814
+ const versionBPrecision = Utils.getVersionPrecision(versionB);
1815
+ let precision = Math.max(versionAPrecision, versionBPrecision);
1816
+ let lastPrecision = 0;
1817
+ const chunks = Utils.map([versionA, versionB], (version) => {
1818
+ const delta = precision - Utils.getVersionPrecision(version);
1819
+ const _version = version + new Array(delta + 1).join(".0");
1820
+ return Utils.map(_version.split("."), (chunk) => new Array(20 - chunk.length).join("0") + chunk).reverse();
1821
+ });
1822
+ if (isLoose) {
1823
+ lastPrecision = precision - Math.min(versionAPrecision, versionBPrecision);
1824
+ }
1825
+ precision -= 1;
1826
+ while (precision >= lastPrecision) {
1827
+ if (chunks[0][precision] > chunks[1][precision]) {
1828
+ return 1;
1829
+ }
1830
+ if (chunks[0][precision] === chunks[1][precision]) {
1831
+ if (precision === lastPrecision) {
1832
+ return 0;
1833
+ }
1834
+ precision -= 1;
1835
+ } else if (chunks[0][precision] < chunks[1][precision]) {
1836
+ return -1;
1837
+ }
1579
1838
  }
1839
+ return void 0;
1580
1840
  }
1581
- clear() {
1582
- try {
1583
- localStorage.clear();
1584
- localStorage.setItem(
1585
- PpLocalStorageKey.initializedAt,
1586
- Date.now().toString()
1587
- );
1588
- } catch (e) {
1841
+ /**
1842
+ * Array::map polyfill
1843
+ *
1844
+ * @param {Array} arr
1845
+ * @param {Function} iterator
1846
+ * @return {Array}
1847
+ */
1848
+ static map(arr, iterator) {
1849
+ const result = [];
1850
+ let i;
1851
+ if (Array.prototype.map) {
1852
+ return Array.prototype.map.call(arr, iterator);
1589
1853
  }
1590
- this.memoryStorage = {};
1854
+ for (i = 0; i < arr.length; i += 1) {
1855
+ result.push(iterator(arr[i]));
1856
+ }
1857
+ return result;
1591
1858
  }
1592
- }
1593
- new LocalStorageProxy();
1594
- function isFunction(val) {
1595
- return typeof val === "function";
1596
- }
1597
- function getRandomString() {
1598
- return Math.random().toString(36).substring(7);
1599
- }
1600
- function setCookie({ name, value, options }) {
1601
- return api.set(name, value, options);
1602
- }
1603
- function getCookie({ name }) {
1604
- return api.get(name);
1605
- }
1606
- function removeCookie({ name, options }) {
1607
- return api.remove(name, options);
1608
- }
1609
- function setLocalStorage({
1610
- name,
1611
- value
1612
- }) {
1613
- return localStorage.setItem(name, value);
1614
- }
1615
- function getLocalStorage({ name }) {
1616
- return localStorage.getItem(name);
1617
- }
1618
- function removeLocalStorage({ name }) {
1619
- return localStorage.removeItem(name);
1620
- }
1621
- function setSessionStorage({
1622
- name,
1623
- value
1624
- }) {
1625
- return sessionStorage.setItem(name, value);
1626
- }
1627
- function getSessionStorage({ name }) {
1628
- return sessionStorage.getItem(name);
1629
- }
1630
- function removeSessionStorage({ name }) {
1631
- return sessionStorage.removeItem(name);
1632
- }
1633
- function removeQueryParametersFromUrl(removeParams) {
1634
- const url = new URL(window.location.href);
1635
- removeParams.forEach((param) => url.searchParams.delete(param));
1636
- const newURL = `${url.pathname}${url.search}`;
1637
- history.replaceState(history.state, "", newURL);
1638
- }
1639
- function getUrl() {
1640
- return window.location.href;
1641
- }
1642
- const clientWindowBridgeFunctions = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1643
- __proto__: null,
1644
- getCookie,
1645
- getLocalStorage,
1646
- getSessionStorage,
1647
- getUrl,
1648
- removeCookie,
1649
- removeLocalStorage,
1650
- removeQueryParametersFromUrl,
1651
- removeSessionStorage,
1652
- setCookie,
1653
- setLocalStorage,
1654
- setSessionStorage
1655
- }, Symbol.toStringTag, { value: "Module" }));
1656
- const IFRAME_NAME = "ppmna-iframe";
1657
- const IFRAME_CONTAINER_NAME = "ppsdk-container";
1658
- let iframeContainer;
1659
- function getCoreIframeContainer() {
1660
- if (!iframeContainer) {
1661
- iframeContainer = createIframeContainer();
1859
+ /**
1860
+ * Array::find polyfill
1861
+ *
1862
+ * @param {Array} arr
1863
+ * @param {Function} predicate
1864
+ * @return {Array}
1865
+ */
1866
+ static find(arr, predicate) {
1867
+ let i;
1868
+ let l;
1869
+ if (Array.prototype.find) {
1870
+ return Array.prototype.find.call(arr, predicate);
1871
+ }
1872
+ for (i = 0, l = arr.length; i < l; i += 1) {
1873
+ const value = arr[i];
1874
+ if (predicate(value, i)) {
1875
+ return value;
1876
+ }
1877
+ }
1878
+ return void 0;
1662
1879
  }
1663
- return iframeContainer;
1664
- }
1665
- function createIframeContainer() {
1666
- const frameExists = document.getElementById(IFRAME_NAME);
1667
- if (frameExists) {
1668
- return;
1880
+ /**
1881
+ * Object::assign polyfill
1882
+ *
1883
+ * @param {Object} obj
1884
+ * @param {Object} ...objs
1885
+ * @return {Object}
1886
+ */
1887
+ static assign(obj, ...assigners) {
1888
+ const result = obj;
1889
+ let i;
1890
+ let l;
1891
+ if (Object.assign) {
1892
+ return Object.assign(obj, ...assigners);
1893
+ }
1894
+ for (i = 0, l = assigners.length; i < l; i += 1) {
1895
+ const assigner = assigners[i];
1896
+ if (typeof assigner === "object" && assigner !== null) {
1897
+ const keys = Object.keys(assigner);
1898
+ keys.forEach((key) => {
1899
+ result[key] = assigner[key];
1900
+ });
1901
+ }
1902
+ }
1903
+ return obj;
1669
1904
  }
1670
- const container = document.createElement("div");
1671
- document.createElement("div");
1672
- container.setAttribute("id", IFRAME_CONTAINER_NAME);
1673
- container.setAttribute("class", IFRAME_CONTAINER_NAME);
1674
- container.style.all = "initial";
1675
- container.style.display = "none";
1676
- container.style.position = "fixed";
1677
- container.style.width = "100%";
1678
- container.style.height = "100%";
1679
- container.style.top = "0";
1680
- container.style.left = "0";
1681
- container.style.zIndex = "2147483637";
1682
- document.body.appendChild(container);
1683
- return container;
1684
- }
1685
- function showCoreIframe(visible) {
1686
- const container = getCoreIframeContainer();
1687
- if (container) {
1688
- container.style.display = visible ? "initial" : "none";
1905
+ /**
1906
+ * Get short version/alias for a browser name
1907
+ *
1908
+ * @example
1909
+ * getBrowserAlias('Microsoft Edge') // edge
1910
+ *
1911
+ * @param {string} browserName
1912
+ * @return {string}
1913
+ */
1914
+ static getBrowserAlias(browserName) {
1915
+ return BROWSER_ALIASES_MAP[browserName];
1689
1916
  }
1690
- }
1691
- let coreIframeLoadingPromise;
1692
- function getCoreIframe() {
1693
- if (!coreIframeLoadingPromise) {
1694
- coreIframeLoadingPromise = createIframe();
1917
+ /**
1918
+ * Get short version/alias for a browser name
1919
+ *
1920
+ * @example
1921
+ * getBrowserAlias('edge') // Microsoft Edge
1922
+ *
1923
+ * @param {string} browserAlias
1924
+ * @return {string}
1925
+ */
1926
+ static getBrowserTypeByAlias(browserAlias) {
1927
+ return BROWSER_MAP[browserAlias] || "";
1695
1928
  }
1696
- return coreIframeLoadingPromise;
1697
- }
1698
- function getCoreIframeWindow() {
1699
- return getCoreIframe().then((iframe) => iframe == null ? void 0 : iframe.contentWindow).catch(() => null);
1700
1929
  }
1701
- function createIframe() {
1702
- return new Promise((resolve, reject) => {
1703
- if (document.readyState === "loading") {
1704
- document.addEventListener("DOMContentLoaded", () => {
1705
- create();
1706
- });
1707
- } else {
1708
- create();
1930
+ const commonVersionIdentifier = /version\/(\d+(\.?_?\d+)+)/i;
1931
+ const browsersList = [
1932
+ /* Googlebot */
1933
+ {
1934
+ test: [/googlebot/i],
1935
+ describe(ua) {
1936
+ const browser = {
1937
+ name: "Googlebot"
1938
+ };
1939
+ const version = Utils.getFirstMatch(/googlebot\/(\d+(\.\d+))/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua);
1940
+ if (version) {
1941
+ browser.version = version;
1942
+ }
1943
+ return browser;
1709
1944
  }
1710
- function create() {
1711
- const iframe = document.createElement("iframe");
1712
- iframe.setAttribute("src", CORE_IFRAME_URL);
1713
- iframe.setAttribute("name", IFRAME_NAME);
1714
- iframe.setAttribute("id", IFRAME_NAME);
1715
- iframe.setAttribute("class", IFRAME_NAME);
1716
- iframe.setAttribute("allow", "geolocation");
1717
- iframe.onload = () => {
1718
- resolve(iframe);
1719
- iframe.onerror = null;
1945
+ },
1946
+ /* Opera < 13.0 */
1947
+ {
1948
+ test: [/opera/i],
1949
+ describe(ua) {
1950
+ const browser = {
1951
+ name: "Opera"
1720
1952
  };
1721
- iframe.onerror = reject;
1722
- iframe.style.all = "initial";
1723
- iframe.style.width = "100%";
1724
- iframe.style.height = "100%";
1725
- iframe.style.border = "none";
1953
+ const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/(?:opera)[\s/](\d+(\.?_?\d+)+)/i, ua);
1954
+ if (version) {
1955
+ browser.version = version;
1956
+ }
1957
+ return browser;
1958
+ }
1959
+ },
1960
+ /* Opera > 13.0 */
1961
+ {
1962
+ test: [/opr\/|opios/i],
1963
+ describe(ua) {
1964
+ const browser = {
1965
+ name: "Opera"
1966
+ };
1967
+ const version = Utils.getFirstMatch(/(?:opr|opios)[\s/](\S+)/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua);
1968
+ if (version) {
1969
+ browser.version = version;
1970
+ }
1971
+ return browser;
1972
+ }
1973
+ },
1974
+ {
1975
+ test: [/SamsungBrowser/i],
1976
+ describe(ua) {
1977
+ const browser = {
1978
+ name: "Samsung Internet for Android"
1979
+ };
1980
+ const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/(?:SamsungBrowser)[\s/](\d+(\.?_?\d+)+)/i, ua);
1981
+ if (version) {
1982
+ browser.version = version;
1983
+ }
1984
+ return browser;
1985
+ }
1986
+ },
1987
+ {
1988
+ test: [/Whale/i],
1989
+ describe(ua) {
1990
+ const browser = {
1991
+ name: "NAVER Whale Browser"
1992
+ };
1993
+ const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/(?:whale)[\s/](\d+(?:\.\d+)+)/i, ua);
1994
+ if (version) {
1995
+ browser.version = version;
1996
+ }
1997
+ return browser;
1998
+ }
1999
+ },
2000
+ {
2001
+ test: [/MZBrowser/i],
2002
+ describe(ua) {
2003
+ const browser = {
2004
+ name: "MZ Browser"
2005
+ };
2006
+ const version = Utils.getFirstMatch(/(?:MZBrowser)[\s/](\d+(?:\.\d+)+)/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua);
2007
+ if (version) {
2008
+ browser.version = version;
2009
+ }
2010
+ return browser;
2011
+ }
2012
+ },
2013
+ {
2014
+ test: [/focus/i],
2015
+ describe(ua) {
2016
+ const browser = {
2017
+ name: "Focus"
2018
+ };
2019
+ const version = Utils.getFirstMatch(/(?:focus)[\s/](\d+(?:\.\d+)+)/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua);
2020
+ if (version) {
2021
+ browser.version = version;
2022
+ }
2023
+ return browser;
2024
+ }
2025
+ },
2026
+ {
2027
+ test: [/swing/i],
2028
+ describe(ua) {
2029
+ const browser = {
2030
+ name: "Swing"
2031
+ };
2032
+ const version = Utils.getFirstMatch(/(?:swing)[\s/](\d+(?:\.\d+)+)/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua);
2033
+ if (version) {
2034
+ browser.version = version;
2035
+ }
2036
+ return browser;
2037
+ }
2038
+ },
2039
+ {
2040
+ test: [/coast/i],
2041
+ describe(ua) {
2042
+ const browser = {
2043
+ name: "Opera Coast"
2044
+ };
2045
+ const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/(?:coast)[\s/](\d+(\.?_?\d+)+)/i, ua);
2046
+ if (version) {
2047
+ browser.version = version;
2048
+ }
2049
+ return browser;
2050
+ }
2051
+ },
2052
+ {
2053
+ test: [/opt\/\d+(?:.?_?\d+)+/i],
2054
+ describe(ua) {
2055
+ const browser = {
2056
+ name: "Opera Touch"
2057
+ };
2058
+ const version = Utils.getFirstMatch(/(?:opt)[\s/](\d+(\.?_?\d+)+)/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua);
2059
+ if (version) {
2060
+ browser.version = version;
2061
+ }
2062
+ return browser;
2063
+ }
2064
+ },
2065
+ {
2066
+ test: [/yabrowser/i],
2067
+ describe(ua) {
2068
+ const browser = {
2069
+ name: "Yandex Browser"
2070
+ };
2071
+ const version = Utils.getFirstMatch(/(?:yabrowser)[\s/](\d+(\.?_?\d+)+)/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua);
2072
+ if (version) {
2073
+ browser.version = version;
2074
+ }
2075
+ return browser;
2076
+ }
2077
+ },
2078
+ {
2079
+ test: [/ucbrowser/i],
2080
+ describe(ua) {
2081
+ const browser = {
2082
+ name: "UC Browser"
2083
+ };
2084
+ const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/(?:ucbrowser)[\s/](\d+(\.?_?\d+)+)/i, ua);
2085
+ if (version) {
2086
+ browser.version = version;
2087
+ }
2088
+ return browser;
2089
+ }
2090
+ },
2091
+ {
2092
+ test: [/Maxthon|mxios/i],
2093
+ describe(ua) {
2094
+ const browser = {
2095
+ name: "Maxthon"
2096
+ };
2097
+ const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/(?:Maxthon|mxios)[\s/](\d+(\.?_?\d+)+)/i, ua);
2098
+ if (version) {
2099
+ browser.version = version;
2100
+ }
2101
+ return browser;
2102
+ }
2103
+ },
2104
+ {
2105
+ test: [/epiphany/i],
2106
+ describe(ua) {
2107
+ const browser = {
2108
+ name: "Epiphany"
2109
+ };
2110
+ const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/(?:epiphany)[\s/](\d+(\.?_?\d+)+)/i, ua);
2111
+ if (version) {
2112
+ browser.version = version;
2113
+ }
2114
+ return browser;
2115
+ }
2116
+ },
2117
+ {
2118
+ test: [/puffin/i],
2119
+ describe(ua) {
2120
+ const browser = {
2121
+ name: "Puffin"
2122
+ };
2123
+ const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/(?:puffin)[\s/](\d+(\.?_?\d+)+)/i, ua);
2124
+ if (version) {
2125
+ browser.version = version;
2126
+ }
2127
+ return browser;
2128
+ }
2129
+ },
2130
+ {
2131
+ test: [/sleipnir/i],
2132
+ describe(ua) {
2133
+ const browser = {
2134
+ name: "Sleipnir"
2135
+ };
2136
+ const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/(?:sleipnir)[\s/](\d+(\.?_?\d+)+)/i, ua);
2137
+ if (version) {
2138
+ browser.version = version;
2139
+ }
2140
+ return browser;
2141
+ }
2142
+ },
2143
+ {
2144
+ test: [/k-meleon/i],
2145
+ describe(ua) {
2146
+ const browser = {
2147
+ name: "K-Meleon"
2148
+ };
2149
+ const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/(?:k-meleon)[\s/](\d+(\.?_?\d+)+)/i, ua);
2150
+ if (version) {
2151
+ browser.version = version;
2152
+ }
2153
+ return browser;
2154
+ }
2155
+ },
2156
+ {
2157
+ test: [/micromessenger/i],
2158
+ describe(ua) {
2159
+ const browser = {
2160
+ name: "WeChat"
2161
+ };
2162
+ const version = Utils.getFirstMatch(/(?:micromessenger)[\s/](\d+(\.?_?\d+)+)/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua);
2163
+ if (version) {
2164
+ browser.version = version;
2165
+ }
2166
+ return browser;
2167
+ }
2168
+ },
2169
+ {
2170
+ test: [/qqbrowser/i],
2171
+ describe(ua) {
2172
+ const browser = {
2173
+ name: /qqbrowserlite/i.test(ua) ? "QQ Browser Lite" : "QQ Browser"
2174
+ };
2175
+ const version = Utils.getFirstMatch(/(?:qqbrowserlite|qqbrowser)[/](\d+(\.?_?\d+)+)/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua);
2176
+ if (version) {
2177
+ browser.version = version;
2178
+ }
2179
+ return browser;
2180
+ }
2181
+ },
2182
+ {
2183
+ test: [/msie|trident/i],
2184
+ describe(ua) {
2185
+ const browser = {
2186
+ name: "Internet Explorer"
2187
+ };
2188
+ const version = Utils.getFirstMatch(/(?:msie |rv:)(\d+(\.?_?\d+)+)/i, ua);
2189
+ if (version) {
2190
+ browser.version = version;
2191
+ }
2192
+ return browser;
2193
+ }
2194
+ },
2195
+ {
2196
+ test: [/\sedg\//i],
2197
+ describe(ua) {
2198
+ const browser = {
2199
+ name: "Microsoft Edge"
2200
+ };
2201
+ const version = Utils.getFirstMatch(/\sedg\/(\d+(\.?_?\d+)+)/i, ua);
2202
+ if (version) {
2203
+ browser.version = version;
2204
+ }
2205
+ return browser;
2206
+ }
2207
+ },
2208
+ {
2209
+ test: [/edg([ea]|ios)/i],
2210
+ describe(ua) {
2211
+ const browser = {
2212
+ name: "Microsoft Edge"
2213
+ };
2214
+ const version = Utils.getSecondMatch(/edg([ea]|ios)\/(\d+(\.?_?\d+)+)/i, ua);
2215
+ if (version) {
2216
+ browser.version = version;
2217
+ }
2218
+ return browser;
2219
+ }
2220
+ },
2221
+ {
2222
+ test: [/vivaldi/i],
2223
+ describe(ua) {
2224
+ const browser = {
2225
+ name: "Vivaldi"
2226
+ };
2227
+ const version = Utils.getFirstMatch(/vivaldi\/(\d+(\.?_?\d+)+)/i, ua);
2228
+ if (version) {
2229
+ browser.version = version;
2230
+ }
2231
+ return browser;
2232
+ }
2233
+ },
2234
+ {
2235
+ test: [/seamonkey/i],
2236
+ describe(ua) {
2237
+ const browser = {
2238
+ name: "SeaMonkey"
2239
+ };
2240
+ const version = Utils.getFirstMatch(/seamonkey\/(\d+(\.?_?\d+)+)/i, ua);
2241
+ if (version) {
2242
+ browser.version = version;
2243
+ }
2244
+ return browser;
2245
+ }
2246
+ },
2247
+ {
2248
+ test: [/sailfish/i],
2249
+ describe(ua) {
2250
+ const browser = {
2251
+ name: "Sailfish"
2252
+ };
2253
+ const version = Utils.getFirstMatch(/sailfish\s?browser\/(\d+(\.\d+)?)/i, ua);
2254
+ if (version) {
2255
+ browser.version = version;
2256
+ }
2257
+ return browser;
2258
+ }
2259
+ },
2260
+ {
2261
+ test: [/silk/i],
2262
+ describe(ua) {
2263
+ const browser = {
2264
+ name: "Amazon Silk"
2265
+ };
2266
+ const version = Utils.getFirstMatch(/silk\/(\d+(\.?_?\d+)+)/i, ua);
2267
+ if (version) {
2268
+ browser.version = version;
2269
+ }
2270
+ return browser;
2271
+ }
2272
+ },
2273
+ {
2274
+ test: [/phantom/i],
2275
+ describe(ua) {
2276
+ const browser = {
2277
+ name: "PhantomJS"
2278
+ };
2279
+ const version = Utils.getFirstMatch(/phantomjs\/(\d+(\.?_?\d+)+)/i, ua);
2280
+ if (version) {
2281
+ browser.version = version;
2282
+ }
2283
+ return browser;
2284
+ }
2285
+ },
2286
+ {
2287
+ test: [/slimerjs/i],
2288
+ describe(ua) {
2289
+ const browser = {
2290
+ name: "SlimerJS"
2291
+ };
2292
+ const version = Utils.getFirstMatch(/slimerjs\/(\d+(\.?_?\d+)+)/i, ua);
2293
+ if (version) {
2294
+ browser.version = version;
2295
+ }
2296
+ return browser;
2297
+ }
2298
+ },
2299
+ {
2300
+ test: [/blackberry|\bbb\d+/i, /rim\stablet/i],
2301
+ describe(ua) {
2302
+ const browser = {
2303
+ name: "BlackBerry"
2304
+ };
2305
+ const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/blackberry[\d]+\/(\d+(\.?_?\d+)+)/i, ua);
2306
+ if (version) {
2307
+ browser.version = version;
2308
+ }
2309
+ return browser;
2310
+ }
2311
+ },
2312
+ {
2313
+ test: [/(web|hpw)[o0]s/i],
2314
+ describe(ua) {
2315
+ const browser = {
2316
+ name: "WebOS Browser"
2317
+ };
2318
+ const version = Utils.getFirstMatch(commonVersionIdentifier, ua) || Utils.getFirstMatch(/w(?:eb)?[o0]sbrowser\/(\d+(\.?_?\d+)+)/i, ua);
2319
+ if (version) {
2320
+ browser.version = version;
2321
+ }
2322
+ return browser;
2323
+ }
2324
+ },
2325
+ {
2326
+ test: [/bada/i],
2327
+ describe(ua) {
2328
+ const browser = {
2329
+ name: "Bada"
2330
+ };
2331
+ const version = Utils.getFirstMatch(/dolfin\/(\d+(\.?_?\d+)+)/i, ua);
2332
+ if (version) {
2333
+ browser.version = version;
2334
+ }
2335
+ return browser;
2336
+ }
2337
+ },
2338
+ {
2339
+ test: [/tizen/i],
2340
+ describe(ua) {
2341
+ const browser = {
2342
+ name: "Tizen"
2343
+ };
2344
+ const version = Utils.getFirstMatch(/(?:tizen\s?)?browser\/(\d+(\.?_?\d+)+)/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua);
2345
+ if (version) {
2346
+ browser.version = version;
2347
+ }
2348
+ return browser;
2349
+ }
2350
+ },
2351
+ {
2352
+ test: [/qupzilla/i],
2353
+ describe(ua) {
2354
+ const browser = {
2355
+ name: "QupZilla"
2356
+ };
2357
+ const version = Utils.getFirstMatch(/(?:qupzilla)[\s/](\d+(\.?_?\d+)+)/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua);
2358
+ if (version) {
2359
+ browser.version = version;
2360
+ }
2361
+ return browser;
2362
+ }
2363
+ },
2364
+ {
2365
+ test: [/firefox|iceweasel|fxios/i],
2366
+ describe(ua) {
2367
+ const browser = {
2368
+ name: "Firefox"
2369
+ };
2370
+ const version = Utils.getFirstMatch(/(?:firefox|iceweasel|fxios)[\s/](\d+(\.?_?\d+)+)/i, ua);
2371
+ if (version) {
2372
+ browser.version = version;
2373
+ }
2374
+ return browser;
2375
+ }
2376
+ },
2377
+ {
2378
+ test: [/electron/i],
2379
+ describe(ua) {
2380
+ const browser = {
2381
+ name: "Electron"
2382
+ };
2383
+ const version = Utils.getFirstMatch(/(?:electron)\/(\d+(\.?_?\d+)+)/i, ua);
2384
+ if (version) {
2385
+ browser.version = version;
2386
+ }
2387
+ return browser;
2388
+ }
2389
+ },
2390
+ {
2391
+ test: [/MiuiBrowser/i],
2392
+ describe(ua) {
2393
+ const browser = {
2394
+ name: "Miui"
2395
+ };
2396
+ const version = Utils.getFirstMatch(/(?:MiuiBrowser)[\s/](\d+(\.?_?\d+)+)/i, ua);
2397
+ if (version) {
2398
+ browser.version = version;
2399
+ }
2400
+ return browser;
2401
+ }
2402
+ },
2403
+ {
2404
+ test: [/chromium/i],
2405
+ describe(ua) {
2406
+ const browser = {
2407
+ name: "Chromium"
2408
+ };
2409
+ const version = Utils.getFirstMatch(/(?:chromium)[\s/](\d+(\.?_?\d+)+)/i, ua) || Utils.getFirstMatch(commonVersionIdentifier, ua);
2410
+ if (version) {
2411
+ browser.version = version;
2412
+ }
2413
+ return browser;
2414
+ }
2415
+ },
2416
+ {
2417
+ test: [/chrome|crios|crmo/i],
2418
+ describe(ua) {
2419
+ const browser = {
2420
+ name: "Chrome"
2421
+ };
2422
+ const version = Utils.getFirstMatch(/(?:chrome|crios|crmo)\/(\d+(\.?_?\d+)+)/i, ua);
2423
+ if (version) {
2424
+ browser.version = version;
2425
+ }
2426
+ return browser;
2427
+ }
2428
+ },
2429
+ {
2430
+ test: [/GSA/i],
2431
+ describe(ua) {
2432
+ const browser = {
2433
+ name: "Google Search"
2434
+ };
2435
+ const version = Utils.getFirstMatch(/(?:GSA)\/(\d+(\.?_?\d+)+)/i, ua);
2436
+ if (version) {
2437
+ browser.version = version;
2438
+ }
2439
+ return browser;
2440
+ }
2441
+ },
2442
+ /* Android Browser */
2443
+ {
2444
+ test(parser) {
2445
+ const notLikeAndroid = !parser.test(/like android/i);
2446
+ const butAndroid = parser.test(/android/i);
2447
+ return notLikeAndroid && butAndroid;
2448
+ },
2449
+ describe(ua) {
2450
+ const browser = {
2451
+ name: "Android Browser"
2452
+ };
2453
+ const version = Utils.getFirstMatch(commonVersionIdentifier, ua);
2454
+ if (version) {
2455
+ browser.version = version;
2456
+ }
2457
+ return browser;
2458
+ }
2459
+ },
2460
+ /* PlayStation 4 */
2461
+ {
2462
+ test: [/playstation 4/i],
2463
+ describe(ua) {
2464
+ const browser = {
2465
+ name: "PlayStation 4"
2466
+ };
2467
+ const version = Utils.getFirstMatch(commonVersionIdentifier, ua);
2468
+ if (version) {
2469
+ browser.version = version;
2470
+ }
2471
+ return browser;
2472
+ }
2473
+ },
2474
+ /* Safari */
2475
+ {
2476
+ test: [/safari|applewebkit/i],
2477
+ describe(ua) {
2478
+ const browser = {
2479
+ name: "Safari"
2480
+ };
2481
+ const version = Utils.getFirstMatch(commonVersionIdentifier, ua);
2482
+ if (version) {
2483
+ browser.version = version;
2484
+ }
2485
+ return browser;
2486
+ }
2487
+ },
2488
+ /* Something else */
2489
+ {
2490
+ test: [/.*/i],
2491
+ describe(ua) {
2492
+ const regexpWithoutDeviceSpec = /^(.*)\/(.*) /;
2493
+ const regexpWithDeviceSpec = /^(.*)\/(.*)[ \t]\((.*)/;
2494
+ const hasDeviceSpec = ua.search("\\(") !== -1;
2495
+ const regexp = hasDeviceSpec ? regexpWithDeviceSpec : regexpWithoutDeviceSpec;
2496
+ return {
2497
+ name: Utils.getFirstMatch(regexp, ua),
2498
+ version: Utils.getSecondMatch(regexp, ua)
2499
+ };
2500
+ }
2501
+ }
2502
+ ];
2503
+ const osParsersList = [
2504
+ /* Roku */
2505
+ {
2506
+ test: [/Roku\/DVP/],
2507
+ describe(ua) {
2508
+ const version = Utils.getFirstMatch(/Roku\/DVP-(\d+\.\d+)/i, ua);
2509
+ return {
2510
+ name: OS_MAP.Roku,
2511
+ version
2512
+ };
2513
+ }
2514
+ },
2515
+ /* Windows Phone */
2516
+ {
2517
+ test: [/windows phone/i],
2518
+ describe(ua) {
2519
+ const version = Utils.getFirstMatch(/windows phone (?:os)?\s?(\d+(\.\d+)*)/i, ua);
2520
+ return {
2521
+ name: OS_MAP.WindowsPhone,
2522
+ version
2523
+ };
2524
+ }
2525
+ },
2526
+ /* Windows */
2527
+ {
2528
+ test: [/windows /i],
2529
+ describe(ua) {
2530
+ const version = Utils.getFirstMatch(/Windows ((NT|XP)( \d\d?.\d)?)/i, ua);
2531
+ const versionName = Utils.getWindowsVersionName(version);
2532
+ return {
2533
+ name: OS_MAP.Windows,
2534
+ version,
2535
+ versionName
2536
+ };
2537
+ }
2538
+ },
2539
+ /* Firefox on iPad */
2540
+ {
2541
+ test: [/Macintosh(.*?) FxiOS(.*?)\//],
2542
+ describe(ua) {
2543
+ const result = {
2544
+ name: OS_MAP.iOS
2545
+ };
2546
+ const version = Utils.getSecondMatch(/(Version\/)(\d[\d.]+)/, ua);
2547
+ if (version) {
2548
+ result.version = version;
2549
+ }
2550
+ return result;
2551
+ }
2552
+ },
2553
+ /* macOS */
2554
+ {
2555
+ test: [/macintosh/i],
2556
+ describe(ua) {
2557
+ const version = Utils.getFirstMatch(/mac os x (\d+(\.?_?\d+)+)/i, ua).replace(/[_\s]/g, ".");
2558
+ const versionName = Utils.getMacOSVersionName(version);
2559
+ const os = {
2560
+ name: OS_MAP.MacOS,
2561
+ version
2562
+ };
2563
+ if (versionName) {
2564
+ os.versionName = versionName;
2565
+ }
2566
+ return os;
2567
+ }
2568
+ },
2569
+ /* iOS */
2570
+ {
2571
+ test: [/(ipod|iphone|ipad)/i],
2572
+ describe(ua) {
2573
+ const version = Utils.getFirstMatch(/os (\d+([_\s]\d+)*) like mac os x/i, ua).replace(/[_\s]/g, ".");
2574
+ return {
2575
+ name: OS_MAP.iOS,
2576
+ version
2577
+ };
2578
+ }
2579
+ },
2580
+ /* Android */
2581
+ {
2582
+ test(parser) {
2583
+ const notLikeAndroid = !parser.test(/like android/i);
2584
+ const butAndroid = parser.test(/android/i);
2585
+ return notLikeAndroid && butAndroid;
2586
+ },
2587
+ describe(ua) {
2588
+ const version = Utils.getFirstMatch(/android[\s/-](\d+(\.\d+)*)/i, ua);
2589
+ const versionName = Utils.getAndroidVersionName(version);
2590
+ const os = {
2591
+ name: OS_MAP.Android,
2592
+ version
2593
+ };
2594
+ if (versionName) {
2595
+ os.versionName = versionName;
2596
+ }
2597
+ return os;
2598
+ }
2599
+ },
2600
+ /* WebOS */
2601
+ {
2602
+ test: [/(web|hpw)[o0]s/i],
2603
+ describe(ua) {
2604
+ const version = Utils.getFirstMatch(/(?:web|hpw)[o0]s\/(\d+(\.\d+)*)/i, ua);
2605
+ const os = {
2606
+ name: OS_MAP.WebOS
2607
+ };
2608
+ if (version && version.length) {
2609
+ os.version = version;
2610
+ }
2611
+ return os;
2612
+ }
2613
+ },
2614
+ /* BlackBerry */
2615
+ {
2616
+ test: [/blackberry|\bbb\d+/i, /rim\stablet/i],
2617
+ describe(ua) {
2618
+ const version = Utils.getFirstMatch(/rim\stablet\sos\s(\d+(\.\d+)*)/i, ua) || Utils.getFirstMatch(/blackberry\d+\/(\d+([_\s]\d+)*)/i, ua) || Utils.getFirstMatch(/\bbb(\d+)/i, ua);
2619
+ return {
2620
+ name: OS_MAP.BlackBerry,
2621
+ version
2622
+ };
2623
+ }
2624
+ },
2625
+ /* Bada */
2626
+ {
2627
+ test: [/bada/i],
2628
+ describe(ua) {
2629
+ const version = Utils.getFirstMatch(/bada\/(\d+(\.\d+)*)/i, ua);
2630
+ return {
2631
+ name: OS_MAP.Bada,
2632
+ version
2633
+ };
2634
+ }
2635
+ },
2636
+ /* Tizen */
2637
+ {
2638
+ test: [/tizen/i],
2639
+ describe(ua) {
2640
+ const version = Utils.getFirstMatch(/tizen[/\s](\d+(\.\d+)*)/i, ua);
2641
+ return {
2642
+ name: OS_MAP.Tizen,
2643
+ version
2644
+ };
2645
+ }
2646
+ },
2647
+ /* Linux */
2648
+ {
2649
+ test: [/linux/i],
2650
+ describe() {
2651
+ return {
2652
+ name: OS_MAP.Linux
2653
+ };
2654
+ }
2655
+ },
2656
+ /* Chrome OS */
2657
+ {
2658
+ test: [/CrOS/],
2659
+ describe() {
2660
+ return {
2661
+ name: OS_MAP.ChromeOS
2662
+ };
2663
+ }
2664
+ },
2665
+ /* Playstation 4 */
2666
+ {
2667
+ test: [/PlayStation 4/],
2668
+ describe(ua) {
2669
+ const version = Utils.getFirstMatch(/PlayStation 4[/\s](\d+(\.\d+)*)/i, ua);
2670
+ return {
2671
+ name: OS_MAP.PlayStation4,
2672
+ version
2673
+ };
2674
+ }
2675
+ }
2676
+ ];
2677
+ const platformParsersList = [
2678
+ /* Googlebot */
2679
+ {
2680
+ test: [/googlebot/i],
2681
+ describe() {
2682
+ return {
2683
+ type: "bot",
2684
+ vendor: "Google"
2685
+ };
2686
+ }
2687
+ },
2688
+ /* Huawei */
2689
+ {
2690
+ test: [/huawei/i],
2691
+ describe(ua) {
2692
+ const model = Utils.getFirstMatch(/(can-l01)/i, ua) && "Nova";
2693
+ const platform = {
2694
+ type: PLATFORMS_MAP.mobile,
2695
+ vendor: "Huawei"
2696
+ };
2697
+ if (model) {
2698
+ platform.model = model;
2699
+ }
2700
+ return platform;
2701
+ }
2702
+ },
2703
+ /* Nexus Tablet */
2704
+ {
2705
+ test: [/nexus\s*(?:7|8|9|10).*/i],
2706
+ describe() {
2707
+ return {
2708
+ type: PLATFORMS_MAP.tablet,
2709
+ vendor: "Nexus"
2710
+ };
2711
+ }
2712
+ },
2713
+ /* iPad */
2714
+ {
2715
+ test: [/ipad/i],
2716
+ describe() {
2717
+ return {
2718
+ type: PLATFORMS_MAP.tablet,
2719
+ vendor: "Apple",
2720
+ model: "iPad"
2721
+ };
2722
+ }
2723
+ },
2724
+ /* Firefox on iPad */
2725
+ {
2726
+ test: [/Macintosh(.*?) FxiOS(.*?)\//],
2727
+ describe() {
2728
+ return {
2729
+ type: PLATFORMS_MAP.tablet,
2730
+ vendor: "Apple",
2731
+ model: "iPad"
2732
+ };
2733
+ }
2734
+ },
2735
+ /* Amazon Kindle Fire */
2736
+ {
2737
+ test: [/kftt build/i],
2738
+ describe() {
2739
+ return {
2740
+ type: PLATFORMS_MAP.tablet,
2741
+ vendor: "Amazon",
2742
+ model: "Kindle Fire HD 7"
2743
+ };
2744
+ }
2745
+ },
2746
+ /* Another Amazon Tablet with Silk */
2747
+ {
2748
+ test: [/silk/i],
2749
+ describe() {
2750
+ return {
2751
+ type: PLATFORMS_MAP.tablet,
2752
+ vendor: "Amazon"
2753
+ };
2754
+ }
2755
+ },
2756
+ /* Tablet */
2757
+ {
2758
+ test: [/tablet(?! pc)/i],
2759
+ describe() {
2760
+ return {
2761
+ type: PLATFORMS_MAP.tablet
2762
+ };
2763
+ }
2764
+ },
2765
+ /* iPod/iPhone */
2766
+ {
2767
+ test(parser) {
2768
+ const iDevice = parser.test(/ipod|iphone/i);
2769
+ const likeIDevice = parser.test(/like (ipod|iphone)/i);
2770
+ return iDevice && !likeIDevice;
2771
+ },
2772
+ describe(ua) {
2773
+ const model = Utils.getFirstMatch(/(ipod|iphone)/i, ua);
2774
+ return {
2775
+ type: PLATFORMS_MAP.mobile,
2776
+ vendor: "Apple",
2777
+ model
2778
+ };
2779
+ }
2780
+ },
2781
+ /* Nexus Mobile */
2782
+ {
2783
+ test: [/nexus\s*[0-6].*/i, /galaxy nexus/i],
2784
+ describe() {
2785
+ return {
2786
+ type: PLATFORMS_MAP.mobile,
2787
+ vendor: "Nexus"
2788
+ };
2789
+ }
2790
+ },
2791
+ /* Mobile */
2792
+ {
2793
+ test: [/[^-]mobi/i],
2794
+ describe() {
2795
+ return {
2796
+ type: PLATFORMS_MAP.mobile
2797
+ };
2798
+ }
2799
+ },
2800
+ /* BlackBerry */
2801
+ {
2802
+ test(parser) {
2803
+ return parser.getBrowserName(true) === "blackberry";
2804
+ },
2805
+ describe() {
2806
+ return {
2807
+ type: PLATFORMS_MAP.mobile,
2808
+ vendor: "BlackBerry"
2809
+ };
2810
+ }
2811
+ },
2812
+ /* Bada */
2813
+ {
2814
+ test(parser) {
2815
+ return parser.getBrowserName(true) === "bada";
2816
+ },
2817
+ describe() {
2818
+ return {
2819
+ type: PLATFORMS_MAP.mobile
2820
+ };
2821
+ }
2822
+ },
2823
+ /* Windows Phone */
2824
+ {
2825
+ test(parser) {
2826
+ return parser.getBrowserName() === "windows phone";
2827
+ },
2828
+ describe() {
2829
+ return {
2830
+ type: PLATFORMS_MAP.mobile,
2831
+ vendor: "Microsoft"
2832
+ };
2833
+ }
2834
+ },
2835
+ /* Android Tablet */
2836
+ {
2837
+ test(parser) {
2838
+ const osMajorVersion = Number(String(parser.getOSVersion()).split(".")[0]);
2839
+ return parser.getOSName(true) === "android" && osMajorVersion >= 3;
2840
+ },
2841
+ describe() {
2842
+ return {
2843
+ type: PLATFORMS_MAP.tablet
2844
+ };
2845
+ }
2846
+ },
2847
+ /* Android Mobile */
2848
+ {
2849
+ test(parser) {
2850
+ return parser.getOSName(true) === "android";
2851
+ },
2852
+ describe() {
2853
+ return {
2854
+ type: PLATFORMS_MAP.mobile
2855
+ };
2856
+ }
2857
+ },
2858
+ /* desktop */
2859
+ {
2860
+ test(parser) {
2861
+ return parser.getOSName(true) === "macos";
2862
+ },
2863
+ describe() {
2864
+ return {
2865
+ type: PLATFORMS_MAP.desktop,
2866
+ vendor: "Apple"
2867
+ };
2868
+ }
2869
+ },
2870
+ /* Windows */
2871
+ {
2872
+ test(parser) {
2873
+ return parser.getOSName(true) === "windows";
2874
+ },
2875
+ describe() {
2876
+ return {
2877
+ type: PLATFORMS_MAP.desktop
2878
+ };
2879
+ }
2880
+ },
2881
+ /* Linux */
2882
+ {
2883
+ test(parser) {
2884
+ return parser.getOSName(true) === "linux";
2885
+ },
2886
+ describe() {
2887
+ return {
2888
+ type: PLATFORMS_MAP.desktop
2889
+ };
2890
+ }
2891
+ },
2892
+ /* PlayStation 4 */
2893
+ {
2894
+ test(parser) {
2895
+ return parser.getOSName(true) === "playstation 4";
2896
+ },
2897
+ describe() {
2898
+ return {
2899
+ type: PLATFORMS_MAP.tv
2900
+ };
2901
+ }
2902
+ },
2903
+ /* Roku */
2904
+ {
2905
+ test(parser) {
2906
+ return parser.getOSName(true) === "roku";
2907
+ },
2908
+ describe() {
2909
+ return {
2910
+ type: PLATFORMS_MAP.tv
2911
+ };
2912
+ }
2913
+ }
2914
+ ];
2915
+ const enginesParsersList = [
2916
+ /* EdgeHTML */
2917
+ {
2918
+ test(parser) {
2919
+ return parser.getBrowserName(true) === "microsoft edge";
2920
+ },
2921
+ describe(ua) {
2922
+ const isBlinkBased = /\sedg\//i.test(ua);
2923
+ if (isBlinkBased) {
2924
+ return {
2925
+ name: ENGINE_MAP.Blink
2926
+ };
2927
+ }
2928
+ const version = Utils.getFirstMatch(/edge\/(\d+(\.?_?\d+)+)/i, ua);
2929
+ return {
2930
+ name: ENGINE_MAP.EdgeHTML,
2931
+ version
2932
+ };
2933
+ }
2934
+ },
2935
+ /* Trident */
2936
+ {
2937
+ test: [/trident/i],
2938
+ describe(ua) {
2939
+ const engine = {
2940
+ name: ENGINE_MAP.Trident
2941
+ };
2942
+ const version = Utils.getFirstMatch(/trident\/(\d+(\.?_?\d+)+)/i, ua);
2943
+ if (version) {
2944
+ engine.version = version;
2945
+ }
2946
+ return engine;
2947
+ }
2948
+ },
2949
+ /* Presto */
2950
+ {
2951
+ test(parser) {
2952
+ return parser.test(/presto/i);
2953
+ },
2954
+ describe(ua) {
2955
+ const engine = {
2956
+ name: ENGINE_MAP.Presto
2957
+ };
2958
+ const version = Utils.getFirstMatch(/presto\/(\d+(\.?_?\d+)+)/i, ua);
2959
+ if (version) {
2960
+ engine.version = version;
2961
+ }
2962
+ return engine;
2963
+ }
2964
+ },
2965
+ /* Gecko */
2966
+ {
2967
+ test(parser) {
2968
+ const isGecko = parser.test(/gecko/i);
2969
+ const likeGecko = parser.test(/like gecko/i);
2970
+ return isGecko && !likeGecko;
2971
+ },
2972
+ describe(ua) {
2973
+ const engine = {
2974
+ name: ENGINE_MAP.Gecko
2975
+ };
2976
+ const version = Utils.getFirstMatch(/gecko\/(\d+(\.?_?\d+)+)/i, ua);
2977
+ if (version) {
2978
+ engine.version = version;
2979
+ }
2980
+ return engine;
2981
+ }
2982
+ },
2983
+ /* Blink */
2984
+ {
2985
+ test: [/(apple)?webkit\/537\.36/i],
2986
+ describe() {
2987
+ return {
2988
+ name: ENGINE_MAP.Blink
2989
+ };
2990
+ }
2991
+ },
2992
+ /* WebKit */
2993
+ {
2994
+ test: [/(apple)?webkit/i],
2995
+ describe(ua) {
2996
+ const engine = {
2997
+ name: ENGINE_MAP.WebKit
2998
+ };
2999
+ const version = Utils.getFirstMatch(/webkit\/(\d+(\.?_?\d+)+)/i, ua);
3000
+ if (version) {
3001
+ engine.version = version;
3002
+ }
3003
+ return engine;
3004
+ }
3005
+ }
3006
+ ];
3007
+ class Parser {
3008
+ /**
3009
+ * Create instance of Parser
3010
+ *
3011
+ * @param {String} UA User-Agent string
3012
+ * @param {Boolean} [skipParsing=false] parser can skip parsing in purpose of performance
3013
+ * improvements if you need to make a more particular parsing
3014
+ * like {@link Parser#parseBrowser} or {@link Parser#parsePlatform}
3015
+ *
3016
+ * @throw {Error} in case of empty UA String
3017
+ *
3018
+ * @constructor
3019
+ */
3020
+ constructor(UA, skipParsing = false) {
3021
+ if (UA === void 0 || UA === null || UA === "") {
3022
+ throw new Error("UserAgent parameter can't be empty");
3023
+ }
3024
+ this._ua = UA;
3025
+ this.parsedResult = {};
3026
+ if (skipParsing !== true) {
3027
+ this.parse();
3028
+ }
3029
+ }
3030
+ /**
3031
+ * Get UserAgent string of current Parser instance
3032
+ * @return {String} User-Agent String of the current <Parser> object
3033
+ *
3034
+ * @public
3035
+ */
3036
+ getUA() {
3037
+ return this._ua;
3038
+ }
3039
+ /**
3040
+ * Test a UA string for a regexp
3041
+ * @param {RegExp} regex
3042
+ * @return {Boolean}
3043
+ */
3044
+ test(regex) {
3045
+ return regex.test(this._ua);
3046
+ }
3047
+ /**
3048
+ * Get parsed browser object
3049
+ * @return {Object}
3050
+ */
3051
+ parseBrowser() {
3052
+ this.parsedResult.browser = {};
3053
+ const browserDescriptor = Utils.find(browsersList, (_browser) => {
3054
+ if (typeof _browser.test === "function") {
3055
+ return _browser.test(this);
3056
+ }
3057
+ if (_browser.test instanceof Array) {
3058
+ return _browser.test.some((condition) => this.test(condition));
3059
+ }
3060
+ throw new Error("Browser's test function is not valid");
3061
+ });
3062
+ if (browserDescriptor) {
3063
+ this.parsedResult.browser = browserDescriptor.describe(this.getUA());
3064
+ }
3065
+ return this.parsedResult.browser;
3066
+ }
3067
+ /**
3068
+ * Get parsed browser object
3069
+ * @return {Object}
3070
+ *
3071
+ * @public
3072
+ */
3073
+ getBrowser() {
3074
+ if (this.parsedResult.browser) {
3075
+ return this.parsedResult.browser;
3076
+ }
3077
+ return this.parseBrowser();
3078
+ }
3079
+ /**
3080
+ * Get browser's name
3081
+ * @return {String} Browser's name or an empty string
3082
+ *
3083
+ * @public
3084
+ */
3085
+ getBrowserName(toLowerCase) {
3086
+ if (toLowerCase) {
3087
+ return String(this.getBrowser().name).toLowerCase() || "";
3088
+ }
3089
+ return this.getBrowser().name || "";
3090
+ }
3091
+ /**
3092
+ * Get browser's version
3093
+ * @return {String} version of browser
3094
+ *
3095
+ * @public
3096
+ */
3097
+ getBrowserVersion() {
3098
+ return this.getBrowser().version;
3099
+ }
3100
+ /**
3101
+ * Get OS
3102
+ * @return {Object}
3103
+ *
3104
+ * @example
3105
+ * this.getOS();
3106
+ * {
3107
+ * name: 'macOS',
3108
+ * version: '10.11.12'
3109
+ * }
3110
+ */
3111
+ getOS() {
3112
+ if (this.parsedResult.os) {
3113
+ return this.parsedResult.os;
3114
+ }
3115
+ return this.parseOS();
3116
+ }
3117
+ /**
3118
+ * Parse OS and save it to this.parsedResult.os
3119
+ * @return {*|{}}
3120
+ */
3121
+ parseOS() {
3122
+ this.parsedResult.os = {};
3123
+ const os = Utils.find(osParsersList, (_os) => {
3124
+ if (typeof _os.test === "function") {
3125
+ return _os.test(this);
3126
+ }
3127
+ if (_os.test instanceof Array) {
3128
+ return _os.test.some((condition) => this.test(condition));
3129
+ }
3130
+ throw new Error("Browser's test function is not valid");
3131
+ });
3132
+ if (os) {
3133
+ this.parsedResult.os = os.describe(this.getUA());
3134
+ }
3135
+ return this.parsedResult.os;
3136
+ }
3137
+ /**
3138
+ * Get OS name
3139
+ * @param {Boolean} [toLowerCase] return lower-cased value
3140
+ * @return {String} name of the OS — macOS, Windows, Linux, etc.
3141
+ */
3142
+ getOSName(toLowerCase) {
3143
+ const { name } = this.getOS();
3144
+ if (toLowerCase) {
3145
+ return String(name).toLowerCase() || "";
3146
+ }
3147
+ return name || "";
3148
+ }
3149
+ /**
3150
+ * Get OS version
3151
+ * @return {String} full version with dots ('10.11.12', '5.6', etc)
3152
+ */
3153
+ getOSVersion() {
3154
+ return this.getOS().version;
3155
+ }
3156
+ /**
3157
+ * Get parsed platform
3158
+ * @return {{}}
3159
+ */
3160
+ getPlatform() {
3161
+ if (this.parsedResult.platform) {
3162
+ return this.parsedResult.platform;
3163
+ }
3164
+ return this.parsePlatform();
3165
+ }
3166
+ /**
3167
+ * Get platform name
3168
+ * @param {Boolean} [toLowerCase=false]
3169
+ * @return {*}
3170
+ */
3171
+ getPlatformType(toLowerCase = false) {
3172
+ const { type } = this.getPlatform();
3173
+ if (toLowerCase) {
3174
+ return String(type).toLowerCase() || "";
3175
+ }
3176
+ return type || "";
3177
+ }
3178
+ /**
3179
+ * Get parsed platform
3180
+ * @return {{}}
3181
+ */
3182
+ parsePlatform() {
3183
+ this.parsedResult.platform = {};
3184
+ const platform = Utils.find(platformParsersList, (_platform) => {
3185
+ if (typeof _platform.test === "function") {
3186
+ return _platform.test(this);
3187
+ }
3188
+ if (_platform.test instanceof Array) {
3189
+ return _platform.test.some((condition) => this.test(condition));
3190
+ }
3191
+ throw new Error("Browser's test function is not valid");
3192
+ });
3193
+ if (platform) {
3194
+ this.parsedResult.platform = platform.describe(this.getUA());
3195
+ }
3196
+ return this.parsedResult.platform;
3197
+ }
3198
+ /**
3199
+ * Get parsed engine
3200
+ * @return {{}}
3201
+ */
3202
+ getEngine() {
3203
+ if (this.parsedResult.engine) {
3204
+ return this.parsedResult.engine;
3205
+ }
3206
+ return this.parseEngine();
3207
+ }
3208
+ /**
3209
+ * Get engines's name
3210
+ * @return {String} Engines's name or an empty string
3211
+ *
3212
+ * @public
3213
+ */
3214
+ getEngineName(toLowerCase) {
3215
+ if (toLowerCase) {
3216
+ return String(this.getEngine().name).toLowerCase() || "";
3217
+ }
3218
+ return this.getEngine().name || "";
3219
+ }
3220
+ /**
3221
+ * Get parsed platform
3222
+ * @return {{}}
3223
+ */
3224
+ parseEngine() {
3225
+ this.parsedResult.engine = {};
3226
+ const engine = Utils.find(enginesParsersList, (_engine) => {
3227
+ if (typeof _engine.test === "function") {
3228
+ return _engine.test(this);
3229
+ }
3230
+ if (_engine.test instanceof Array) {
3231
+ return _engine.test.some((condition) => this.test(condition));
3232
+ }
3233
+ throw new Error("Browser's test function is not valid");
3234
+ });
3235
+ if (engine) {
3236
+ this.parsedResult.engine = engine.describe(this.getUA());
3237
+ }
3238
+ return this.parsedResult.engine;
3239
+ }
3240
+ /**
3241
+ * Parse full information about the browser
3242
+ * @returns {Parser}
3243
+ */
3244
+ parse() {
3245
+ this.parseBrowser();
3246
+ this.parseOS();
3247
+ this.parsePlatform();
3248
+ this.parseEngine();
3249
+ return this;
3250
+ }
3251
+ /**
3252
+ * Get parsed result
3253
+ * @return {ParsedResult}
3254
+ */
3255
+ getResult() {
3256
+ return Utils.assign({}, this.parsedResult);
3257
+ }
3258
+ /**
3259
+ * Check if parsed browser matches certain conditions
3260
+ *
3261
+ * @param {Object} checkTree It's one or two layered object,
3262
+ * which can include a platform or an OS on the first layer
3263
+ * and should have browsers specs on the bottom-laying layer
3264
+ *
3265
+ * @returns {Boolean|undefined} Whether the browser satisfies the set conditions or not.
3266
+ * Returns `undefined` when the browser is no described in the checkTree object.
3267
+ *
3268
+ * @example
3269
+ * const browser = Bowser.getParser(window.navigator.userAgent);
3270
+ * if (browser.satisfies({chrome: '>118.01.1322' }))
3271
+ * // or with os
3272
+ * if (browser.satisfies({windows: { chrome: '>118.01.1322' } }))
3273
+ * // or with platforms
3274
+ * if (browser.satisfies({desktop: { chrome: '>118.01.1322' } }))
3275
+ */
3276
+ satisfies(checkTree) {
3277
+ const platformsAndOSes = {};
3278
+ let platformsAndOSCounter = 0;
3279
+ const browsers = {};
3280
+ let browsersCounter = 0;
3281
+ const allDefinitions = Object.keys(checkTree);
3282
+ allDefinitions.forEach((key) => {
3283
+ const currentDefinition = checkTree[key];
3284
+ if (typeof currentDefinition === "string") {
3285
+ browsers[key] = currentDefinition;
3286
+ browsersCounter += 1;
3287
+ } else if (typeof currentDefinition === "object") {
3288
+ platformsAndOSes[key] = currentDefinition;
3289
+ platformsAndOSCounter += 1;
3290
+ }
3291
+ });
3292
+ if (platformsAndOSCounter > 0) {
3293
+ const platformsAndOSNames = Object.keys(platformsAndOSes);
3294
+ const OSMatchingDefinition = Utils.find(platformsAndOSNames, (name) => this.isOS(name));
3295
+ if (OSMatchingDefinition) {
3296
+ const osResult = this.satisfies(platformsAndOSes[OSMatchingDefinition]);
3297
+ if (osResult !== void 0) {
3298
+ return osResult;
3299
+ }
3300
+ }
3301
+ const platformMatchingDefinition = Utils.find(
3302
+ platformsAndOSNames,
3303
+ (name) => this.isPlatform(name)
3304
+ );
3305
+ if (platformMatchingDefinition) {
3306
+ const platformResult = this.satisfies(platformsAndOSes[platformMatchingDefinition]);
3307
+ if (platformResult !== void 0) {
3308
+ return platformResult;
3309
+ }
3310
+ }
3311
+ }
3312
+ if (browsersCounter > 0) {
3313
+ const browserNames = Object.keys(browsers);
3314
+ const matchingDefinition = Utils.find(browserNames, (name) => this.isBrowser(name, true));
3315
+ if (matchingDefinition !== void 0) {
3316
+ return this.compareVersion(browsers[matchingDefinition]);
3317
+ }
3318
+ }
3319
+ return void 0;
3320
+ }
3321
+ /**
3322
+ * Check if the browser name equals the passed string
3323
+ * @param browserName The string to compare with the browser name
3324
+ * @param [includingAlias=false] The flag showing whether alias will be included into comparison
3325
+ * @returns {boolean}
3326
+ */
3327
+ isBrowser(browserName, includingAlias = false) {
3328
+ const defaultBrowserName = this.getBrowserName().toLowerCase();
3329
+ let browserNameLower = browserName.toLowerCase();
3330
+ const alias = Utils.getBrowserTypeByAlias(browserNameLower);
3331
+ if (includingAlias && alias) {
3332
+ browserNameLower = alias.toLowerCase();
3333
+ }
3334
+ return browserNameLower === defaultBrowserName;
3335
+ }
3336
+ compareVersion(version) {
3337
+ let expectedResults = [0];
3338
+ let comparableVersion = version;
3339
+ let isLoose = false;
3340
+ const currentBrowserVersion = this.getBrowserVersion();
3341
+ if (typeof currentBrowserVersion !== "string") {
3342
+ return void 0;
3343
+ }
3344
+ if (version[0] === ">" || version[0] === "<") {
3345
+ comparableVersion = version.substr(1);
3346
+ if (version[1] === "=") {
3347
+ isLoose = true;
3348
+ comparableVersion = version.substr(2);
3349
+ } else {
3350
+ expectedResults = [];
3351
+ }
3352
+ if (version[0] === ">") {
3353
+ expectedResults.push(1);
3354
+ } else {
3355
+ expectedResults.push(-1);
3356
+ }
3357
+ } else if (version[0] === "=") {
3358
+ comparableVersion = version.substr(1);
3359
+ } else if (version[0] === "~") {
3360
+ isLoose = true;
3361
+ comparableVersion = version.substr(1);
3362
+ }
3363
+ return expectedResults.indexOf(
3364
+ Utils.compareVersions(currentBrowserVersion, comparableVersion, isLoose)
3365
+ ) > -1;
3366
+ }
3367
+ isOS(osName) {
3368
+ return this.getOSName(true) === String(osName).toLowerCase();
3369
+ }
3370
+ isPlatform(platformType) {
3371
+ return this.getPlatformType(true) === String(platformType).toLowerCase();
3372
+ }
3373
+ isEngine(engineName) {
3374
+ return this.getEngineName(true) === String(engineName).toLowerCase();
3375
+ }
3376
+ /**
3377
+ * Is anything? Check if the browser is called "anything",
3378
+ * the OS called "anything" or the platform called "anything"
3379
+ * @param {String} anything
3380
+ * @param [includingAlias=false] The flag showing whether alias will be included into comparison
3381
+ * @returns {Boolean}
3382
+ */
3383
+ is(anything, includingAlias = false) {
3384
+ return this.isBrowser(anything, includingAlias) || this.isOS(anything) || this.isPlatform(anything);
3385
+ }
3386
+ /**
3387
+ * Check if any of the given values satisfies this.is(anything)
3388
+ * @param {String[]} anythings
3389
+ * @returns {Boolean}
3390
+ */
3391
+ some(anythings = []) {
3392
+ return anythings.some((anything) => this.is(anything));
3393
+ }
3394
+ }
3395
+ /*!
3396
+ * Bowser - a browser detector
3397
+ * https://github.com/lancedikson/bowser
3398
+ * MIT License | (c) Dustin Diaz 2012-2015
3399
+ * MIT License | (c) Denis Demchenko 2015-2019
3400
+ */
3401
+ class Bowser {
3402
+ /**
3403
+ * Creates a {@link Parser} instance
3404
+ *
3405
+ * @param {String} UA UserAgent string
3406
+ * @param {Boolean} [skipParsing=false] Will make the Parser postpone parsing until you ask it
3407
+ * explicitly. Same as `skipParsing` for {@link Parser}.
3408
+ * @returns {Parser}
3409
+ * @throws {Error} when UA is not a String
3410
+ *
3411
+ * @example
3412
+ * const parser = Bowser.getParser(window.navigator.userAgent);
3413
+ * const result = parser.getResult();
3414
+ */
3415
+ static getParser(UA, skipParsing = false) {
3416
+ if (typeof UA !== "string") {
3417
+ throw new Error("UserAgent should be a string");
3418
+ }
3419
+ return new Parser(UA, skipParsing);
3420
+ }
3421
+ /**
3422
+ * Creates a {@link Parser} instance and runs {@link Parser.getResult} immediately
3423
+ *
3424
+ * @param UA
3425
+ * @return {ParsedResult}
3426
+ *
3427
+ * @example
3428
+ * const result = Bowser.parse(window.navigator.userAgent);
3429
+ */
3430
+ static parse(UA) {
3431
+ return new Parser(UA).getResult();
3432
+ }
3433
+ static get BROWSER_MAP() {
3434
+ return BROWSER_MAP;
3435
+ }
3436
+ static get ENGINE_MAP() {
3437
+ return ENGINE_MAP;
3438
+ }
3439
+ static get OS_MAP() {
3440
+ return OS_MAP;
3441
+ }
3442
+ static get PLATFORMS_MAP() {
3443
+ return PLATFORMS_MAP;
3444
+ }
3445
+ }
3446
+ class LocalStorageProxy {
3447
+ constructor() {
3448
+ var _a;
3449
+ this.useLocalStorage = true;
3450
+ this.memoryStorage = {};
3451
+ try {
3452
+ localStorage.setItem(
3453
+ PpLocalStorageKey.initializedAt,
3454
+ Date.now().toString()
3455
+ );
3456
+ for (let i = 0; i < localStorage.length; i++) {
3457
+ const key = localStorage.key(i);
3458
+ if (key != null) {
3459
+ this.memoryStorage[key] = (_a = localStorage.getItem(key)) != null ? _a : "";
3460
+ }
3461
+ }
3462
+ } catch (e) {
3463
+ this.useLocalStorage = false;
3464
+ }
3465
+ }
3466
+ getItem(key) {
3467
+ var _a;
3468
+ if (this.useLocalStorage) {
3469
+ try {
3470
+ if (localStorage.getItem(PpLocalStorageKey.initializedAt) != null) {
3471
+ return localStorage.getItem(key);
3472
+ } else {
3473
+ console.debug("local storage value has lost unexpectedly.");
3474
+ addBreadcrumbToSentry({
3475
+ message: "local storage value has lost unexpectedly.",
3476
+ category: "storage"
3477
+ });
3478
+ }
3479
+ } catch (e) {
3480
+ }
3481
+ }
3482
+ this.useLocalStorage = false;
3483
+ return (_a = this.memoryStorage[key]) != null ? _a : null;
3484
+ }
3485
+ setItem(key, value) {
3486
+ this.memoryStorage[key] = value;
3487
+ if (this.useLocalStorage) {
3488
+ try {
3489
+ localStorage.setItem(key, value);
3490
+ } catch (e) {
3491
+ this.useLocalStorage = false;
3492
+ console.warn("localStorage has become unavailable.");
3493
+ }
3494
+ }
3495
+ }
3496
+ removeItem(key) {
3497
+ delete this.memoryStorage[key];
3498
+ try {
3499
+ localStorage.removeItem(key);
3500
+ } catch (e) {
3501
+ this.useLocalStorage = false;
3502
+ }
3503
+ }
3504
+ clear() {
3505
+ try {
3506
+ localStorage.clear();
3507
+ localStorage.setItem(
3508
+ PpLocalStorageKey.initializedAt,
3509
+ Date.now().toString()
3510
+ );
3511
+ } catch (e) {
3512
+ }
3513
+ this.memoryStorage = {};
3514
+ }
3515
+ }
3516
+ function writeCookie(key, value) {
3517
+ api.set(key, value, __spreadValues({
3518
+ expires: 365,
3519
+ sameSite: "None"
3520
+ }, { secure: true, Partitioned: true }));
3521
+ }
3522
+ class CookieStorageProxy {
3523
+ constructor() {
3524
+ var _a;
3525
+ this.useCookie = true;
3526
+ this.memoryStorage = {};
3527
+ try {
3528
+ writeCookie(PpLocalStorageKey.initializedAt, Date.now().toString());
3529
+ const cookies = api.get();
3530
+ for (const key in cookies) {
3531
+ this.memoryStorage[key] = (_a = cookies[key]) != null ? _a : "";
3532
+ }
3533
+ } catch (e) {
3534
+ this.useCookie = false;
3535
+ }
3536
+ }
3537
+ getItem(key) {
3538
+ var _a;
3539
+ if (this.useCookie) {
3540
+ try {
3541
+ if (api.get(PpLocalStorageKey.initializedAt) != null) {
3542
+ const val = api.get(key);
3543
+ if (val != null) {
3544
+ return val;
3545
+ }
3546
+ return localStorage.getItem(key);
3547
+ } else {
3548
+ addBreadcrumbToSentry({
3549
+ message: "cookie value has lost unexpectedly.",
3550
+ category: "storage"
3551
+ });
3552
+ }
3553
+ } catch (e) {
3554
+ }
3555
+ }
3556
+ this.useCookie = false;
3557
+ return (_a = this.memoryStorage[key]) != null ? _a : null;
3558
+ }
3559
+ setItem(key, value) {
3560
+ this.memoryStorage[key] = value;
3561
+ if (this.useCookie) {
3562
+ try {
3563
+ writeCookie(key, value);
3564
+ localStorage.removeItem(key);
3565
+ } catch (e) {
3566
+ this.useCookie = false;
3567
+ console.warn("cookie has become unavailable.");
3568
+ }
3569
+ }
3570
+ }
3571
+ removeItem(key) {
3572
+ delete this.memoryStorage[key];
3573
+ try {
3574
+ api.remove(key);
3575
+ localStorage.removeItem(key);
3576
+ } catch (e) {
3577
+ this.useCookie = false;
3578
+ }
3579
+ }
3580
+ clear() {
3581
+ try {
3582
+ localStorage.clear();
3583
+ const cookies = api.get();
3584
+ for (const key in cookies) {
3585
+ api.remove(key);
3586
+ }
3587
+ writeCookie(PpLocalStorageKey.initializedAt, Date.now().toString());
3588
+ } catch (e) {
3589
+ }
3590
+ this.memoryStorage = {};
3591
+ }
3592
+ }
3593
+ (() => {
3594
+ const browser = Bowser.getParser(window.navigator.userAgent);
3595
+ if (browser.satisfies({ safari: ">=18.4", chrome: ">=0", edge: ">=0" })) {
3596
+ return new CookieStorageProxy();
3597
+ }
3598
+ return new LocalStorageProxy();
3599
+ })();
3600
+ function isFunction(val) {
3601
+ return typeof val === "function";
3602
+ }
3603
+ function getRandomString() {
3604
+ return Math.random().toString(36).substring(7);
3605
+ }
3606
+ function setCookie({ name, value, options }) {
3607
+ return api.set(name, value, options);
3608
+ }
3609
+ function getCookie({ name }) {
3610
+ return api.get(name);
3611
+ }
3612
+ function removeCookie({ name, options }) {
3613
+ return api.remove(name, options);
3614
+ }
3615
+ function setLocalStorage({
3616
+ name,
3617
+ value
3618
+ }) {
3619
+ return localStorage.setItem(name, value);
3620
+ }
3621
+ function getLocalStorage({ name }) {
3622
+ return localStorage.getItem(name);
3623
+ }
3624
+ function removeLocalStorage({ name }) {
3625
+ return localStorage.removeItem(name);
3626
+ }
3627
+ function setSessionStorage({
3628
+ name,
3629
+ value
3630
+ }) {
3631
+ return sessionStorage.setItem(name, value);
3632
+ }
3633
+ function getSessionStorage({ name }) {
3634
+ return sessionStorage.getItem(name);
3635
+ }
3636
+ function removeSessionStorage({ name }) {
3637
+ return sessionStorage.removeItem(name);
3638
+ }
3639
+ function removeQueryParametersFromUrl(removeParams) {
3640
+ const url = new URL(window.location.href);
3641
+ removeParams.forEach((param) => url.searchParams.delete(param));
3642
+ const newURL = `${url.pathname}${url.search}`;
3643
+ history.replaceState(history.state, "", newURL);
3644
+ }
3645
+ function getUrl() {
3646
+ return window.location.href;
3647
+ }
3648
+ const clientWindowBridgeFunctions = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
3649
+ __proto__: null,
3650
+ getCookie,
3651
+ getLocalStorage,
3652
+ getSessionStorage,
3653
+ getUrl,
3654
+ removeCookie,
3655
+ removeLocalStorage,
3656
+ removeQueryParametersFromUrl,
3657
+ removeSessionStorage,
3658
+ setCookie,
3659
+ setLocalStorage,
3660
+ setSessionStorage
3661
+ }, Symbol.toStringTag, { value: "Module" }));
3662
+ const IFRAME_NAME = "ppmna-iframe";
3663
+ const IFRAME_CONTAINER_NAME = "ppsdk-container";
3664
+ let iframeContainer;
3665
+ function getCoreIframeContainer() {
3666
+ if (!iframeContainer) {
3667
+ iframeContainer = createIframeContainer();
3668
+ }
3669
+ return iframeContainer;
3670
+ }
3671
+ function createIframeContainer() {
3672
+ const frameExists = document.getElementById(IFRAME_NAME);
3673
+ if (frameExists) {
3674
+ return;
3675
+ }
3676
+ const container = document.createElement("div");
3677
+ document.createElement("div");
3678
+ container.setAttribute("id", IFRAME_CONTAINER_NAME);
3679
+ container.setAttribute("class", IFRAME_CONTAINER_NAME);
3680
+ container.style.all = "initial";
3681
+ container.style.display = "none";
3682
+ container.style.position = "fixed";
3683
+ container.style.width = "100%";
3684
+ container.style.height = "100%";
3685
+ container.style.top = "0";
3686
+ container.style.left = "0";
3687
+ container.style.zIndex = "2147483637";
3688
+ document.body.appendChild(container);
3689
+ return container;
3690
+ }
3691
+ function showCoreIframe(visible) {
3692
+ const container = getCoreIframeContainer();
3693
+ if (container) {
3694
+ container.style.display = visible ? "initial" : "none";
3695
+ }
3696
+ }
3697
+ let coreIframeLoadingPromise;
3698
+ function getCoreIframe() {
3699
+ if (!coreIframeLoadingPromise) {
3700
+ coreIframeLoadingPromise = createIframe();
3701
+ }
3702
+ return coreIframeLoadingPromise;
3703
+ }
3704
+ function getCoreIframeWindow() {
3705
+ return getCoreIframe().then((iframe) => iframe == null ? void 0 : iframe.contentWindow).catch(() => null);
3706
+ }
3707
+ function createIframe() {
3708
+ return new Promise((resolve, reject) => {
3709
+ if (document.readyState === "loading") {
3710
+ document.addEventListener("DOMContentLoaded", () => {
3711
+ create();
3712
+ });
3713
+ } else {
3714
+ create();
3715
+ }
3716
+ function create() {
3717
+ const iframe = document.createElement("iframe");
3718
+ iframe.setAttribute("src", CORE_IFRAME_URL);
3719
+ iframe.setAttribute("name", IFRAME_NAME);
3720
+ iframe.setAttribute("id", IFRAME_NAME);
3721
+ iframe.setAttribute("class", IFRAME_NAME);
3722
+ iframe.setAttribute("allow", "geolocation");
3723
+ iframe.onload = () => {
3724
+ resolve(iframe);
3725
+ iframe.onerror = null;
3726
+ };
3727
+ iframe.onerror = reject;
3728
+ iframe.style.all = "initial";
3729
+ iframe.style.width = "100%";
3730
+ iframe.style.height = "100%";
3731
+ iframe.style.border = "none";
1726
3732
  const container = getCoreIframeContainer();
1727
3733
  if (container) {
1728
3734
  container.innerHTML = "";
@@ -1865,22 +3871,33 @@ const INIT_STATUS_CODE_REMAP = {
1865
3871
  function callbackToPromise(target, functionName) {
1866
3872
  return (params = {}) => {
1867
3873
  return new Promise((resolve, reject) => {
3874
+ let _error;
3875
+ let _result;
1868
3876
  target(__spreadProps(__spreadValues({}, params), {
1869
3877
  success: (result) => {
1870
3878
  var _a;
1871
- resolve(result);
3879
+ _result = result;
1872
3880
  (_a = params.success) == null ? void 0 : _a.call(params, result);
1873
3881
  },
1874
3882
  fail: (error) => {
1875
3883
  var _a;
1876
3884
  if (functionName === "init" && INIT_STATUS_CODE_REMAP[error.errorCode]) {
1877
- resolve({
3885
+ _result = {
1878
3886
  statusCode: INIT_STATUS_CODE_REMAP[error.errorCode]
1879
- });
3887
+ };
1880
3888
  } else {
1881
- reject(error);
3889
+ _error = error;
1882
3890
  }
1883
3891
  (_a = params.fail) == null ? void 0 : _a.call(params, error);
3892
+ },
3893
+ complete: () => {
3894
+ var _a;
3895
+ if (_error) {
3896
+ reject(_error);
3897
+ } else {
3898
+ resolve(_result);
3899
+ }
3900
+ (_a = params.complete) == null ? void 0 : _a.call(params);
1884
3901
  }
1885
3902
  }));
1886
3903
  });
@@ -1934,7 +3951,7 @@ addEventListener("popstate", () => {
1934
3951
  function init(params) {
1935
3952
  const refreshToken = getRefreshToken(params.clientId);
1936
3953
  const codeVerifier = getCodeVerifier(params.clientId);
1937
- const clientVersion = "2.48.0";
3954
+ const clientVersion = "2.51.0";
1938
3955
  const initParams = {
1939
3956
  env: params.env,
1940
3957
  mode: params.mode,
@@ -2014,8 +4031,8 @@ function executePendingFunctionCalls(client2) {
2014
4031
  }
2015
4032
  }
2016
4033
  const clientProperties = {
2017
- version: "2.48.0",
2018
- revision: "765ecbf"
4034
+ version: "2.51.0",
4035
+ revision: "9c03362"
2019
4036
  };
2020
4037
  function isInitClientParams(params) {
2021
4038
  return params.clientId !== void 0;
@@ -2129,7 +4146,7 @@ const logout = promiseToCallback("logout", () => __async(void 0, null, function*
2129
4146
  return { statusCode: MiniAppStatusType.loggedOut };
2130
4147
  } catch (error) {
2131
4148
  throw new PPError(
2132
- `An error ocurred while trying to logout the user, error=${error}`,
4149
+ `An error occurred while trying to logout the user, error=${error}`,
2133
4150
  MiniAppErrorType.unknown
2134
4151
  );
2135
4152
  }
@@ -2191,7 +4208,7 @@ const renderCoupons = promiseToCallback(
2191
4208
  });
2192
4209
  } catch (error) {
2193
4210
  throw new PPError(
2194
- `An error ocurred while displaying coupons, merchantId=${merchantId}, couponId=${couponId}, error=${error}`,
4211
+ `An error occurred while displaying coupons, merchantId=${merchantId}, couponId=${couponId}, error=${error}`,
2195
4212
  MiniAppErrorType.unknown
2196
4213
  );
2197
4214
  }