@be-link/cls-logger 1.0.1-beta.9 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -562,6 +562,19 @@ function getPagePath$1() {
562
562
  return '';
563
563
  }
564
564
  }
565
+ function getMpPagePath() {
566
+ try {
567
+ const pages = globalThis.getCurrentPages?.();
568
+ if (Array.isArray(pages) && pages.length > 0) {
569
+ const page = pages[pages.length - 1];
570
+ return page.route || page.__route__ || '';
571
+ }
572
+ return '';
573
+ }
574
+ catch {
575
+ return '';
576
+ }
577
+ }
565
578
  function normalizeErrorLike(err, maxTextLength) {
566
579
  if (err && typeof err === 'object') {
567
580
  const anyErr = err;
@@ -721,6 +734,7 @@ function installMiniProgramErrorMonitor(report, options) {
721
734
  return;
722
735
  const e = normalizeErrorLike(msg, options.maxTextLength);
723
736
  const payload = {
737
+ pagePath: getMpPagePath(),
724
738
  source: 'wx.onError',
725
739
  message: e.message,
726
740
  errorName: e.name,
@@ -747,6 +761,7 @@ function installMiniProgramErrorMonitor(report, options) {
747
761
  return;
748
762
  const e = normalizeErrorLike(res?.reason, options.maxTextLength);
749
763
  const payload = {
764
+ pagePath: getMpPagePath(),
750
765
  source: 'wx.onUnhandledRejection',
751
766
  message: e.message,
752
767
  errorName: e.name,
@@ -778,6 +793,7 @@ function installMiniProgramErrorMonitor(report, options) {
778
793
  if (sampleHit$1(options.sampleRate)) {
779
794
  const e = normalizeErrorLike(args?.[0], options.maxTextLength);
780
795
  const payload = {
796
+ pagePath: getMpPagePath(),
781
797
  source: 'App.onError',
782
798
  message: e.message,
783
799
  errorName: e.name,
@@ -801,6 +817,7 @@ function installMiniProgramErrorMonitor(report, options) {
801
817
  const reason = args?.[0]?.reason ?? args?.[0];
802
818
  const e = normalizeErrorLike(reason, options.maxTextLength);
803
819
  const payload = {
820
+ pagePath: getMpPagePath(),
804
821
  source: 'App.onUnhandledRejection',
805
822
  message: e.message,
806
823
  errorName: e.name,
@@ -1108,18 +1125,28 @@ function installMiniProgramPerformanceMonitor(report, options) {
1108
1125
  continue;
1109
1126
  // Page Render: firstRender
1110
1127
  if (entry.entryType === 'render' && entry.name === 'firstRender') {
1128
+ const duration = typeof entry.duration === 'number'
1129
+ ? entry.duration
1130
+ : typeof entry.startTime === 'number' && typeof entry.endTime === 'number'
1131
+ ? entry.endTime - entry.startTime
1132
+ : 0;
1111
1133
  report(options.reportType, {
1112
1134
  metric: 'page-render',
1113
- duration: entry.duration,
1135
+ duration,
1114
1136
  pagePath: entry.path || '',
1115
1137
  unit: 'ms',
1116
1138
  });
1117
1139
  }
1118
1140
  // Route Switch: route
1119
1141
  else if (entry.entryType === 'navigation' && entry.name === 'route') {
1142
+ const duration = typeof entry.duration === 'number'
1143
+ ? entry.duration
1144
+ : typeof entry.startTime === 'number' && typeof entry.endTime === 'number'
1145
+ ? entry.endTime - entry.startTime
1146
+ : 0;
1120
1147
  report(options.reportType, {
1121
1148
  metric: 'route',
1122
- duration: entry.duration,
1149
+ duration,
1123
1150
  pagePath: entry.path || '',
1124
1151
  unit: 'ms',
1125
1152
  });
@@ -1463,7 +1490,7 @@ function installBehaviorMonitor(report, envType, options = {}) {
1463
1490
  const tag = (el.tagName || '').toLowerCase();
1464
1491
  const trackId = getAttr(el, clickTrackIdAttr);
1465
1492
  // 过滤无效点击:白名单 tag + 没有 trackId
1466
- if (clickWhiteList.includes(tag) && !trackId)
1493
+ if (clickWhiteList.includes(tag) || !trackId)
1467
1494
  return;
1468
1495
  void uvStatePromise.then(({ uvId, meta }) => {
1469
1496
  if (destroyed)
@@ -1504,8 +1531,12 @@ function installBehaviorMonitor(report, envType, options = {}) {
1504
1531
  g.Page = function patchedPage(conf) {
1505
1532
  const originalOnShow = conf?.onShow;
1506
1533
  conf.onShow = function (...args) {
1507
- if (pvEnabled)
1508
- reportPv(getPagePath());
1534
+ if (pvEnabled) {
1535
+ const pagePath = getPagePath();
1536
+ if (pagePath?.length > 0) {
1537
+ reportPv(pagePath);
1538
+ }
1539
+ }
1509
1540
  return typeof originalOnShow === 'function' ? originalOnShow.apply(this, args) : undefined;
1510
1541
  };
1511
1542
  // 点击:wrap 页面 methods(bindtap 等会调用到这里的 handler)
@@ -1889,9 +1920,14 @@ class ClsLoggerCore {
1889
1920
  * 子类可按需重写(默认检测 wx)
1890
1921
  */
1891
1922
  detectEnvType() {
1892
- const wxAny = globalThis.wx;
1893
- if (wxAny && typeof wxAny.getSystemInfoSync === 'function')
1923
+ const g = globalThis;
1924
+ // 微信、支付宝、字节跳动、UniApp 等小程序环境通常都有特定全局变量
1925
+ if ((g.wx && typeof g.wx.getSystemInfoSync === 'function') ||
1926
+ (g.my && typeof g.my.getSystemInfoSync === 'function') ||
1927
+ (g.tt && typeof g.tt.getSystemInfoSync === 'function') ||
1928
+ (g.uni && typeof g.uni.getSystemInfoSync === 'function')) {
1894
1929
  return 'miniprogram';
1930
+ }
1895
1931
  return 'browser';
1896
1932
  }
1897
1933
  init(options) {
@@ -2264,15 +2300,57 @@ class ClsLoggerCore {
2264
2300
  return nowTs + this.batchIntervalMs;
2265
2301
  }
2266
2302
  info(message, data = {}) {
2267
- const payload = normalizeFlatFields({ message, ...data }, 'info');
2303
+ let msg = '';
2304
+ let extra = {};
2305
+ if (message instanceof Error) {
2306
+ msg = message.message;
2307
+ extra = {
2308
+ stack: message.stack,
2309
+ name: message.name,
2310
+ ...data,
2311
+ };
2312
+ }
2313
+ else {
2314
+ msg = String(message);
2315
+ extra = data;
2316
+ }
2317
+ const payload = normalizeFlatFields({ message: msg, ...extra }, 'info');
2268
2318
  this.report({ type: 'info', data: payload, timestamp: Date.now() });
2269
2319
  }
2270
2320
  warn(message, data = {}) {
2271
- const payload = normalizeFlatFields({ message, ...data }, 'warn');
2321
+ let msg = '';
2322
+ let extra = {};
2323
+ if (message instanceof Error) {
2324
+ msg = message.message;
2325
+ extra = {
2326
+ stack: message.stack,
2327
+ name: message.name,
2328
+ ...data,
2329
+ };
2330
+ }
2331
+ else {
2332
+ msg = String(message);
2333
+ extra = data;
2334
+ }
2335
+ const payload = normalizeFlatFields({ message: msg, ...extra }, 'warn');
2272
2336
  this.report({ type: 'warn', data: payload, timestamp: Date.now() });
2273
2337
  }
2274
2338
  error(message, data = {}) {
2275
- const payload = normalizeFlatFields({ message, ...data }, 'error');
2339
+ let msg = '';
2340
+ let extra = {};
2341
+ if (message instanceof Error) {
2342
+ msg = message.message;
2343
+ extra = {
2344
+ stack: message.stack,
2345
+ name: message.name,
2346
+ ...data,
2347
+ };
2348
+ }
2349
+ else {
2350
+ msg = String(message);
2351
+ extra = data;
2352
+ }
2353
+ const payload = normalizeFlatFields({ message: msg, ...extra }, 'error');
2276
2354
  this.report({ type: 'error', data: payload, timestamp: Date.now() });
2277
2355
  }
2278
2356
  track(trackType, data = {}) {
@@ -2494,38 +2572,78 @@ class ClsLogger extends ClsLoggerCore {
2494
2572
  }
2495
2573
  }
2496
2574
  const isMini = this.envType === 'miniprogram';
2497
- // 静态字面量,方便打包器识别(但在此兼容入口里,仍然可能被一起分析)
2498
- const WEB_SDK = 'tencentcloud-cls-sdk-js-web';
2499
- const MINI_SDK = 'tencentcloud-cls-sdk-js-mini';
2500
- // UMD(浏览器脚本)优先读全局变量
2501
- if (!isMini) {
2575
+ // 3) 尝试 require / 全局变量
2576
+ // Mini Program: 尝试直接 require
2577
+ if (isMini) {
2578
+ // 显式使用字面量 require,帮助打包工具识别依赖(尤其是 CJS 构建模式下)
2579
+ try {
2580
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
2581
+ const req = typeof require === 'function' ? require('tencentcloud-cls-sdk-js-mini') : null;
2582
+ const reqSdk = normalizeSdk(req);
2583
+ if (reqSdk) {
2584
+ this.sdk = reqSdk;
2585
+ return reqSdk;
2586
+ }
2587
+ }
2588
+ catch {
2589
+ // ignore
2590
+ }
2591
+ // 尝试使用 tryRequire(作为补充)
2592
+ const reqMod = tryRequire('tencentcloud-cls-sdk-js-mini');
2593
+ const reqSdk = normalizeSdk(reqMod);
2594
+ if (reqSdk) {
2595
+ this.sdk = reqSdk;
2596
+ return reqSdk;
2597
+ }
2598
+ }
2599
+ else {
2600
+ // Web: 优先读全局变量 (UMD)
2502
2601
  const g = readGlobal('tencentcloudClsSdkJsWeb');
2503
2602
  const sdk = normalizeSdk(g);
2504
2603
  if (sdk) {
2505
2604
  this.sdk = sdk;
2506
2605
  return sdk;
2507
2606
  }
2607
+ // Web: 尝试 require
2608
+ const reqMod = tryRequire('tencentcloud-cls-sdk-js-web');
2609
+ const reqSdk = normalizeSdk(reqMod);
2610
+ if (reqSdk) {
2611
+ this.sdk = reqSdk;
2612
+ return reqSdk;
2613
+ }
2614
+ }
2615
+ // 4) 动态 import
2616
+ // 使用字符串字面量,确保 Bundler 能正确识别并进行 Code Splitting
2617
+ if (isMini) {
2618
+ this.sdkPromise = import('tencentcloud-cls-sdk-js-mini')
2619
+ .then((m) => {
2620
+ const sdk = normalizeSdk(m);
2621
+ if (!sdk)
2622
+ throw new Error(`ClsLogger.loadSdk: invalid sdk module for mini`);
2623
+ this.sdk = sdk;
2624
+ return sdk;
2625
+ })
2626
+ .catch((err) => {
2627
+ this.sdkPromise = null;
2628
+ console.error('[ClsLogger] Failed to load mini sdk:', err);
2629
+ throw err;
2630
+ });
2631
+ }
2632
+ else {
2633
+ this.sdkPromise = import('tencentcloud-cls-sdk-js-web')
2634
+ .then((m) => {
2635
+ const sdk = normalizeSdk(m);
2636
+ if (!sdk)
2637
+ throw new Error(`ClsLogger.loadSdk: invalid sdk module for web`);
2638
+ this.sdk = sdk;
2639
+ return sdk;
2640
+ })
2641
+ .catch((err) => {
2642
+ this.sdkPromise = null;
2643
+ console.error('[ClsLogger] Failed to load web sdk:', err);
2644
+ throw err;
2645
+ });
2508
2646
  }
2509
- // 尽量同步 require
2510
- const reqMod = tryRequire(isMini ? MINI_SDK : WEB_SDK);
2511
- const reqSdk = normalizeSdk(reqMod);
2512
- if (reqSdk) {
2513
- this.sdk = reqSdk;
2514
- return reqSdk;
2515
- }
2516
- // 动态 import
2517
- this.sdkPromise = (isMini ? import(MINI_SDK) : import(WEB_SDK))
2518
- .then((m) => {
2519
- const sdk = normalizeSdk(m);
2520
- if (!sdk)
2521
- throw new Error(`ClsLogger.loadSdk: invalid sdk module for ${isMini ? MINI_SDK : WEB_SDK}`);
2522
- this.sdk = sdk;
2523
- return sdk;
2524
- })
2525
- .catch((err) => {
2526
- this.sdkPromise = null;
2527
- throw err;
2528
- });
2529
2647
  return this.sdkPromise;
2530
2648
  }
2531
2649
  }
package/dist/index.umd.js CHANGED
@@ -564,6 +564,19 @@
564
564
  return '';
565
565
  }
566
566
  }
567
+ function getMpPagePath() {
568
+ try {
569
+ const pages = globalThis.getCurrentPages?.();
570
+ if (Array.isArray(pages) && pages.length > 0) {
571
+ const page = pages[pages.length - 1];
572
+ return page.route || page.__route__ || '';
573
+ }
574
+ return '';
575
+ }
576
+ catch {
577
+ return '';
578
+ }
579
+ }
567
580
  function normalizeErrorLike(err, maxTextLength) {
568
581
  if (err && typeof err === 'object') {
569
582
  const anyErr = err;
@@ -723,6 +736,7 @@
723
736
  return;
724
737
  const e = normalizeErrorLike(msg, options.maxTextLength);
725
738
  const payload = {
739
+ pagePath: getMpPagePath(),
726
740
  source: 'wx.onError',
727
741
  message: e.message,
728
742
  errorName: e.name,
@@ -749,6 +763,7 @@
749
763
  return;
750
764
  const e = normalizeErrorLike(res?.reason, options.maxTextLength);
751
765
  const payload = {
766
+ pagePath: getMpPagePath(),
752
767
  source: 'wx.onUnhandledRejection',
753
768
  message: e.message,
754
769
  errorName: e.name,
@@ -780,6 +795,7 @@
780
795
  if (sampleHit$1(options.sampleRate)) {
781
796
  const e = normalizeErrorLike(args?.[0], options.maxTextLength);
782
797
  const payload = {
798
+ pagePath: getMpPagePath(),
783
799
  source: 'App.onError',
784
800
  message: e.message,
785
801
  errorName: e.name,
@@ -803,6 +819,7 @@
803
819
  const reason = args?.[0]?.reason ?? args?.[0];
804
820
  const e = normalizeErrorLike(reason, options.maxTextLength);
805
821
  const payload = {
822
+ pagePath: getMpPagePath(),
806
823
  source: 'App.onUnhandledRejection',
807
824
  message: e.message,
808
825
  errorName: e.name,
@@ -1110,18 +1127,28 @@
1110
1127
  continue;
1111
1128
  // Page Render: firstRender
1112
1129
  if (entry.entryType === 'render' && entry.name === 'firstRender') {
1130
+ const duration = typeof entry.duration === 'number'
1131
+ ? entry.duration
1132
+ : typeof entry.startTime === 'number' && typeof entry.endTime === 'number'
1133
+ ? entry.endTime - entry.startTime
1134
+ : 0;
1113
1135
  report(options.reportType, {
1114
1136
  metric: 'page-render',
1115
- duration: entry.duration,
1137
+ duration,
1116
1138
  pagePath: entry.path || '',
1117
1139
  unit: 'ms',
1118
1140
  });
1119
1141
  }
1120
1142
  // Route Switch: route
1121
1143
  else if (entry.entryType === 'navigation' && entry.name === 'route') {
1144
+ const duration = typeof entry.duration === 'number'
1145
+ ? entry.duration
1146
+ : typeof entry.startTime === 'number' && typeof entry.endTime === 'number'
1147
+ ? entry.endTime - entry.startTime
1148
+ : 0;
1122
1149
  report(options.reportType, {
1123
1150
  metric: 'route',
1124
- duration: entry.duration,
1151
+ duration,
1125
1152
  pagePath: entry.path || '',
1126
1153
  unit: 'ms',
1127
1154
  });
@@ -1465,7 +1492,7 @@
1465
1492
  const tag = (el.tagName || '').toLowerCase();
1466
1493
  const trackId = getAttr(el, clickTrackIdAttr);
1467
1494
  // 过滤无效点击:白名单 tag + 没有 trackId
1468
- if (clickWhiteList.includes(tag) && !trackId)
1495
+ if (clickWhiteList.includes(tag) || !trackId)
1469
1496
  return;
1470
1497
  void uvStatePromise.then(({ uvId, meta }) => {
1471
1498
  if (destroyed)
@@ -1506,8 +1533,12 @@
1506
1533
  g.Page = function patchedPage(conf) {
1507
1534
  const originalOnShow = conf?.onShow;
1508
1535
  conf.onShow = function (...args) {
1509
- if (pvEnabled)
1510
- reportPv(getPagePath());
1536
+ if (pvEnabled) {
1537
+ const pagePath = getPagePath();
1538
+ if (pagePath?.length > 0) {
1539
+ reportPv(pagePath);
1540
+ }
1541
+ }
1511
1542
  return typeof originalOnShow === 'function' ? originalOnShow.apply(this, args) : undefined;
1512
1543
  };
1513
1544
  // 点击:wrap 页面 methods(bindtap 等会调用到这里的 handler)
@@ -1891,9 +1922,14 @@
1891
1922
  * 子类可按需重写(默认检测 wx)
1892
1923
  */
1893
1924
  detectEnvType() {
1894
- const wxAny = globalThis.wx;
1895
- if (wxAny && typeof wxAny.getSystemInfoSync === 'function')
1925
+ const g = globalThis;
1926
+ // 微信、支付宝、字节跳动、UniApp 等小程序环境通常都有特定全局变量
1927
+ if ((g.wx && typeof g.wx.getSystemInfoSync === 'function') ||
1928
+ (g.my && typeof g.my.getSystemInfoSync === 'function') ||
1929
+ (g.tt && typeof g.tt.getSystemInfoSync === 'function') ||
1930
+ (g.uni && typeof g.uni.getSystemInfoSync === 'function')) {
1896
1931
  return 'miniprogram';
1932
+ }
1897
1933
  return 'browser';
1898
1934
  }
1899
1935
  init(options) {
@@ -2266,15 +2302,57 @@
2266
2302
  return nowTs + this.batchIntervalMs;
2267
2303
  }
2268
2304
  info(message, data = {}) {
2269
- const payload = normalizeFlatFields({ message, ...data }, 'info');
2305
+ let msg = '';
2306
+ let extra = {};
2307
+ if (message instanceof Error) {
2308
+ msg = message.message;
2309
+ extra = {
2310
+ stack: message.stack,
2311
+ name: message.name,
2312
+ ...data,
2313
+ };
2314
+ }
2315
+ else {
2316
+ msg = String(message);
2317
+ extra = data;
2318
+ }
2319
+ const payload = normalizeFlatFields({ message: msg, ...extra }, 'info');
2270
2320
  this.report({ type: 'info', data: payload, timestamp: Date.now() });
2271
2321
  }
2272
2322
  warn(message, data = {}) {
2273
- const payload = normalizeFlatFields({ message, ...data }, 'warn');
2323
+ let msg = '';
2324
+ let extra = {};
2325
+ if (message instanceof Error) {
2326
+ msg = message.message;
2327
+ extra = {
2328
+ stack: message.stack,
2329
+ name: message.name,
2330
+ ...data,
2331
+ };
2332
+ }
2333
+ else {
2334
+ msg = String(message);
2335
+ extra = data;
2336
+ }
2337
+ const payload = normalizeFlatFields({ message: msg, ...extra }, 'warn');
2274
2338
  this.report({ type: 'warn', data: payload, timestamp: Date.now() });
2275
2339
  }
2276
2340
  error(message, data = {}) {
2277
- const payload = normalizeFlatFields({ message, ...data }, 'error');
2341
+ let msg = '';
2342
+ let extra = {};
2343
+ if (message instanceof Error) {
2344
+ msg = message.message;
2345
+ extra = {
2346
+ stack: message.stack,
2347
+ name: message.name,
2348
+ ...data,
2349
+ };
2350
+ }
2351
+ else {
2352
+ msg = String(message);
2353
+ extra = data;
2354
+ }
2355
+ const payload = normalizeFlatFields({ message: msg, ...extra }, 'error');
2278
2356
  this.report({ type: 'error', data: payload, timestamp: Date.now() });
2279
2357
  }
2280
2358
  track(trackType, data = {}) {
@@ -2496,38 +2574,78 @@
2496
2574
  }
2497
2575
  }
2498
2576
  const isMini = this.envType === 'miniprogram';
2499
- // 静态字面量,方便打包器识别(但在此兼容入口里,仍然可能被一起分析)
2500
- const WEB_SDK = 'tencentcloud-cls-sdk-js-web';
2501
- const MINI_SDK = 'tencentcloud-cls-sdk-js-mini';
2502
- // UMD(浏览器脚本)优先读全局变量
2503
- if (!isMini) {
2577
+ // 3) 尝试 require / 全局变量
2578
+ // Mini Program: 尝试直接 require
2579
+ if (isMini) {
2580
+ // 显式使用字面量 require,帮助打包工具识别依赖(尤其是 CJS 构建模式下)
2581
+ try {
2582
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
2583
+ const req = typeof require === 'function' ? require('tencentcloud-cls-sdk-js-mini') : null;
2584
+ const reqSdk = normalizeSdk(req);
2585
+ if (reqSdk) {
2586
+ this.sdk = reqSdk;
2587
+ return reqSdk;
2588
+ }
2589
+ }
2590
+ catch {
2591
+ // ignore
2592
+ }
2593
+ // 尝试使用 tryRequire(作为补充)
2594
+ const reqMod = tryRequire('tencentcloud-cls-sdk-js-mini');
2595
+ const reqSdk = normalizeSdk(reqMod);
2596
+ if (reqSdk) {
2597
+ this.sdk = reqSdk;
2598
+ return reqSdk;
2599
+ }
2600
+ }
2601
+ else {
2602
+ // Web: 优先读全局变量 (UMD)
2504
2603
  const g = readGlobal('tencentcloudClsSdkJsWeb');
2505
2604
  const sdk = normalizeSdk(g);
2506
2605
  if (sdk) {
2507
2606
  this.sdk = sdk;
2508
2607
  return sdk;
2509
2608
  }
2609
+ // Web: 尝试 require
2610
+ const reqMod = tryRequire('tencentcloud-cls-sdk-js-web');
2611
+ const reqSdk = normalizeSdk(reqMod);
2612
+ if (reqSdk) {
2613
+ this.sdk = reqSdk;
2614
+ return reqSdk;
2615
+ }
2616
+ }
2617
+ // 4) 动态 import
2618
+ // 使用字符串字面量,确保 Bundler 能正确识别并进行 Code Splitting
2619
+ if (isMini) {
2620
+ this.sdkPromise = import('tencentcloud-cls-sdk-js-mini')
2621
+ .then((m) => {
2622
+ const sdk = normalizeSdk(m);
2623
+ if (!sdk)
2624
+ throw new Error(`ClsLogger.loadSdk: invalid sdk module for mini`);
2625
+ this.sdk = sdk;
2626
+ return sdk;
2627
+ })
2628
+ .catch((err) => {
2629
+ this.sdkPromise = null;
2630
+ console.error('[ClsLogger] Failed to load mini sdk:', err);
2631
+ throw err;
2632
+ });
2633
+ }
2634
+ else {
2635
+ this.sdkPromise = import('tencentcloud-cls-sdk-js-web')
2636
+ .then((m) => {
2637
+ const sdk = normalizeSdk(m);
2638
+ if (!sdk)
2639
+ throw new Error(`ClsLogger.loadSdk: invalid sdk module for web`);
2640
+ this.sdk = sdk;
2641
+ return sdk;
2642
+ })
2643
+ .catch((err) => {
2644
+ this.sdkPromise = null;
2645
+ console.error('[ClsLogger] Failed to load web sdk:', err);
2646
+ throw err;
2647
+ });
2510
2648
  }
2511
- // 尽量同步 require
2512
- const reqMod = tryRequire(isMini ? MINI_SDK : WEB_SDK);
2513
- const reqSdk = normalizeSdk(reqMod);
2514
- if (reqSdk) {
2515
- this.sdk = reqSdk;
2516
- return reqSdk;
2517
- }
2518
- // 动态 import
2519
- this.sdkPromise = (isMini ? import(MINI_SDK) : import(WEB_SDK))
2520
- .then((m) => {
2521
- const sdk = normalizeSdk(m);
2522
- if (!sdk)
2523
- throw new Error(`ClsLogger.loadSdk: invalid sdk module for ${isMini ? MINI_SDK : WEB_SDK}`);
2524
- this.sdk = sdk;
2525
- return sdk;
2526
- })
2527
- .catch((err) => {
2528
- this.sdkPromise = null;
2529
- throw err;
2530
- });
2531
2649
  return this.sdkPromise;
2532
2650
  }
2533
2651
  }