@howone/sdk 0.2.7 → 0.2.8
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 +51 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +51 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -587,7 +587,7 @@ var UnifiedAuthService = class {
|
|
|
587
587
|
}
|
|
588
588
|
generateAppId() {
|
|
589
589
|
const urlParams = new URLSearchParams(window.location.search);
|
|
590
|
-
let appId = urlParams.get("appId");
|
|
590
|
+
let appId = urlParams.get("appId") || urlParams.get("project_id");
|
|
591
591
|
return appId || "app";
|
|
592
592
|
}
|
|
593
593
|
/**
|
|
@@ -3157,6 +3157,7 @@ var ErrorTracking = class {
|
|
|
3157
3157
|
this.setupGlobalErrorListeners();
|
|
3158
3158
|
this.setupConsoleInterception();
|
|
3159
3159
|
this.setupNetworkMonitoring();
|
|
3160
|
+
this.setupResourceLoadMonitoring();
|
|
3160
3161
|
this.initialized = true;
|
|
3161
3162
|
setTimeout(() => {
|
|
3162
3163
|
this.fullyInitialized = true;
|
|
@@ -3167,7 +3168,7 @@ var ErrorTracking = class {
|
|
|
3167
3168
|
*/
|
|
3168
3169
|
setupGlobalErrorListeners() {
|
|
3169
3170
|
window.addEventListener("error", (event) => {
|
|
3170
|
-
event.
|
|
3171
|
+
this.internalLog("warn", "\u{1F3AF}\u{1F3AF}\u{1F3AF} window.error \u4E8B\u4EF6\u89E6\u53D1:", event.message || event.error?.message);
|
|
3171
3172
|
this.handleError(event.error || new Error(event.message), {
|
|
3172
3173
|
filename: event.filename,
|
|
3173
3174
|
lineno: event.lineno,
|
|
@@ -3177,7 +3178,6 @@ var ErrorTracking = class {
|
|
|
3177
3178
|
});
|
|
3178
3179
|
});
|
|
3179
3180
|
window.addEventListener("unhandledrejection", (event) => {
|
|
3180
|
-
event.preventDefault();
|
|
3181
3181
|
const error = event.reason instanceof Error ? event.reason : new Error(String(event.reason));
|
|
3182
3182
|
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);
|
|
3183
3183
|
this.handleError(error, {
|
|
@@ -3295,6 +3295,43 @@ var ErrorTracking = class {
|
|
|
3295
3295
|
this.internalLog("error", "[ErrorTracking] \u63A7\u5236\u53F0\u8F6C\u53D1\u5931\u8D25:", error);
|
|
3296
3296
|
}
|
|
3297
3297
|
}
|
|
3298
|
+
/**
|
|
3299
|
+
* 设置资源加载监控(使用 PerformanceObserver 监控 504 错误)
|
|
3300
|
+
*/
|
|
3301
|
+
setupResourceLoadMonitoring() {
|
|
3302
|
+
if (!window.PerformanceObserver) {
|
|
3303
|
+
this.internalLog("warn", "\u274C\u274C\u274CPerformanceObserver \u4E0D\u652F\u6301\u274C\u274C\u274C");
|
|
3304
|
+
return;
|
|
3305
|
+
}
|
|
3306
|
+
try {
|
|
3307
|
+
const observer = new PerformanceObserver((list) => {
|
|
3308
|
+
for (const entry of list.getEntries()) {
|
|
3309
|
+
console.log("\u{1F30D}\u{1F30D}entry---------entry\u{1F30D}\u{1F30D}", entry);
|
|
3310
|
+
if (entry.entryType === "resource") {
|
|
3311
|
+
const resourceEntry = entry;
|
|
3312
|
+
if (resourceEntry.transferSize === 0 && !resourceEntry.duration) {
|
|
3313
|
+
const url = resourceEntry.name;
|
|
3314
|
+
console.log("\u{1F30D}\u{1F30D}url--------------url\u{1F30D}\u{1F30D}", url);
|
|
3315
|
+
if (url.includes(".js") || url.includes(".mjs")) {
|
|
3316
|
+
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);
|
|
3317
|
+
this.handleError(new Error(`Resource load failed (possibly 504): ${url}`), {
|
|
3318
|
+
type: "resource",
|
|
3319
|
+
resourceUrl: url,
|
|
3320
|
+
source: "PerformanceObserver",
|
|
3321
|
+
transferSize: resourceEntry.transferSize,
|
|
3322
|
+
duration: resourceEntry.duration
|
|
3323
|
+
});
|
|
3324
|
+
}
|
|
3325
|
+
}
|
|
3326
|
+
}
|
|
3327
|
+
}
|
|
3328
|
+
});
|
|
3329
|
+
observer.observe({ entryTypes: ["resource"] });
|
|
3330
|
+
this.internalLog("log", "\u2705\u2705\u2705\u2705\u2705\u2705\u2705\u2705\u2705\u2705\u5DF2\u542F\u52A8\uFF0C\u76D1\u63A7\u8D44\u6E90\u52A0\u8F7D");
|
|
3331
|
+
} catch (error) {
|
|
3332
|
+
this.internalLog("error", "\u274C\u274C\u274C\u274C\u274C\u274C\u274C\u274C\u274C\u274CPerformanceObserver \u8BBE\u7F6E\u5931\u8D25:", error);
|
|
3333
|
+
}
|
|
3334
|
+
}
|
|
3298
3335
|
/**
|
|
3299
3336
|
* 设置网络监控
|
|
3300
3337
|
*/
|
|
@@ -3428,11 +3465,18 @@ var ErrorTracking = class {
|
|
|
3428
3465
|
return false;
|
|
3429
3466
|
}
|
|
3430
3467
|
/**
|
|
3431
|
-
* 判断是否是 504
|
|
3468
|
+
* 判断是否是 504 错误或资源加载失败,需要立即发送
|
|
3432
3469
|
*/
|
|
3433
3470
|
isCriticalNetworkError(error, details) {
|
|
3434
3471
|
const message = error.message?.toLowerCase() || "";
|
|
3435
|
-
|
|
3472
|
+
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);
|
|
3473
|
+
if (message.includes("504") || message.includes("gateway timeout")) {
|
|
3474
|
+
return true;
|
|
3475
|
+
}
|
|
3476
|
+
if (details.type === "resource" && details.source === "PerformanceObserver") {
|
|
3477
|
+
return true;
|
|
3478
|
+
}
|
|
3479
|
+
return false;
|
|
3436
3480
|
}
|
|
3437
3481
|
/**
|
|
3438
3482
|
* 发送统一格式的错误
|
|
@@ -3440,9 +3484,11 @@ var ErrorTracking = class {
|
|
|
3440
3484
|
sendUnifiedError(error, details = {}) {
|
|
3441
3485
|
if (window.parent === window) return;
|
|
3442
3486
|
const isCriticalError = this.isCriticalNetworkError(error, details);
|
|
3487
|
+
console.log("\u53D1\u73B0504\u9519\u8BEF\u4E86\u5417\u2753\u2753\u2753\u2753\u2753\u2753\u2753\u2753", isCriticalError);
|
|
3443
3488
|
if (isCriticalError) {
|
|
3444
3489
|
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);
|
|
3445
3490
|
}
|
|
3491
|
+
console.log("\u7B2C\u4E8C\u4E2A\u5224\u65AD\u662F\u4EC0\u4E48\u2753\u2753\u2753\u2753\u2753\u2753\u2753\u2753", this.fullyInitialized);
|
|
3446
3492
|
if (!isCriticalError && !this.fullyInitialized) {
|
|
3447
3493
|
return;
|
|
3448
3494
|
}
|