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

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.esm.js CHANGED
@@ -1084,140 +1084,58 @@ function installBrowserPerformanceMonitor(report, options) {
1084
1084
  }
1085
1085
  }
1086
1086
  }
1087
- function wrapMiniProgramRouteApi(report, reportType, apiName, options) {
1088
- const wxAny = globalThis.wx;
1089
- if (!wxAny || typeof wxAny[apiName] !== 'function')
1090
- return;
1091
- const flagKey = `__beLinkClsLoggerMpRouteWrapped__${apiName}`;
1092
- if (wxAny[flagKey])
1093
- return;
1094
- wxAny[flagKey] = true;
1095
- const raw = wxAny[apiName].bind(wxAny);
1096
- wxAny[apiName] = (opts) => {
1097
- const start = Date.now();
1098
- const url = opts?.url ? String(opts.url) : '';
1099
- const wrapCb = (cb, success) => {
1100
- return (...args) => {
1101
- try {
1102
- if (sampleHit(options.sampleRate)) {
1103
- report(reportType, {
1104
- metric: 'route',
1105
- api: apiName,
1106
- url,
1107
- duration: Date.now() - start,
1108
- success: success ? 1 : 0,
1109
- error: success ? '' : truncate$1(stringifyLogValue(args?.[0]), options.maxTextLength),
1110
- unit: 'ms',
1111
- });
1112
- }
1113
- }
1114
- catch {
1115
- // ignore
1116
- }
1117
- if (typeof cb === 'function')
1118
- return cb(...args);
1119
- return undefined;
1120
- };
1121
- };
1122
- const next = { ...(opts ?? {}) };
1123
- next.success = wrapCb(next.success, true);
1124
- next.fail = wrapCb(next.fail, false);
1125
- return raw(next);
1126
- };
1127
- }
1128
- function installMiniProgramPageRenderMonitor(report, reportType, options) {
1129
- const g = globalThis;
1130
- if (typeof g.Page !== 'function')
1131
- return;
1132
- if (g.__beLinkClsLoggerPageWrapped__)
1133
- return;
1134
- g.__beLinkClsLoggerPageWrapped__ = true;
1135
- const rawPage = g.Page;
1136
- g.Page = (pageOptions) => {
1137
- const next = { ...(pageOptions ?? {}) };
1138
- const rawOnLoad = next.onLoad;
1139
- const rawOnReady = next.onReady;
1140
- next.onLoad = function (...args) {
1141
- try {
1142
- this.__beLinkClsLoggerPageLoadTs__ = Date.now();
1143
- }
1144
- catch {
1145
- // ignore
1146
- }
1147
- if (typeof rawOnLoad === 'function')
1148
- return rawOnLoad.apply(this, args);
1149
- return undefined;
1150
- };
1151
- next.onReady = function (...args) {
1152
- try {
1153
- const start = this.__beLinkClsLoggerPageLoadTs__;
1154
- if (typeof start === 'number' && sampleHit(options.sampleRate)) {
1155
- report(reportType, {
1156
- metric: 'page-render',
1157
- route: this?.route ? String(this.route) : '',
1158
- duration: Date.now() - start,
1159
- unit: 'ms',
1160
- });
1161
- }
1162
- }
1163
- catch {
1164
- // ignore
1165
- }
1166
- if (typeof rawOnReady === 'function')
1167
- return rawOnReady.apply(this, args);
1168
- return undefined;
1169
- };
1170
- return rawPage(next);
1171
- };
1172
- }
1173
1087
  function installMiniProgramPerformanceMonitor(report, options) {
1174
1088
  const g = globalThis;
1089
+ const ctx = g.wx || g.Taro;
1090
+ if (!ctx || typeof ctx.getPerformance !== 'function')
1091
+ return;
1175
1092
  if (g.__beLinkClsLoggerMpPerfInstalled__)
1176
1093
  return;
1177
1094
  g.__beLinkClsLoggerMpPerfInstalled__ = true;
1178
- // 路由切换耗时(用 API 回调近似)
1179
- for (const apiName of ['navigateTo', 'redirectTo', 'switchTab', 'reLaunch']) {
1180
- try {
1181
- wrapMiniProgramRouteApi(report, options.reportType, apiName, options);
1182
- }
1183
- catch {
1184
- // ignore
1185
- }
1186
- }
1187
- // 页面渲染耗时(onLoad -> onReady)
1188
- try {
1189
- installMiniProgramPageRenderMonitor(report, options.reportType, options);
1190
- }
1191
- catch {
1192
- // ignore
1193
- }
1194
- // wx.getPerformance()(若可用,尝试读取已有 entries)
1195
1095
  try {
1196
- const wxAny = globalThis.wx;
1197
- if (wxAny && typeof wxAny.getPerformance === 'function') {
1198
- const perf = wxAny.getPerformance();
1199
- if (perf && isPlainObject(perf)) {
1200
- // 不同基础库实现差异较大:尽量容错
1201
- setTimeout(() => {
1202
- try {
1203
- if (!sampleHit(options.sampleRate))
1204
- return;
1205
- const entries = typeof perf.getEntries === 'function'
1206
- ? perf.getEntries()
1207
- : typeof perf.getEntriesByType === 'function'
1208
- ? perf.getEntriesByType('navigation')
1209
- : [];
1096
+ const perf = ctx.getPerformance();
1097
+ if (!perf || typeof perf.createObserver !== 'function')
1098
+ return;
1099
+ const observer = perf.createObserver((entryList) => {
1100
+ try {
1101
+ const entries = entryList.getEntries();
1102
+ for (const entry of entries) {
1103
+ if (!sampleHit(options.sampleRate))
1104
+ continue;
1105
+ // Page Render: firstRender
1106
+ if (entry.entryType === 'render' && entry.name === 'firstRender') {
1210
1107
  report(options.reportType, {
1211
- metric: 'mp-performance',
1212
- entries: truncate$1(stringifyLogValue(entries), options.maxTextLength),
1108
+ metric: 'page-render',
1109
+ duration: entry.duration,
1110
+ pagePath: entry.path || '',
1111
+ unit: 'ms',
1213
1112
  });
1214
1113
  }
1215
- catch {
1216
- // ignore
1114
+ // Route Switch: route
1115
+ else if (entry.entryType === 'navigation' && entry.name === 'route') {
1116
+ report(options.reportType, {
1117
+ metric: 'route',
1118
+ duration: entry.duration,
1119
+ pagePath: entry.path || '',
1120
+ unit: 'ms',
1121
+ });
1217
1122
  }
1218
- }, 0);
1123
+ // App Launch: appLaunch (Cold)
1124
+ else if (entry.entryType === 'navigation' && entry.name === 'appLaunch') {
1125
+ report(options.reportType, {
1126
+ metric: 'app-launch',
1127
+ duration: entry.duration,
1128
+ launchType: 'cold',
1129
+ unit: 'ms',
1130
+ });
1131
+ }
1132
+ }
1219
1133
  }
1220
- }
1134
+ catch {
1135
+ // ignore
1136
+ }
1137
+ });
1138
+ observer.observe({ entryTypes: ['navigation', 'render'] });
1221
1139
  }
1222
1140
  catch {
1223
1141
  // ignore
package/dist/index.js CHANGED
@@ -1088,140 +1088,58 @@ function installBrowserPerformanceMonitor(report, options) {
1088
1088
  }
1089
1089
  }
1090
1090
  }
1091
- function wrapMiniProgramRouteApi(report, reportType, apiName, options) {
1092
- const wxAny = globalThis.wx;
1093
- if (!wxAny || typeof wxAny[apiName] !== 'function')
1094
- return;
1095
- const flagKey = `__beLinkClsLoggerMpRouteWrapped__${apiName}`;
1096
- if (wxAny[flagKey])
1097
- return;
1098
- wxAny[flagKey] = true;
1099
- const raw = wxAny[apiName].bind(wxAny);
1100
- wxAny[apiName] = (opts) => {
1101
- const start = Date.now();
1102
- const url = opts?.url ? String(opts.url) : '';
1103
- const wrapCb = (cb, success) => {
1104
- return (...args) => {
1105
- try {
1106
- if (sampleHit(options.sampleRate)) {
1107
- report(reportType, {
1108
- metric: 'route',
1109
- api: apiName,
1110
- url,
1111
- duration: Date.now() - start,
1112
- success: success ? 1 : 0,
1113
- error: success ? '' : truncate$1(stringifyLogValue(args?.[0]), options.maxTextLength),
1114
- unit: 'ms',
1115
- });
1116
- }
1117
- }
1118
- catch {
1119
- // ignore
1120
- }
1121
- if (typeof cb === 'function')
1122
- return cb(...args);
1123
- return undefined;
1124
- };
1125
- };
1126
- const next = { ...(opts ?? {}) };
1127
- next.success = wrapCb(next.success, true);
1128
- next.fail = wrapCb(next.fail, false);
1129
- return raw(next);
1130
- };
1131
- }
1132
- function installMiniProgramPageRenderMonitor(report, reportType, options) {
1133
- const g = globalThis;
1134
- if (typeof g.Page !== 'function')
1135
- return;
1136
- if (g.__beLinkClsLoggerPageWrapped__)
1137
- return;
1138
- g.__beLinkClsLoggerPageWrapped__ = true;
1139
- const rawPage = g.Page;
1140
- g.Page = (pageOptions) => {
1141
- const next = { ...(pageOptions ?? {}) };
1142
- const rawOnLoad = next.onLoad;
1143
- const rawOnReady = next.onReady;
1144
- next.onLoad = function (...args) {
1145
- try {
1146
- this.__beLinkClsLoggerPageLoadTs__ = Date.now();
1147
- }
1148
- catch {
1149
- // ignore
1150
- }
1151
- if (typeof rawOnLoad === 'function')
1152
- return rawOnLoad.apply(this, args);
1153
- return undefined;
1154
- };
1155
- next.onReady = function (...args) {
1156
- try {
1157
- const start = this.__beLinkClsLoggerPageLoadTs__;
1158
- if (typeof start === 'number' && sampleHit(options.sampleRate)) {
1159
- report(reportType, {
1160
- metric: 'page-render',
1161
- route: this?.route ? String(this.route) : '',
1162
- duration: Date.now() - start,
1163
- unit: 'ms',
1164
- });
1165
- }
1166
- }
1167
- catch {
1168
- // ignore
1169
- }
1170
- if (typeof rawOnReady === 'function')
1171
- return rawOnReady.apply(this, args);
1172
- return undefined;
1173
- };
1174
- return rawPage(next);
1175
- };
1176
- }
1177
1091
  function installMiniProgramPerformanceMonitor(report, options) {
1178
1092
  const g = globalThis;
1093
+ const ctx = g.wx || g.Taro;
1094
+ if (!ctx || typeof ctx.getPerformance !== 'function')
1095
+ return;
1179
1096
  if (g.__beLinkClsLoggerMpPerfInstalled__)
1180
1097
  return;
1181
1098
  g.__beLinkClsLoggerMpPerfInstalled__ = true;
1182
- // 路由切换耗时(用 API 回调近似)
1183
- for (const apiName of ['navigateTo', 'redirectTo', 'switchTab', 'reLaunch']) {
1184
- try {
1185
- wrapMiniProgramRouteApi(report, options.reportType, apiName, options);
1186
- }
1187
- catch {
1188
- // ignore
1189
- }
1190
- }
1191
- // 页面渲染耗时(onLoad -> onReady)
1192
- try {
1193
- installMiniProgramPageRenderMonitor(report, options.reportType, options);
1194
- }
1195
- catch {
1196
- // ignore
1197
- }
1198
- // wx.getPerformance()(若可用,尝试读取已有 entries)
1199
1099
  try {
1200
- const wxAny = globalThis.wx;
1201
- if (wxAny && typeof wxAny.getPerformance === 'function') {
1202
- const perf = wxAny.getPerformance();
1203
- if (perf && isPlainObject(perf)) {
1204
- // 不同基础库实现差异较大:尽量容错
1205
- setTimeout(() => {
1206
- try {
1207
- if (!sampleHit(options.sampleRate))
1208
- return;
1209
- const entries = typeof perf.getEntries === 'function'
1210
- ? perf.getEntries()
1211
- : typeof perf.getEntriesByType === 'function'
1212
- ? perf.getEntriesByType('navigation')
1213
- : [];
1100
+ const perf = ctx.getPerformance();
1101
+ if (!perf || typeof perf.createObserver !== 'function')
1102
+ return;
1103
+ const observer = perf.createObserver((entryList) => {
1104
+ try {
1105
+ const entries = entryList.getEntries();
1106
+ for (const entry of entries) {
1107
+ if (!sampleHit(options.sampleRate))
1108
+ continue;
1109
+ // Page Render: firstRender
1110
+ if (entry.entryType === 'render' && entry.name === 'firstRender') {
1214
1111
  report(options.reportType, {
1215
- metric: 'mp-performance',
1216
- entries: truncate$1(stringifyLogValue(entries), options.maxTextLength),
1112
+ metric: 'page-render',
1113
+ duration: entry.duration,
1114
+ pagePath: entry.path || '',
1115
+ unit: 'ms',
1217
1116
  });
1218
1117
  }
1219
- catch {
1220
- // ignore
1118
+ // Route Switch: route
1119
+ else if (entry.entryType === 'navigation' && entry.name === 'route') {
1120
+ report(options.reportType, {
1121
+ metric: 'route',
1122
+ duration: entry.duration,
1123
+ pagePath: entry.path || '',
1124
+ unit: 'ms',
1125
+ });
1221
1126
  }
1222
- }, 0);
1127
+ // App Launch: appLaunch (Cold)
1128
+ else if (entry.entryType === 'navigation' && entry.name === 'appLaunch') {
1129
+ report(options.reportType, {
1130
+ metric: 'app-launch',
1131
+ duration: entry.duration,
1132
+ launchType: 'cold',
1133
+ unit: 'ms',
1134
+ });
1135
+ }
1136
+ }
1223
1137
  }
1224
- }
1138
+ catch {
1139
+ // ignore
1140
+ }
1141
+ });
1142
+ observer.observe({ entryTypes: ['navigation', 'render'] });
1225
1143
  }
1226
1144
  catch {
1227
1145
  // ignore
package/dist/index.umd.js CHANGED
@@ -1090,140 +1090,58 @@
1090
1090
  }
1091
1091
  }
1092
1092
  }
1093
- function wrapMiniProgramRouteApi(report, reportType, apiName, options) {
1094
- const wxAny = globalThis.wx;
1095
- if (!wxAny || typeof wxAny[apiName] !== 'function')
1096
- return;
1097
- const flagKey = `__beLinkClsLoggerMpRouteWrapped__${apiName}`;
1098
- if (wxAny[flagKey])
1099
- return;
1100
- wxAny[flagKey] = true;
1101
- const raw = wxAny[apiName].bind(wxAny);
1102
- wxAny[apiName] = (opts) => {
1103
- const start = Date.now();
1104
- const url = opts?.url ? String(opts.url) : '';
1105
- const wrapCb = (cb, success) => {
1106
- return (...args) => {
1107
- try {
1108
- if (sampleHit(options.sampleRate)) {
1109
- report(reportType, {
1110
- metric: 'route',
1111
- api: apiName,
1112
- url,
1113
- duration: Date.now() - start,
1114
- success: success ? 1 : 0,
1115
- error: success ? '' : truncate$1(stringifyLogValue(args?.[0]), options.maxTextLength),
1116
- unit: 'ms',
1117
- });
1118
- }
1119
- }
1120
- catch {
1121
- // ignore
1122
- }
1123
- if (typeof cb === 'function')
1124
- return cb(...args);
1125
- return undefined;
1126
- };
1127
- };
1128
- const next = { ...(opts ?? {}) };
1129
- next.success = wrapCb(next.success, true);
1130
- next.fail = wrapCb(next.fail, false);
1131
- return raw(next);
1132
- };
1133
- }
1134
- function installMiniProgramPageRenderMonitor(report, reportType, options) {
1135
- const g = globalThis;
1136
- if (typeof g.Page !== 'function')
1137
- return;
1138
- if (g.__beLinkClsLoggerPageWrapped__)
1139
- return;
1140
- g.__beLinkClsLoggerPageWrapped__ = true;
1141
- const rawPage = g.Page;
1142
- g.Page = (pageOptions) => {
1143
- const next = { ...(pageOptions ?? {}) };
1144
- const rawOnLoad = next.onLoad;
1145
- const rawOnReady = next.onReady;
1146
- next.onLoad = function (...args) {
1147
- try {
1148
- this.__beLinkClsLoggerPageLoadTs__ = Date.now();
1149
- }
1150
- catch {
1151
- // ignore
1152
- }
1153
- if (typeof rawOnLoad === 'function')
1154
- return rawOnLoad.apply(this, args);
1155
- return undefined;
1156
- };
1157
- next.onReady = function (...args) {
1158
- try {
1159
- const start = this.__beLinkClsLoggerPageLoadTs__;
1160
- if (typeof start === 'number' && sampleHit(options.sampleRate)) {
1161
- report(reportType, {
1162
- metric: 'page-render',
1163
- route: this?.route ? String(this.route) : '',
1164
- duration: Date.now() - start,
1165
- unit: 'ms',
1166
- });
1167
- }
1168
- }
1169
- catch {
1170
- // ignore
1171
- }
1172
- if (typeof rawOnReady === 'function')
1173
- return rawOnReady.apply(this, args);
1174
- return undefined;
1175
- };
1176
- return rawPage(next);
1177
- };
1178
- }
1179
1093
  function installMiniProgramPerformanceMonitor(report, options) {
1180
1094
  const g = globalThis;
1095
+ const ctx = g.wx || g.Taro;
1096
+ if (!ctx || typeof ctx.getPerformance !== 'function')
1097
+ return;
1181
1098
  if (g.__beLinkClsLoggerMpPerfInstalled__)
1182
1099
  return;
1183
1100
  g.__beLinkClsLoggerMpPerfInstalled__ = true;
1184
- // 路由切换耗时(用 API 回调近似)
1185
- for (const apiName of ['navigateTo', 'redirectTo', 'switchTab', 'reLaunch']) {
1186
- try {
1187
- wrapMiniProgramRouteApi(report, options.reportType, apiName, options);
1188
- }
1189
- catch {
1190
- // ignore
1191
- }
1192
- }
1193
- // 页面渲染耗时(onLoad -> onReady)
1194
- try {
1195
- installMiniProgramPageRenderMonitor(report, options.reportType, options);
1196
- }
1197
- catch {
1198
- // ignore
1199
- }
1200
- // wx.getPerformance()(若可用,尝试读取已有 entries)
1201
1101
  try {
1202
- const wxAny = globalThis.wx;
1203
- if (wxAny && typeof wxAny.getPerformance === 'function') {
1204
- const perf = wxAny.getPerformance();
1205
- if (perf && isPlainObject(perf)) {
1206
- // 不同基础库实现差异较大:尽量容错
1207
- setTimeout(() => {
1208
- try {
1209
- if (!sampleHit(options.sampleRate))
1210
- return;
1211
- const entries = typeof perf.getEntries === 'function'
1212
- ? perf.getEntries()
1213
- : typeof perf.getEntriesByType === 'function'
1214
- ? perf.getEntriesByType('navigation')
1215
- : [];
1102
+ const perf = ctx.getPerformance();
1103
+ if (!perf || typeof perf.createObserver !== 'function')
1104
+ return;
1105
+ const observer = perf.createObserver((entryList) => {
1106
+ try {
1107
+ const entries = entryList.getEntries();
1108
+ for (const entry of entries) {
1109
+ if (!sampleHit(options.sampleRate))
1110
+ continue;
1111
+ // Page Render: firstRender
1112
+ if (entry.entryType === 'render' && entry.name === 'firstRender') {
1216
1113
  report(options.reportType, {
1217
- metric: 'mp-performance',
1218
- entries: truncate$1(stringifyLogValue(entries), options.maxTextLength),
1114
+ metric: 'page-render',
1115
+ duration: entry.duration,
1116
+ pagePath: entry.path || '',
1117
+ unit: 'ms',
1219
1118
  });
1220
1119
  }
1221
- catch {
1222
- // ignore
1120
+ // Route Switch: route
1121
+ else if (entry.entryType === 'navigation' && entry.name === 'route') {
1122
+ report(options.reportType, {
1123
+ metric: 'route',
1124
+ duration: entry.duration,
1125
+ pagePath: entry.path || '',
1126
+ unit: 'ms',
1127
+ });
1223
1128
  }
1224
- }, 0);
1129
+ // App Launch: appLaunch (Cold)
1130
+ else if (entry.entryType === 'navigation' && entry.name === 'appLaunch') {
1131
+ report(options.reportType, {
1132
+ metric: 'app-launch',
1133
+ duration: entry.duration,
1134
+ launchType: 'cold',
1135
+ unit: 'ms',
1136
+ });
1137
+ }
1138
+ }
1225
1139
  }
1226
- }
1140
+ catch {
1141
+ // ignore
1142
+ }
1143
+ });
1144
+ observer.observe({ entryTypes: ['navigation', 'render'] });
1227
1145
  }
1228
1146
  catch {
1229
1147
  // ignore
package/dist/mini.esm.js CHANGED
@@ -1086,140 +1086,58 @@ function installBrowserPerformanceMonitor(report, options) {
1086
1086
  }
1087
1087
  }
1088
1088
  }
1089
- function wrapMiniProgramRouteApi(report, reportType, apiName, options) {
1090
- const wxAny = globalThis.wx;
1091
- if (!wxAny || typeof wxAny[apiName] !== 'function')
1092
- return;
1093
- const flagKey = `__beLinkClsLoggerMpRouteWrapped__${apiName}`;
1094
- if (wxAny[flagKey])
1095
- return;
1096
- wxAny[flagKey] = true;
1097
- const raw = wxAny[apiName].bind(wxAny);
1098
- wxAny[apiName] = (opts) => {
1099
- const start = Date.now();
1100
- const url = opts?.url ? String(opts.url) : '';
1101
- const wrapCb = (cb, success) => {
1102
- return (...args) => {
1103
- try {
1104
- if (sampleHit(options.sampleRate)) {
1105
- report(reportType, {
1106
- metric: 'route',
1107
- api: apiName,
1108
- url,
1109
- duration: Date.now() - start,
1110
- success: success ? 1 : 0,
1111
- error: success ? '' : truncate$1(stringifyLogValue(args?.[0]), options.maxTextLength),
1112
- unit: 'ms',
1113
- });
1114
- }
1115
- }
1116
- catch {
1117
- // ignore
1118
- }
1119
- if (typeof cb === 'function')
1120
- return cb(...args);
1121
- return undefined;
1122
- };
1123
- };
1124
- const next = { ...(opts ?? {}) };
1125
- next.success = wrapCb(next.success, true);
1126
- next.fail = wrapCb(next.fail, false);
1127
- return raw(next);
1128
- };
1129
- }
1130
- function installMiniProgramPageRenderMonitor(report, reportType, options) {
1131
- const g = globalThis;
1132
- if (typeof g.Page !== 'function')
1133
- return;
1134
- if (g.__beLinkClsLoggerPageWrapped__)
1135
- return;
1136
- g.__beLinkClsLoggerPageWrapped__ = true;
1137
- const rawPage = g.Page;
1138
- g.Page = (pageOptions) => {
1139
- const next = { ...(pageOptions ?? {}) };
1140
- const rawOnLoad = next.onLoad;
1141
- const rawOnReady = next.onReady;
1142
- next.onLoad = function (...args) {
1143
- try {
1144
- this.__beLinkClsLoggerPageLoadTs__ = Date.now();
1145
- }
1146
- catch {
1147
- // ignore
1148
- }
1149
- if (typeof rawOnLoad === 'function')
1150
- return rawOnLoad.apply(this, args);
1151
- return undefined;
1152
- };
1153
- next.onReady = function (...args) {
1154
- try {
1155
- const start = this.__beLinkClsLoggerPageLoadTs__;
1156
- if (typeof start === 'number' && sampleHit(options.sampleRate)) {
1157
- report(reportType, {
1158
- metric: 'page-render',
1159
- route: this?.route ? String(this.route) : '',
1160
- duration: Date.now() - start,
1161
- unit: 'ms',
1162
- });
1163
- }
1164
- }
1165
- catch {
1166
- // ignore
1167
- }
1168
- if (typeof rawOnReady === 'function')
1169
- return rawOnReady.apply(this, args);
1170
- return undefined;
1171
- };
1172
- return rawPage(next);
1173
- };
1174
- }
1175
1089
  function installMiniProgramPerformanceMonitor(report, options) {
1176
1090
  const g = globalThis;
1091
+ const ctx = g.wx || g.Taro;
1092
+ if (!ctx || typeof ctx.getPerformance !== 'function')
1093
+ return;
1177
1094
  if (g.__beLinkClsLoggerMpPerfInstalled__)
1178
1095
  return;
1179
1096
  g.__beLinkClsLoggerMpPerfInstalled__ = true;
1180
- // 路由切换耗时(用 API 回调近似)
1181
- for (const apiName of ['navigateTo', 'redirectTo', 'switchTab', 'reLaunch']) {
1182
- try {
1183
- wrapMiniProgramRouteApi(report, options.reportType, apiName, options);
1184
- }
1185
- catch {
1186
- // ignore
1187
- }
1188
- }
1189
- // 页面渲染耗时(onLoad -> onReady)
1190
- try {
1191
- installMiniProgramPageRenderMonitor(report, options.reportType, options);
1192
- }
1193
- catch {
1194
- // ignore
1195
- }
1196
- // wx.getPerformance()(若可用,尝试读取已有 entries)
1197
1097
  try {
1198
- const wxAny = globalThis.wx;
1199
- if (wxAny && typeof wxAny.getPerformance === 'function') {
1200
- const perf = wxAny.getPerformance();
1201
- if (perf && isPlainObject(perf)) {
1202
- // 不同基础库实现差异较大:尽量容错
1203
- setTimeout(() => {
1204
- try {
1205
- if (!sampleHit(options.sampleRate))
1206
- return;
1207
- const entries = typeof perf.getEntries === 'function'
1208
- ? perf.getEntries()
1209
- : typeof perf.getEntriesByType === 'function'
1210
- ? perf.getEntriesByType('navigation')
1211
- : [];
1098
+ const perf = ctx.getPerformance();
1099
+ if (!perf || typeof perf.createObserver !== 'function')
1100
+ return;
1101
+ const observer = perf.createObserver((entryList) => {
1102
+ try {
1103
+ const entries = entryList.getEntries();
1104
+ for (const entry of entries) {
1105
+ if (!sampleHit(options.sampleRate))
1106
+ continue;
1107
+ // Page Render: firstRender
1108
+ if (entry.entryType === 'render' && entry.name === 'firstRender') {
1212
1109
  report(options.reportType, {
1213
- metric: 'mp-performance',
1214
- entries: truncate$1(stringifyLogValue(entries), options.maxTextLength),
1110
+ metric: 'page-render',
1111
+ duration: entry.duration,
1112
+ pagePath: entry.path || '',
1113
+ unit: 'ms',
1215
1114
  });
1216
1115
  }
1217
- catch {
1218
- // ignore
1116
+ // Route Switch: route
1117
+ else if (entry.entryType === 'navigation' && entry.name === 'route') {
1118
+ report(options.reportType, {
1119
+ metric: 'route',
1120
+ duration: entry.duration,
1121
+ pagePath: entry.path || '',
1122
+ unit: 'ms',
1123
+ });
1219
1124
  }
1220
- }, 0);
1125
+ // App Launch: appLaunch (Cold)
1126
+ else if (entry.entryType === 'navigation' && entry.name === 'appLaunch') {
1127
+ report(options.reportType, {
1128
+ metric: 'app-launch',
1129
+ duration: entry.duration,
1130
+ launchType: 'cold',
1131
+ unit: 'ms',
1132
+ });
1133
+ }
1134
+ }
1221
1135
  }
1222
- }
1136
+ catch {
1137
+ // ignore
1138
+ }
1139
+ });
1140
+ observer.observe({ entryTypes: ['navigation', 'render'] });
1223
1141
  }
1224
1142
  catch {
1225
1143
  // ignore
package/dist/mini.js CHANGED
@@ -1109,140 +1109,58 @@ function installBrowserPerformanceMonitor(report, options) {
1109
1109
  }
1110
1110
  }
1111
1111
  }
1112
- function wrapMiniProgramRouteApi(report, reportType, apiName, options) {
1113
- const wxAny = globalThis.wx;
1114
- if (!wxAny || typeof wxAny[apiName] !== 'function')
1115
- return;
1116
- const flagKey = `__beLinkClsLoggerMpRouteWrapped__${apiName}`;
1117
- if (wxAny[flagKey])
1118
- return;
1119
- wxAny[flagKey] = true;
1120
- const raw = wxAny[apiName].bind(wxAny);
1121
- wxAny[apiName] = (opts) => {
1122
- const start = Date.now();
1123
- const url = opts?.url ? String(opts.url) : '';
1124
- const wrapCb = (cb, success) => {
1125
- return (...args) => {
1126
- try {
1127
- if (sampleHit(options.sampleRate)) {
1128
- report(reportType, {
1129
- metric: 'route',
1130
- api: apiName,
1131
- url,
1132
- duration: Date.now() - start,
1133
- success: success ? 1 : 0,
1134
- error: success ? '' : truncate$1(stringifyLogValue(args?.[0]), options.maxTextLength),
1135
- unit: 'ms',
1136
- });
1137
- }
1138
- }
1139
- catch {
1140
- // ignore
1141
- }
1142
- if (typeof cb === 'function')
1143
- return cb(...args);
1144
- return undefined;
1145
- };
1146
- };
1147
- const next = { ...(opts ?? {}) };
1148
- next.success = wrapCb(next.success, true);
1149
- next.fail = wrapCb(next.fail, false);
1150
- return raw(next);
1151
- };
1152
- }
1153
- function installMiniProgramPageRenderMonitor(report, reportType, options) {
1154
- const g = globalThis;
1155
- if (typeof g.Page !== 'function')
1156
- return;
1157
- if (g.__beLinkClsLoggerPageWrapped__)
1158
- return;
1159
- g.__beLinkClsLoggerPageWrapped__ = true;
1160
- const rawPage = g.Page;
1161
- g.Page = (pageOptions) => {
1162
- const next = { ...(pageOptions ?? {}) };
1163
- const rawOnLoad = next.onLoad;
1164
- const rawOnReady = next.onReady;
1165
- next.onLoad = function (...args) {
1166
- try {
1167
- this.__beLinkClsLoggerPageLoadTs__ = Date.now();
1168
- }
1169
- catch {
1170
- // ignore
1171
- }
1172
- if (typeof rawOnLoad === 'function')
1173
- return rawOnLoad.apply(this, args);
1174
- return undefined;
1175
- };
1176
- next.onReady = function (...args) {
1177
- try {
1178
- const start = this.__beLinkClsLoggerPageLoadTs__;
1179
- if (typeof start === 'number' && sampleHit(options.sampleRate)) {
1180
- report(reportType, {
1181
- metric: 'page-render',
1182
- route: this?.route ? String(this.route) : '',
1183
- duration: Date.now() - start,
1184
- unit: 'ms',
1185
- });
1186
- }
1187
- }
1188
- catch {
1189
- // ignore
1190
- }
1191
- if (typeof rawOnReady === 'function')
1192
- return rawOnReady.apply(this, args);
1193
- return undefined;
1194
- };
1195
- return rawPage(next);
1196
- };
1197
- }
1198
1112
  function installMiniProgramPerformanceMonitor(report, options) {
1199
1113
  const g = globalThis;
1114
+ const ctx = g.wx || g.Taro;
1115
+ if (!ctx || typeof ctx.getPerformance !== 'function')
1116
+ return;
1200
1117
  if (g.__beLinkClsLoggerMpPerfInstalled__)
1201
1118
  return;
1202
1119
  g.__beLinkClsLoggerMpPerfInstalled__ = true;
1203
- // 路由切换耗时(用 API 回调近似)
1204
- for (const apiName of ['navigateTo', 'redirectTo', 'switchTab', 'reLaunch']) {
1205
- try {
1206
- wrapMiniProgramRouteApi(report, options.reportType, apiName, options);
1207
- }
1208
- catch {
1209
- // ignore
1210
- }
1211
- }
1212
- // 页面渲染耗时(onLoad -> onReady)
1213
- try {
1214
- installMiniProgramPageRenderMonitor(report, options.reportType, options);
1215
- }
1216
- catch {
1217
- // ignore
1218
- }
1219
- // wx.getPerformance()(若可用,尝试读取已有 entries)
1220
1120
  try {
1221
- const wxAny = globalThis.wx;
1222
- if (wxAny && typeof wxAny.getPerformance === 'function') {
1223
- const perf = wxAny.getPerformance();
1224
- if (perf && isPlainObject(perf)) {
1225
- // 不同基础库实现差异较大:尽量容错
1226
- setTimeout(() => {
1227
- try {
1228
- if (!sampleHit(options.sampleRate))
1229
- return;
1230
- const entries = typeof perf.getEntries === 'function'
1231
- ? perf.getEntries()
1232
- : typeof perf.getEntriesByType === 'function'
1233
- ? perf.getEntriesByType('navigation')
1234
- : [];
1121
+ const perf = ctx.getPerformance();
1122
+ if (!perf || typeof perf.createObserver !== 'function')
1123
+ return;
1124
+ const observer = perf.createObserver((entryList) => {
1125
+ try {
1126
+ const entries = entryList.getEntries();
1127
+ for (const entry of entries) {
1128
+ if (!sampleHit(options.sampleRate))
1129
+ continue;
1130
+ // Page Render: firstRender
1131
+ if (entry.entryType === 'render' && entry.name === 'firstRender') {
1235
1132
  report(options.reportType, {
1236
- metric: 'mp-performance',
1237
- entries: truncate$1(stringifyLogValue(entries), options.maxTextLength),
1133
+ metric: 'page-render',
1134
+ duration: entry.duration,
1135
+ pagePath: entry.path || '',
1136
+ unit: 'ms',
1238
1137
  });
1239
1138
  }
1240
- catch {
1241
- // ignore
1139
+ // Route Switch: route
1140
+ else if (entry.entryType === 'navigation' && entry.name === 'route') {
1141
+ report(options.reportType, {
1142
+ metric: 'route',
1143
+ duration: entry.duration,
1144
+ pagePath: entry.path || '',
1145
+ unit: 'ms',
1146
+ });
1242
1147
  }
1243
- }, 0);
1148
+ // App Launch: appLaunch (Cold)
1149
+ else if (entry.entryType === 'navigation' && entry.name === 'appLaunch') {
1150
+ report(options.reportType, {
1151
+ metric: 'app-launch',
1152
+ duration: entry.duration,
1153
+ launchType: 'cold',
1154
+ unit: 'ms',
1155
+ });
1156
+ }
1157
+ }
1244
1158
  }
1245
- }
1159
+ catch {
1160
+ // ignore
1161
+ }
1162
+ });
1163
+ observer.observe({ entryTypes: ['navigation', 'render'] });
1246
1164
  }
1247
1165
  catch {
1248
1166
  // ignore
@@ -1 +1 @@
1
- {"version":3,"file":"performanceMonitor.d.ts","sourceRoot":"","sources":["../src/performanceMonitor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAC;AAGrE,KAAK,QAAQ,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,KAAK,IAAI,CAAC;AAiYzD,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,QAAQ,EAChB,IAAI,GAAE,OAAO,GAAG,yBAAyB,GAAG,SAAc,GACzD,IAAI,CAsBN"}
1
+ {"version":3,"file":"performanceMonitor.d.ts","sourceRoot":"","sources":["../src/performanceMonitor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAC;AAGrE,KAAK,QAAQ,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,KAAK,IAAI,CAAC;AAuSzD,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,QAAQ,EAChB,IAAI,GAAE,OAAO,GAAG,yBAAyB,GAAG,SAAc,GACzD,IAAI,CAsBN"}
package/dist/web.esm.js CHANGED
@@ -1086,140 +1086,58 @@ function installBrowserPerformanceMonitor(report, options) {
1086
1086
  }
1087
1087
  }
1088
1088
  }
1089
- function wrapMiniProgramRouteApi(report, reportType, apiName, options) {
1090
- const wxAny = globalThis.wx;
1091
- if (!wxAny || typeof wxAny[apiName] !== 'function')
1092
- return;
1093
- const flagKey = `__beLinkClsLoggerMpRouteWrapped__${apiName}`;
1094
- if (wxAny[flagKey])
1095
- return;
1096
- wxAny[flagKey] = true;
1097
- const raw = wxAny[apiName].bind(wxAny);
1098
- wxAny[apiName] = (opts) => {
1099
- const start = Date.now();
1100
- const url = opts?.url ? String(opts.url) : '';
1101
- const wrapCb = (cb, success) => {
1102
- return (...args) => {
1103
- try {
1104
- if (sampleHit(options.sampleRate)) {
1105
- report(reportType, {
1106
- metric: 'route',
1107
- api: apiName,
1108
- url,
1109
- duration: Date.now() - start,
1110
- success: success ? 1 : 0,
1111
- error: success ? '' : truncate$1(stringifyLogValue(args?.[0]), options.maxTextLength),
1112
- unit: 'ms',
1113
- });
1114
- }
1115
- }
1116
- catch {
1117
- // ignore
1118
- }
1119
- if (typeof cb === 'function')
1120
- return cb(...args);
1121
- return undefined;
1122
- };
1123
- };
1124
- const next = { ...(opts ?? {}) };
1125
- next.success = wrapCb(next.success, true);
1126
- next.fail = wrapCb(next.fail, false);
1127
- return raw(next);
1128
- };
1129
- }
1130
- function installMiniProgramPageRenderMonitor(report, reportType, options) {
1131
- const g = globalThis;
1132
- if (typeof g.Page !== 'function')
1133
- return;
1134
- if (g.__beLinkClsLoggerPageWrapped__)
1135
- return;
1136
- g.__beLinkClsLoggerPageWrapped__ = true;
1137
- const rawPage = g.Page;
1138
- g.Page = (pageOptions) => {
1139
- const next = { ...(pageOptions ?? {}) };
1140
- const rawOnLoad = next.onLoad;
1141
- const rawOnReady = next.onReady;
1142
- next.onLoad = function (...args) {
1143
- try {
1144
- this.__beLinkClsLoggerPageLoadTs__ = Date.now();
1145
- }
1146
- catch {
1147
- // ignore
1148
- }
1149
- if (typeof rawOnLoad === 'function')
1150
- return rawOnLoad.apply(this, args);
1151
- return undefined;
1152
- };
1153
- next.onReady = function (...args) {
1154
- try {
1155
- const start = this.__beLinkClsLoggerPageLoadTs__;
1156
- if (typeof start === 'number' && sampleHit(options.sampleRate)) {
1157
- report(reportType, {
1158
- metric: 'page-render',
1159
- route: this?.route ? String(this.route) : '',
1160
- duration: Date.now() - start,
1161
- unit: 'ms',
1162
- });
1163
- }
1164
- }
1165
- catch {
1166
- // ignore
1167
- }
1168
- if (typeof rawOnReady === 'function')
1169
- return rawOnReady.apply(this, args);
1170
- return undefined;
1171
- };
1172
- return rawPage(next);
1173
- };
1174
- }
1175
1089
  function installMiniProgramPerformanceMonitor(report, options) {
1176
1090
  const g = globalThis;
1091
+ const ctx = g.wx || g.Taro;
1092
+ if (!ctx || typeof ctx.getPerformance !== 'function')
1093
+ return;
1177
1094
  if (g.__beLinkClsLoggerMpPerfInstalled__)
1178
1095
  return;
1179
1096
  g.__beLinkClsLoggerMpPerfInstalled__ = true;
1180
- // 路由切换耗时(用 API 回调近似)
1181
- for (const apiName of ['navigateTo', 'redirectTo', 'switchTab', 'reLaunch']) {
1182
- try {
1183
- wrapMiniProgramRouteApi(report, options.reportType, apiName, options);
1184
- }
1185
- catch {
1186
- // ignore
1187
- }
1188
- }
1189
- // 页面渲染耗时(onLoad -> onReady)
1190
- try {
1191
- installMiniProgramPageRenderMonitor(report, options.reportType, options);
1192
- }
1193
- catch {
1194
- // ignore
1195
- }
1196
- // wx.getPerformance()(若可用,尝试读取已有 entries)
1197
1097
  try {
1198
- const wxAny = globalThis.wx;
1199
- if (wxAny && typeof wxAny.getPerformance === 'function') {
1200
- const perf = wxAny.getPerformance();
1201
- if (perf && isPlainObject(perf)) {
1202
- // 不同基础库实现差异较大:尽量容错
1203
- setTimeout(() => {
1204
- try {
1205
- if (!sampleHit(options.sampleRate))
1206
- return;
1207
- const entries = typeof perf.getEntries === 'function'
1208
- ? perf.getEntries()
1209
- : typeof perf.getEntriesByType === 'function'
1210
- ? perf.getEntriesByType('navigation')
1211
- : [];
1098
+ const perf = ctx.getPerformance();
1099
+ if (!perf || typeof perf.createObserver !== 'function')
1100
+ return;
1101
+ const observer = perf.createObserver((entryList) => {
1102
+ try {
1103
+ const entries = entryList.getEntries();
1104
+ for (const entry of entries) {
1105
+ if (!sampleHit(options.sampleRate))
1106
+ continue;
1107
+ // Page Render: firstRender
1108
+ if (entry.entryType === 'render' && entry.name === 'firstRender') {
1212
1109
  report(options.reportType, {
1213
- metric: 'mp-performance',
1214
- entries: truncate$1(stringifyLogValue(entries), options.maxTextLength),
1110
+ metric: 'page-render',
1111
+ duration: entry.duration,
1112
+ pagePath: entry.path || '',
1113
+ unit: 'ms',
1215
1114
  });
1216
1115
  }
1217
- catch {
1218
- // ignore
1116
+ // Route Switch: route
1117
+ else if (entry.entryType === 'navigation' && entry.name === 'route') {
1118
+ report(options.reportType, {
1119
+ metric: 'route',
1120
+ duration: entry.duration,
1121
+ pagePath: entry.path || '',
1122
+ unit: 'ms',
1123
+ });
1219
1124
  }
1220
- }, 0);
1125
+ // App Launch: appLaunch (Cold)
1126
+ else if (entry.entryType === 'navigation' && entry.name === 'appLaunch') {
1127
+ report(options.reportType, {
1128
+ metric: 'app-launch',
1129
+ duration: entry.duration,
1130
+ launchType: 'cold',
1131
+ unit: 'ms',
1132
+ });
1133
+ }
1134
+ }
1221
1135
  }
1222
- }
1136
+ catch {
1137
+ // ignore
1138
+ }
1139
+ });
1140
+ observer.observe({ entryTypes: ['navigation', 'render'] });
1223
1141
  }
1224
1142
  catch {
1225
1143
  // ignore
package/dist/web.js CHANGED
@@ -1109,140 +1109,58 @@ function installBrowserPerformanceMonitor(report, options) {
1109
1109
  }
1110
1110
  }
1111
1111
  }
1112
- function wrapMiniProgramRouteApi(report, reportType, apiName, options) {
1113
- const wxAny = globalThis.wx;
1114
- if (!wxAny || typeof wxAny[apiName] !== 'function')
1115
- return;
1116
- const flagKey = `__beLinkClsLoggerMpRouteWrapped__${apiName}`;
1117
- if (wxAny[flagKey])
1118
- return;
1119
- wxAny[flagKey] = true;
1120
- const raw = wxAny[apiName].bind(wxAny);
1121
- wxAny[apiName] = (opts) => {
1122
- const start = Date.now();
1123
- const url = opts?.url ? String(opts.url) : '';
1124
- const wrapCb = (cb, success) => {
1125
- return (...args) => {
1126
- try {
1127
- if (sampleHit(options.sampleRate)) {
1128
- report(reportType, {
1129
- metric: 'route',
1130
- api: apiName,
1131
- url,
1132
- duration: Date.now() - start,
1133
- success: success ? 1 : 0,
1134
- error: success ? '' : truncate$1(stringifyLogValue(args?.[0]), options.maxTextLength),
1135
- unit: 'ms',
1136
- });
1137
- }
1138
- }
1139
- catch {
1140
- // ignore
1141
- }
1142
- if (typeof cb === 'function')
1143
- return cb(...args);
1144
- return undefined;
1145
- };
1146
- };
1147
- const next = { ...(opts ?? {}) };
1148
- next.success = wrapCb(next.success, true);
1149
- next.fail = wrapCb(next.fail, false);
1150
- return raw(next);
1151
- };
1152
- }
1153
- function installMiniProgramPageRenderMonitor(report, reportType, options) {
1154
- const g = globalThis;
1155
- if (typeof g.Page !== 'function')
1156
- return;
1157
- if (g.__beLinkClsLoggerPageWrapped__)
1158
- return;
1159
- g.__beLinkClsLoggerPageWrapped__ = true;
1160
- const rawPage = g.Page;
1161
- g.Page = (pageOptions) => {
1162
- const next = { ...(pageOptions ?? {}) };
1163
- const rawOnLoad = next.onLoad;
1164
- const rawOnReady = next.onReady;
1165
- next.onLoad = function (...args) {
1166
- try {
1167
- this.__beLinkClsLoggerPageLoadTs__ = Date.now();
1168
- }
1169
- catch {
1170
- // ignore
1171
- }
1172
- if (typeof rawOnLoad === 'function')
1173
- return rawOnLoad.apply(this, args);
1174
- return undefined;
1175
- };
1176
- next.onReady = function (...args) {
1177
- try {
1178
- const start = this.__beLinkClsLoggerPageLoadTs__;
1179
- if (typeof start === 'number' && sampleHit(options.sampleRate)) {
1180
- report(reportType, {
1181
- metric: 'page-render',
1182
- route: this?.route ? String(this.route) : '',
1183
- duration: Date.now() - start,
1184
- unit: 'ms',
1185
- });
1186
- }
1187
- }
1188
- catch {
1189
- // ignore
1190
- }
1191
- if (typeof rawOnReady === 'function')
1192
- return rawOnReady.apply(this, args);
1193
- return undefined;
1194
- };
1195
- return rawPage(next);
1196
- };
1197
- }
1198
1112
  function installMiniProgramPerformanceMonitor(report, options) {
1199
1113
  const g = globalThis;
1114
+ const ctx = g.wx || g.Taro;
1115
+ if (!ctx || typeof ctx.getPerformance !== 'function')
1116
+ return;
1200
1117
  if (g.__beLinkClsLoggerMpPerfInstalled__)
1201
1118
  return;
1202
1119
  g.__beLinkClsLoggerMpPerfInstalled__ = true;
1203
- // 路由切换耗时(用 API 回调近似)
1204
- for (const apiName of ['navigateTo', 'redirectTo', 'switchTab', 'reLaunch']) {
1205
- try {
1206
- wrapMiniProgramRouteApi(report, options.reportType, apiName, options);
1207
- }
1208
- catch {
1209
- // ignore
1210
- }
1211
- }
1212
- // 页面渲染耗时(onLoad -> onReady)
1213
- try {
1214
- installMiniProgramPageRenderMonitor(report, options.reportType, options);
1215
- }
1216
- catch {
1217
- // ignore
1218
- }
1219
- // wx.getPerformance()(若可用,尝试读取已有 entries)
1220
1120
  try {
1221
- const wxAny = globalThis.wx;
1222
- if (wxAny && typeof wxAny.getPerformance === 'function') {
1223
- const perf = wxAny.getPerformance();
1224
- if (perf && isPlainObject(perf)) {
1225
- // 不同基础库实现差异较大:尽量容错
1226
- setTimeout(() => {
1227
- try {
1228
- if (!sampleHit(options.sampleRate))
1229
- return;
1230
- const entries = typeof perf.getEntries === 'function'
1231
- ? perf.getEntries()
1232
- : typeof perf.getEntriesByType === 'function'
1233
- ? perf.getEntriesByType('navigation')
1234
- : [];
1121
+ const perf = ctx.getPerformance();
1122
+ if (!perf || typeof perf.createObserver !== 'function')
1123
+ return;
1124
+ const observer = perf.createObserver((entryList) => {
1125
+ try {
1126
+ const entries = entryList.getEntries();
1127
+ for (const entry of entries) {
1128
+ if (!sampleHit(options.sampleRate))
1129
+ continue;
1130
+ // Page Render: firstRender
1131
+ if (entry.entryType === 'render' && entry.name === 'firstRender') {
1235
1132
  report(options.reportType, {
1236
- metric: 'mp-performance',
1237
- entries: truncate$1(stringifyLogValue(entries), options.maxTextLength),
1133
+ metric: 'page-render',
1134
+ duration: entry.duration,
1135
+ pagePath: entry.path || '',
1136
+ unit: 'ms',
1238
1137
  });
1239
1138
  }
1240
- catch {
1241
- // ignore
1139
+ // Route Switch: route
1140
+ else if (entry.entryType === 'navigation' && entry.name === 'route') {
1141
+ report(options.reportType, {
1142
+ metric: 'route',
1143
+ duration: entry.duration,
1144
+ pagePath: entry.path || '',
1145
+ unit: 'ms',
1146
+ });
1242
1147
  }
1243
- }, 0);
1148
+ // App Launch: appLaunch (Cold)
1149
+ else if (entry.entryType === 'navigation' && entry.name === 'appLaunch') {
1150
+ report(options.reportType, {
1151
+ metric: 'app-launch',
1152
+ duration: entry.duration,
1153
+ launchType: 'cold',
1154
+ unit: 'ms',
1155
+ });
1156
+ }
1157
+ }
1244
1158
  }
1245
- }
1159
+ catch {
1160
+ // ignore
1161
+ }
1162
+ });
1163
+ observer.observe({ entryTypes: ['navigation', 'render'] });
1246
1164
  }
1247
1165
  catch {
1248
1166
  // ignore
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@be-link/cls-logger",
3
- "version": "1.0.1-beta.8",
3
+ "version": "1.0.1-beta.9",
4
4
  "description": "@be-link cls-logger - 腾讯云 CLS 日志上报封装",
5
5
  "homepage": "https://github.com/snowmountain-top/be-link",
6
6
  "author": "zhuiyi",