@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.mjs
CHANGED
|
@@ -516,7 +516,7 @@ var UnifiedAuthService = class {
|
|
|
516
516
|
}
|
|
517
517
|
generateAppId() {
|
|
518
518
|
const urlParams = new URLSearchParams(window.location.search);
|
|
519
|
-
let appId = urlParams.get("appId");
|
|
519
|
+
let appId = urlParams.get("appId") || urlParams.get("project_id");
|
|
520
520
|
return appId || "app";
|
|
521
521
|
}
|
|
522
522
|
/**
|
|
@@ -3086,6 +3086,7 @@ var ErrorTracking = class {
|
|
|
3086
3086
|
this.setupGlobalErrorListeners();
|
|
3087
3087
|
this.setupConsoleInterception();
|
|
3088
3088
|
this.setupNetworkMonitoring();
|
|
3089
|
+
this.setupResourceLoadMonitoring();
|
|
3089
3090
|
this.initialized = true;
|
|
3090
3091
|
setTimeout(() => {
|
|
3091
3092
|
this.fullyInitialized = true;
|
|
@@ -3096,7 +3097,7 @@ var ErrorTracking = class {
|
|
|
3096
3097
|
*/
|
|
3097
3098
|
setupGlobalErrorListeners() {
|
|
3098
3099
|
window.addEventListener("error", (event) => {
|
|
3099
|
-
event.
|
|
3100
|
+
this.internalLog("warn", "\u{1F3AF}\u{1F3AF}\u{1F3AF} window.error \u4E8B\u4EF6\u89E6\u53D1:", event.message || event.error?.message);
|
|
3100
3101
|
this.handleError(event.error || new Error(event.message), {
|
|
3101
3102
|
filename: event.filename,
|
|
3102
3103
|
lineno: event.lineno,
|
|
@@ -3106,7 +3107,6 @@ var ErrorTracking = class {
|
|
|
3106
3107
|
});
|
|
3107
3108
|
});
|
|
3108
3109
|
window.addEventListener("unhandledrejection", (event) => {
|
|
3109
|
-
event.preventDefault();
|
|
3110
3110
|
const error = event.reason instanceof Error ? event.reason : new Error(String(event.reason));
|
|
3111
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
3112
|
this.handleError(error, {
|
|
@@ -3224,6 +3224,43 @@ var ErrorTracking = class {
|
|
|
3224
3224
|
this.internalLog("error", "[ErrorTracking] \u63A7\u5236\u53F0\u8F6C\u53D1\u5931\u8D25:", error);
|
|
3225
3225
|
}
|
|
3226
3226
|
}
|
|
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
|
+
}
|
|
3227
3264
|
/**
|
|
3228
3265
|
* 设置网络监控
|
|
3229
3266
|
*/
|
|
@@ -3357,11 +3394,18 @@ var ErrorTracking = class {
|
|
|
3357
3394
|
return false;
|
|
3358
3395
|
}
|
|
3359
3396
|
/**
|
|
3360
|
-
* 判断是否是 504
|
|
3397
|
+
* 判断是否是 504 错误或资源加载失败,需要立即发送
|
|
3361
3398
|
*/
|
|
3362
3399
|
isCriticalNetworkError(error, details) {
|
|
3363
3400
|
const message = error.message?.toLowerCase() || "";
|
|
3364
|
-
|
|
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;
|
|
3365
3409
|
}
|
|
3366
3410
|
/**
|
|
3367
3411
|
* 发送统一格式的错误
|
|
@@ -3369,9 +3413,11 @@ var ErrorTracking = class {
|
|
|
3369
3413
|
sendUnifiedError(error, details = {}) {
|
|
3370
3414
|
if (window.parent === window) return;
|
|
3371
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);
|
|
3372
3417
|
if (isCriticalError) {
|
|
3373
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);
|
|
3374
3419
|
}
|
|
3420
|
+
console.log("\u7B2C\u4E8C\u4E2A\u5224\u65AD\u662F\u4EC0\u4E48\u2753\u2753\u2753\u2753\u2753\u2753\u2753\u2753", this.fullyInitialized);
|
|
3375
3421
|
if (!isCriticalError && !this.fullyInitialized) {
|
|
3376
3422
|
return;
|
|
3377
3423
|
}
|