@howone/sdk 0.2.8 → 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.js +5 -70
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5 -70
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3157,7 +3157,6 @@ var ErrorTracking = class {
|
|
|
3157
3157
|
this.setupGlobalErrorListeners();
|
|
3158
3158
|
this.setupConsoleInterception();
|
|
3159
3159
|
this.setupNetworkMonitoring();
|
|
3160
|
-
this.setupResourceLoadMonitoring();
|
|
3161
3160
|
this.initialized = true;
|
|
3162
3161
|
setTimeout(() => {
|
|
3163
3162
|
this.fullyInitialized = true;
|
|
@@ -3168,7 +3167,7 @@ var ErrorTracking = class {
|
|
|
3168
3167
|
*/
|
|
3169
3168
|
setupGlobalErrorListeners() {
|
|
3170
3169
|
window.addEventListener("error", (event) => {
|
|
3171
|
-
|
|
3170
|
+
event.preventDefault();
|
|
3172
3171
|
this.handleError(event.error || new Error(event.message), {
|
|
3173
3172
|
filename: event.filename,
|
|
3174
3173
|
lineno: event.lineno,
|
|
@@ -3178,8 +3177,8 @@ var ErrorTracking = class {
|
|
|
3178
3177
|
});
|
|
3179
3178
|
});
|
|
3180
3179
|
window.addEventListener("unhandledrejection", (event) => {
|
|
3180
|
+
event.preventDefault();
|
|
3181
3181
|
const error = event.reason instanceof Error ? event.reason : new Error(String(event.reason));
|
|
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
3182
|
this.handleError(error, {
|
|
3184
3183
|
type: "promise",
|
|
3185
3184
|
source: "unhandledrejection"
|
|
@@ -3214,12 +3213,7 @@ var ErrorTracking = class {
|
|
|
3214
3213
|
*/
|
|
3215
3214
|
safeForwardConsoleToParent(method, args) {
|
|
3216
3215
|
if (window.parent === window) return;
|
|
3217
|
-
|
|
3218
|
-
const is504Error = argsStr.includes("504") || argsStr.includes("gateway timeout");
|
|
3219
|
-
if (is504Error) {
|
|
3220
|
-
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));
|
|
3221
|
-
}
|
|
3222
|
-
if (!is504Error && !this.fullyInitialized) return;
|
|
3216
|
+
if (!this.fullyInitialized) return;
|
|
3223
3217
|
try {
|
|
3224
3218
|
let stack = null;
|
|
3225
3219
|
if (method === "warn" || method === "error") {
|
|
@@ -3295,43 +3289,6 @@ var ErrorTracking = class {
|
|
|
3295
3289
|
this.internalLog("error", "[ErrorTracking] \u63A7\u5236\u53F0\u8F6C\u53D1\u5931\u8D25:", error);
|
|
3296
3290
|
}
|
|
3297
3291
|
}
|
|
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
|
-
}
|
|
3335
3292
|
/**
|
|
3336
3293
|
* 设置网络监控
|
|
3337
3294
|
*/
|
|
@@ -3464,34 +3421,12 @@ var ErrorTracking = class {
|
|
|
3464
3421
|
}, 5e3);
|
|
3465
3422
|
return false;
|
|
3466
3423
|
}
|
|
3467
|
-
/**
|
|
3468
|
-
* 判断是否是 504 错误或资源加载失败,需要立即发送
|
|
3469
|
-
*/
|
|
3470
|
-
isCriticalNetworkError(error, details) {
|
|
3471
|
-
const message = error.message?.toLowerCase() || "";
|
|
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;
|
|
3480
|
-
}
|
|
3481
3424
|
/**
|
|
3482
3425
|
* 发送统一格式的错误
|
|
3483
3426
|
*/
|
|
3484
3427
|
sendUnifiedError(error, details = {}) {
|
|
3485
3428
|
if (window.parent === window) return;
|
|
3486
|
-
|
|
3487
|
-
console.log("\u53D1\u73B0504\u9519\u8BEF\u4E86\u5417\u2753\u2753\u2753\u2753\u2753\u2753\u2753\u2753", isCriticalError);
|
|
3488
|
-
if (isCriticalError) {
|
|
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);
|
|
3490
|
-
}
|
|
3491
|
-
console.log("\u7B2C\u4E8C\u4E2A\u5224\u65AD\u662F\u4EC0\u4E48\u2753\u2753\u2753\u2753\u2753\u2753\u2753\u2753", this.fullyInitialized);
|
|
3492
|
-
if (!isCriticalError && !this.fullyInitialized) {
|
|
3493
|
-
return;
|
|
3494
|
-
}
|
|
3429
|
+
if (!this.fullyInitialized) return;
|
|
3495
3430
|
try {
|
|
3496
3431
|
const currentViewInfo = this.viewDetector?.getCurrentViewInfo();
|
|
3497
3432
|
const payload = {
|
|
@@ -6070,7 +6005,7 @@ function createClient(opts) {
|
|
|
6070
6005
|
const bizWrapped = wrapRequestWithProjectPrefix(biz, opts?.projectId);
|
|
6071
6006
|
let token = null;
|
|
6072
6007
|
function getAvailableToken() {
|
|
6073
|
-
return
|
|
6008
|
+
return getGlobalAvailableToken();
|
|
6074
6009
|
}
|
|
6075
6010
|
try {
|
|
6076
6011
|
if (opts?.projectId) {
|