@howone/sdk 0.2.9 → 0.2.10

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.mjs CHANGED
@@ -3086,7 +3086,6 @@ var ErrorTracking = class {
3086
3086
  this.setupGlobalErrorListeners();
3087
3087
  this.setupConsoleInterception();
3088
3088
  this.setupNetworkMonitoring();
3089
- this.setupResourceLoadMonitoring();
3090
3089
  this.initialized = true;
3091
3090
  setTimeout(() => {
3092
3091
  this.fullyInitialized = true;
@@ -3097,7 +3096,7 @@ var ErrorTracking = class {
3097
3096
  */
3098
3097
  setupGlobalErrorListeners() {
3099
3098
  window.addEventListener("error", (event) => {
3100
- this.internalLog("warn", "\u{1F3AF}\u{1F3AF}\u{1F3AF} window.error \u4E8B\u4EF6\u89E6\u53D1:", event.message || event.error?.message);
3099
+ event.preventDefault();
3101
3100
  this.handleError(event.error || new Error(event.message), {
3102
3101
  filename: event.filename,
3103
3102
  lineno: event.lineno,
@@ -3107,8 +3106,8 @@ var ErrorTracking = class {
3107
3106
  });
3108
3107
  });
3109
3108
  window.addEventListener("unhandledrejection", (event) => {
3109
+ event.preventDefault();
3110
3110
  const error = event.reason instanceof Error ? event.reason : new Error(String(event.reason));
3111
- this.internalLog("warn", "\u{1F680}\u{1F680}\u{1F680}\u{1F680}\u{1F680}\u{1F680}\u{1F680}\u{1F680}\u{1F680}\u{1F680}\u{1F680}\u{1F680}\u6355\u83B7 unhandledrejection:", error.message);
3112
3111
  this.handleError(error, {
3113
3112
  type: "promise",
3114
3113
  source: "unhandledrejection"
@@ -3143,12 +3142,7 @@ var ErrorTracking = class {
3143
3142
  */
3144
3143
  safeForwardConsoleToParent(method, args) {
3145
3144
  if (window.parent === window) return;
3146
- const argsStr = args.map((arg) => String(arg)).join(" ").toLowerCase();
3147
- const is504Error = argsStr.includes("504") || argsStr.includes("gateway timeout");
3148
- if (is504Error) {
3149
- this.internalLog("warn", "\u{1F697}\u{1F697}\u{1F697}\u{1F697}\u{1F697}\u{1F697}\u{1F697}\u{1F697}\u{1F697}\u{1F697}\u{1F697}\u{1F697}\u{1F697}\u{1F697}\u{1F697}\u{1F697}[ErrorTracking] \u63A7\u5236\u53F0\u6355\u83B7 504 \u9519\u8BEF:", argsStr.substring(0, 100));
3150
- }
3151
- if (!is504Error && !this.fullyInitialized) return;
3145
+ if (!this.fullyInitialized) return;
3152
3146
  try {
3153
3147
  let stack = null;
3154
3148
  if (method === "warn" || method === "error") {
@@ -3224,43 +3218,6 @@ var ErrorTracking = class {
3224
3218
  this.internalLog("error", "[ErrorTracking] \u63A7\u5236\u53F0\u8F6C\u53D1\u5931\u8D25:", error);
3225
3219
  }
3226
3220
  }
3227
- /**
3228
- * 设置资源加载监控(使用 PerformanceObserver 监控 504 错误)
3229
- */
3230
- setupResourceLoadMonitoring() {
3231
- if (!window.PerformanceObserver) {
3232
- this.internalLog("warn", "\u274C\u274C\u274CPerformanceObserver \u4E0D\u652F\u6301\u274C\u274C\u274C");
3233
- return;
3234
- }
3235
- try {
3236
- const observer = new PerformanceObserver((list) => {
3237
- for (const entry of list.getEntries()) {
3238
- console.log("\u{1F30D}\u{1F30D}entry---------entry\u{1F30D}\u{1F30D}", entry);
3239
- if (entry.entryType === "resource") {
3240
- const resourceEntry = entry;
3241
- if (resourceEntry.transferSize === 0 && !resourceEntry.duration) {
3242
- const url = resourceEntry.name;
3243
- console.log("\u{1F30D}\u{1F30D}url--------------url\u{1F30D}\u{1F30D}", url);
3244
- if (url.includes(".js") || url.includes(".mjs")) {
3245
- this.internalLog("error", "\u274C\u274C\u274C\u274C\u274C\u274C\u274C\u274C\u274C\u274C\u68C0\u6D4B\u5230\u8D44\u6E90\u52A0\u8F7D\u5931\u8D25\uFF08\u53EF\u80FD\u662F 504\uFF09:", url);
3246
- this.handleError(new Error(`Resource load failed (possibly 504): ${url}`), {
3247
- type: "resource",
3248
- resourceUrl: url,
3249
- source: "PerformanceObserver",
3250
- transferSize: resourceEntry.transferSize,
3251
- duration: resourceEntry.duration
3252
- });
3253
- }
3254
- }
3255
- }
3256
- }
3257
- });
3258
- observer.observe({ entryTypes: ["resource"] });
3259
- this.internalLog("log", "\u2705\u2705\u2705\u2705\u2705\u2705\u2705\u2705\u2705\u2705\u5DF2\u542F\u52A8\uFF0C\u76D1\u63A7\u8D44\u6E90\u52A0\u8F7D");
3260
- } catch (error) {
3261
- this.internalLog("error", "\u274C\u274C\u274C\u274C\u274C\u274C\u274C\u274C\u274C\u274CPerformanceObserver \u8BBE\u7F6E\u5931\u8D25:", error);
3262
- }
3263
- }
3264
3221
  /**
3265
3222
  * 设置网络监控
3266
3223
  */
@@ -3393,34 +3350,12 @@ var ErrorTracking = class {
3393
3350
  }, 5e3);
3394
3351
  return false;
3395
3352
  }
3396
- /**
3397
- * 判断是否是 504 错误或资源加载失败,需要立即发送
3398
- */
3399
- isCriticalNetworkError(error, details) {
3400
- const message = error.message?.toLowerCase() || "";
3401
- console.log("\u5F00\u59CB\u68C0\u6D4B\u2705\u5F00\u59CB\u68C0\u6D4B\u2705\u5F00\u59CB\u68C0\u6D4B\u2705\u5F00\u59CB\u68C0\u6D4B\u2705\u5F00\u59CB\u68C0\u6D4B\u2705", message, details);
3402
- if (message.includes("504") || message.includes("gateway timeout")) {
3403
- return true;
3404
- }
3405
- if (details.type === "resource" && details.source === "PerformanceObserver") {
3406
- return true;
3407
- }
3408
- return false;
3409
- }
3410
3353
  /**
3411
3354
  * 发送统一格式的错误
3412
3355
  */
3413
3356
  sendUnifiedError(error, details = {}) {
3414
3357
  if (window.parent === window) return;
3415
- const isCriticalError = this.isCriticalNetworkError(error, details);
3416
- console.log("\u53D1\u73B0504\u9519\u8BEF\u4E86\u5417\u2753\u2753\u2753\u2753\u2753\u2753\u2753\u2753", isCriticalError);
3417
- if (isCriticalError) {
3418
- this.internalLog("warn", "\u{1F31E}\u{1F31E}\u{1F31E}\u{1F31E}\u{1F31E}\u{1F31E}\u{1F31E}\u{1F31E}\u{1F31E}\u{1F31E}\u{1F31E}\u68C0\u6D4B\u5230 504 \u9519\u8BEF\uFF0C\u7ACB\u5373\u53D1\u9001:", error.message);
3419
- }
3420
- console.log("\u7B2C\u4E8C\u4E2A\u5224\u65AD\u662F\u4EC0\u4E48\u2753\u2753\u2753\u2753\u2753\u2753\u2753\u2753", this.fullyInitialized);
3421
- if (!isCriticalError && !this.fullyInitialized) {
3422
- return;
3423
- }
3358
+ if (!this.fullyInitialized) return;
3424
3359
  try {
3425
3360
  const currentViewInfo = this.viewDetector?.getCurrentViewInfo();
3426
3361
  const payload = {