@antglobal/rlog-sdk 0.0.1755855517-dev.17 → 0.0.1755855517-dev.18
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/README.md +203 -483
- package/dist/esm/index.d.ts +1 -2
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +36 -18
- package/dist/esm/lib/config.js +1 -1
- package/dist/esm/lib/error-trigger.d.ts.map +1 -1
- package/dist/esm/lib/error-trigger.js +5 -4
- package/dist/esm/lib/error.d.ts.map +1 -1
- package/dist/esm/lib/error.js +61 -50
- package/dist/esm/lib/init.d.ts.map +1 -1
- package/dist/esm/lib/init.js +43 -15
- package/dist/esm/lib/net.d.ts.map +1 -1
- package/dist/esm/lib/net.js +195 -160
- package/dist/esm/lib/router-monitor.d.ts.map +1 -1
- package/dist/esm/lib/router-monitor.js +18 -11
- package/dist/esm/lib/rrweb.d.ts.map +1 -1
- package/dist/esm/lib/rrweb.js +12 -8
- package/dist/esm/lib/upload-worker-manager.d.ts.map +1 -1
- package/dist/esm/lib/upload-worker-manager.js +59 -42
- package/dist/esm/lib/uploader.d.ts.map +1 -1
- package/dist/esm/lib/uploader.js +54 -50
- package/dist/lib/index.d.ts +1 -2
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +41 -17
- package/dist/lib/lib/config.js +1 -1
- package/dist/lib/lib/error-trigger.d.ts.map +1 -1
- package/dist/lib/lib/error-trigger.js +5 -4
- package/dist/lib/lib/error.d.ts.map +1 -1
- package/dist/lib/lib/error.js +61 -50
- package/dist/lib/lib/init.d.ts.map +1 -1
- package/dist/lib/lib/init.js +43 -15
- package/dist/lib/lib/net.d.ts.map +1 -1
- package/dist/lib/lib/net.js +195 -160
- package/dist/lib/lib/router-monitor.d.ts.map +1 -1
- package/dist/lib/lib/router-monitor.js +18 -11
- package/dist/lib/lib/rrweb.d.ts.map +1 -1
- package/dist/lib/lib/rrweb.js +12 -8
- package/dist/lib/lib/upload-worker-manager.d.ts.map +1 -1
- package/dist/lib/lib/upload-worker-manager.js +59 -42
- package/dist/lib/lib/uploader.d.ts.map +1 -1
- package/dist/lib/lib/uploader.js +54 -50
- package/dist/rlog-sdk.min.js +1 -1
- package/package.json +1 -1
package/dist/esm/index.d.ts
CHANGED
|
@@ -32,8 +32,7 @@ declare const debug: {
|
|
|
32
32
|
eventCount: number;
|
|
33
33
|
}>;
|
|
34
34
|
clearStorage(): Promise<void>;
|
|
35
|
-
shouldRecordUrl: typeof shouldRecordUrl;
|
|
36
35
|
getConfig: typeof getConfig;
|
|
37
36
|
};
|
|
38
|
-
export { init, cancelRecord, addCustomEvent, setConsumeOnlyMode, isConsumeOnlyMode, toggleConsumeOnlyMode, updateRouterConfig, getCurrentRouteInfo, manualRouteChange, stopRouterMonitor, setCustomHeaders, getCustomHeaders, setWhiteListUrls, setBlackListUrls, getBlackListUrls, getWhiteListUrls, getSdkLogEndpoint, reportError, cleanupErrorHandler, debug, };
|
|
37
|
+
export { init, cancelRecord, addCustomEvent, setConsumeOnlyMode, isConsumeOnlyMode, toggleConsumeOnlyMode, updateRouterConfig, getCurrentRouteInfo, manualRouteChange, stopRouterMonitor, shouldRecordUrl, setCustomHeaders, getCustomHeaders, setWhiteListUrls, setBlackListUrls, getBlackListUrls, getWhiteListUrls, getSdkLogEndpoint, reportError, cleanupErrorHandler, debug, };
|
|
39
38
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EAChB,MAAM,WAAW,CAAC;AAInB,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EACL,kBAA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,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI,CAEjD;AAED,iBAAS,iBAAiB,IAAI,OAAO,CAKpC;AAED,iBAAS,qBAAqB,IAAI,OAAO,CAIxC;AAED,iBAAS,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,GAAG,IAAI,CA6BhD;AAED,QAAA,MAAM,KAAK;6BACgB,MAAM;;;;;;;;;;;CAgBhC,CAAC;AAGF,OAAO,EAEL,IAAI,EACJ,YAAY,EAEZ,cAAc,EAEd,kBAAkB,EAClB,iBAAiB,EACjB,qBAAqB,EAErB,kBAAkB,EAClB,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,EAEjB,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EAEjB,WAAW,EACX,mBAAmB,EAEnB,KAAK,GACN,CAAC"}
|
package/dist/esm/index.js
CHANGED
|
@@ -14,27 +14,42 @@ import { cleanupErrorHandler, getErrorTrigger } from "./lib/error";
|
|
|
14
14
|
import logger from "./lib/logger";
|
|
15
15
|
import { STORAGE_KEY_CONSUME_ONLY, STORAGE_VALUE_CONSUME_ONLY, EVENT_CUSTOM_ERROR } from "./lib/constants";
|
|
16
16
|
function init(param) {
|
|
17
|
-
|
|
17
|
+
try {
|
|
18
|
+
initRLog(param.serv, param.appId, param.cdnConfigUrl);
|
|
19
|
+
} catch (error) {
|
|
20
|
+
logger.error('Failed to initialize SDK:', error);
|
|
21
|
+
}
|
|
18
22
|
return {
|
|
19
23
|
cancel: function cancel() {
|
|
20
24
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
21
|
-
|
|
25
|
+
try {
|
|
26
|
+
cancelRlog(options, 'SDK instance');
|
|
27
|
+
} catch (error) {
|
|
28
|
+
logger.error('Failed to cancel SDK:', error);
|
|
29
|
+
}
|
|
22
30
|
}
|
|
23
31
|
};
|
|
24
32
|
}
|
|
25
33
|
function cancelRecord() {
|
|
26
34
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
27
|
-
|
|
28
|
-
|
|
35
|
+
try {
|
|
36
|
+
logger.warn('Please use rlog.cancel() from initialized instance instead of standalone cancelRecord()');
|
|
37
|
+
cancelRlog(options, 'standalone function');
|
|
38
|
+
} catch (error) {
|
|
39
|
+
logger.error('Failed to cancel record:', error);
|
|
40
|
+
}
|
|
29
41
|
}
|
|
30
42
|
function addCustomEvent(tagName, payload) {
|
|
31
|
-
|
|
43
|
+
try {
|
|
44
|
+
record.addCustomEvent(tagName, payload);
|
|
45
|
+
} catch (error) {
|
|
46
|
+
logger.warn('Failed to add custom event:', error);
|
|
47
|
+
}
|
|
32
48
|
}
|
|
33
49
|
function setConsumeOnlyMode(enable) {
|
|
34
50
|
updateConfig({
|
|
35
51
|
consumeOnly: enable
|
|
36
52
|
});
|
|
37
|
-
logger.log("Consume only mode ".concat(enable ? 'enabled' : 'disabled'));
|
|
38
53
|
}
|
|
39
54
|
function isConsumeOnlyMode() {
|
|
40
55
|
return sessionStorage.getItem(STORAGE_KEY_CONSUME_ONLY) === STORAGE_VALUE_CONSUME_ONLY || !!getConfig().consumeOnly;
|
|
@@ -58,16 +73,20 @@ function reportError(error) {
|
|
|
58
73
|
} catch (e) {
|
|
59
74
|
logger.warn('Failed to add custom error event:', e);
|
|
60
75
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
trigger
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
76
|
+
try {
|
|
77
|
+
var trigger = getErrorTrigger();
|
|
78
|
+
if (trigger) {
|
|
79
|
+
trigger.onError({
|
|
80
|
+
type: 'custom',
|
|
81
|
+
message: message,
|
|
82
|
+
timestamp: Date.now(),
|
|
83
|
+
detail: {
|
|
84
|
+
stack: stack
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
} catch (e) {
|
|
89
|
+
logger.warn('Failed to trigger error mode:', e);
|
|
71
90
|
}
|
|
72
91
|
}
|
|
73
92
|
var debug = {
|
|
@@ -108,7 +127,6 @@ var debug = {
|
|
|
108
127
|
}, _callee2);
|
|
109
128
|
}))();
|
|
110
129
|
},
|
|
111
|
-
shouldRecordUrl: shouldRecordUrl,
|
|
112
130
|
getConfig: getConfig
|
|
113
131
|
};
|
|
114
132
|
|
|
@@ -123,7 +141,7 @@ setConsumeOnlyMode, isConsumeOnlyMode, toggleConsumeOnlyMode,
|
|
|
123
141
|
// 路由监控
|
|
124
142
|
updateRouterConfig, getCurrentRouteInfo, manualRouteChange, stopRouterMonitor,
|
|
125
143
|
// 网络监控
|
|
126
|
-
setCustomHeaders, getCustomHeaders, setWhiteListUrls, setBlackListUrls, getBlackListUrls, getWhiteListUrls, getSdkLogEndpoint,
|
|
144
|
+
shouldRecordUrl, setCustomHeaders, getCustomHeaders, setWhiteListUrls, setBlackListUrls, getBlackListUrls, getWhiteListUrls, getSdkLogEndpoint,
|
|
127
145
|
// 错误处理
|
|
128
146
|
reportError, cleanupErrorHandler,
|
|
129
147
|
// 调试工具
|
package/dist/esm/lib/config.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-trigger.d.ts","sourceRoot":"","sources":["../../../src/lib/error-trigger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAQH,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAID,qBAAa,YAAY;IACvB,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,aAAa,CAAS;IAG9B,OAAO,CAAC,KAAK,CAAwB;IAGrC,OAAO,CAAC,aAAa,CAA8C;IAGnE,OAAO,CAAC,SAAS,CAAS;gBAEd,OAAO,GAAE;QACnB,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,aAAa,CAAC,EAAE,MAAM,CAAC;KACnB;IAKN;;OAEG;IACH,WAAW,IAAI,OAAO;IAItB;;;;;;;;;;OAUG;IACH,OAAO,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI;IAcnC;;OAEG;IACH,OAAO,CAAC,mBAAmB;
|
|
1
|
+
{"version":3,"file":"error-trigger.d.ts","sourceRoot":"","sources":["../../../src/lib/error-trigger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAQH,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAID,qBAAa,YAAY;IACvB,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,aAAa,CAAS;IAG9B,OAAO,CAAC,KAAK,CAAwB;IAGrC,OAAO,CAAC,aAAa,CAA8C;IAGnE,OAAO,CAAC,SAAS,CAAS;gBAEd,OAAO,GAAE;QACnB,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,aAAa,CAAC,EAAE,MAAM,CAAC;KACnB;IAKN;;OAEG;IACH,WAAW,IAAI,OAAO;IAItB;;;;;;;;;;OAUG;IACH,OAAO,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI;IAcnC;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAc3B;;;OAGG;IACH,OAAO,CAAC,aAAa;IAerB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAc1B;;OAEG;IACH,OAAO,IAAI,IAAI;CAahB"}
|
|
@@ -89,7 +89,6 @@ export var ErrorTrigger = /*#__PURE__*/function () {
|
|
|
89
89
|
key: "enterUploadingState",
|
|
90
90
|
value: function enterUploadingState(errorTimestamp) {
|
|
91
91
|
this.state = 'uploading';
|
|
92
|
-
logger.log('ErrorTrigger: error detected, entering uploading state');
|
|
93
92
|
|
|
94
93
|
// 1. 设置上传窗口起点(错误时间 - beforeDuration)
|
|
95
94
|
var windowStart = errorTimestamp - this.beforeDuration;
|
|
@@ -115,7 +114,11 @@ export var ErrorTrigger = /*#__PURE__*/function () {
|
|
|
115
114
|
this.cooldownTimer = null;
|
|
116
115
|
}
|
|
117
116
|
this.cooldownTimer = setTimeout(function () {
|
|
118
|
-
|
|
117
|
+
try {
|
|
118
|
+
_this.exitUploadingState();
|
|
119
|
+
} catch (error) {
|
|
120
|
+
logger.warn('Error in exitUploadingState:', error);
|
|
121
|
+
}
|
|
119
122
|
}, this.afterDuration);
|
|
120
123
|
}
|
|
121
124
|
|
|
@@ -125,8 +128,6 @@ export var ErrorTrigger = /*#__PURE__*/function () {
|
|
|
125
128
|
}, {
|
|
126
129
|
key: "exitUploadingState",
|
|
127
130
|
value: function exitUploadingState() {
|
|
128
|
-
logger.log('ErrorTrigger: cooldown expired, exiting uploading state');
|
|
129
|
-
|
|
130
131
|
// 清理 cooldown 定时器
|
|
131
132
|
if (this.cooldownTimer) {
|
|
132
133
|
clearTimeout(this.cooldownTimer);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../../src/lib/error.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAU/C;;GAEG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI,GAAG,IAAI,CAElE;AAED;;GAEG;AACH,wBAAgB,eAAe,IAAI,YAAY,GAAG,IAAI,CAErD;AAGD,eAAO,MAAM,oBAAoB,SAAU,GAAG,
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../../src/lib/error.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAU/C;;GAEG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI,GAAG,IAAI,CAElE;AAED;;GAEG;AACH,wBAAgB,eAAe,IAAI,YAAY,GAAG,IAAI,CAErD;AAGD,eAAO,MAAM,oBAAoB,SAAU,GAAG,SAuB7C,CAAC;AA6EF,wBAAgB,gBAAgB,SAO/B;AAGD,wBAAgB,mBAAmB,SAOlC"}
|
package/dist/esm/lib/error.js
CHANGED
|
@@ -35,14 +35,18 @@ export var sendErrorToAnalytics = function sendErrorToAnalytics(data) {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
// 错误采集模式下,通知错误触发器
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
errorTriggerInstance
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
38
|
+
try {
|
|
39
|
+
var config = getConfig();
|
|
40
|
+
if (config.captureMode === 'error' && errorTriggerInstance) {
|
|
41
|
+
errorTriggerInstance.onError({
|
|
42
|
+
type: data.type,
|
|
43
|
+
message: data.message || data.type,
|
|
44
|
+
timestamp: data.timestamp || Date.now(),
|
|
45
|
+
detail: data
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
} catch (error) {
|
|
49
|
+
logger.warn('Failed to notify error trigger:', error);
|
|
46
50
|
}
|
|
47
51
|
};
|
|
48
52
|
|
|
@@ -50,42 +54,47 @@ export var sendErrorToAnalytics = function sendErrorToAnalytics(data) {
|
|
|
50
54
|
* JavaScript 运行时错误 & 资源加载错误处理
|
|
51
55
|
*/
|
|
52
56
|
function handleError(event) {
|
|
53
|
-
|
|
57
|
+
try {
|
|
58
|
+
var errorEvent = event;
|
|
54
59
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
// 检查是否是资源加载错误
|
|
61
|
+
if (event.target !== window) {
|
|
62
|
+
var _errorData = {
|
|
63
|
+
type: 'RESOURCE_ERROR',
|
|
64
|
+
resourceType: event.target.tagName,
|
|
65
|
+
url: event.target.src || event.target.href || event.target.src,
|
|
66
|
+
message: errorEvent.message,
|
|
67
|
+
userAgent: navigator.userAgent,
|
|
68
|
+
timestamp: Date.now(),
|
|
69
|
+
location: window.location.href
|
|
70
|
+
};
|
|
71
|
+
sendErrorToAnalytics(_errorData);
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// JavaScript 运行时错误
|
|
76
|
+
var message = errorEvent.message,
|
|
77
|
+
filename = errorEvent.filename,
|
|
78
|
+
lineno = errorEvent.lineno,
|
|
79
|
+
colno = errorEvent.colno,
|
|
80
|
+
error = errorEvent.error;
|
|
81
|
+
var errorData = {
|
|
82
|
+
type: 'JS_ERROR',
|
|
83
|
+
message: message,
|
|
84
|
+
file: filename,
|
|
85
|
+
line: lineno,
|
|
86
|
+
column: colno,
|
|
87
|
+
stack: error === null || error === void 0 ? void 0 : error.stack,
|
|
62
88
|
userAgent: navigator.userAgent,
|
|
63
89
|
timestamp: Date.now(),
|
|
64
90
|
location: window.location.href
|
|
65
91
|
};
|
|
66
|
-
sendErrorToAnalytics(
|
|
67
|
-
|
|
92
|
+
sendErrorToAnalytics(errorData);
|
|
93
|
+
} catch (e) {
|
|
94
|
+
// SDK 错误处理自身不能再抛异常,避免死循环
|
|
95
|
+
logger.warn('Failed to handle unhandled rejection:', e);
|
|
68
96
|
}
|
|
69
97
|
|
|
70
|
-
// JavaScript 运行时错误
|
|
71
|
-
var message = errorEvent.message,
|
|
72
|
-
filename = errorEvent.filename,
|
|
73
|
-
lineno = errorEvent.lineno,
|
|
74
|
-
colno = errorEvent.colno,
|
|
75
|
-
error = errorEvent.error;
|
|
76
|
-
var errorData = {
|
|
77
|
-
type: 'JS_ERROR',
|
|
78
|
-
message: message,
|
|
79
|
-
file: filename,
|
|
80
|
-
line: lineno,
|
|
81
|
-
column: colno,
|
|
82
|
-
stack: error === null || error === void 0 ? void 0 : error.stack,
|
|
83
|
-
userAgent: navigator.userAgent,
|
|
84
|
-
timestamp: Date.now(),
|
|
85
|
-
location: window.location.href
|
|
86
|
-
};
|
|
87
|
-
sendErrorToAnalytics(errorData);
|
|
88
|
-
|
|
89
98
|
// 控制台保留原始错误显示
|
|
90
99
|
return false;
|
|
91
100
|
}
|
|
@@ -94,22 +103,26 @@ function handleError(event) {
|
|
|
94
103
|
* 未处理的 Promise 错误处理
|
|
95
104
|
*/
|
|
96
105
|
function handleUnhandledRejection(event) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
106
|
+
try {
|
|
107
|
+
var rejectionEvent = event;
|
|
108
|
+
var reason = rejectionEvent.reason || 'Unknown rejection';
|
|
109
|
+
var errorData = {
|
|
110
|
+
type: 'PROMISE_REJECTION',
|
|
111
|
+
message: typeof reason === 'string' ? reason : reason.message,
|
|
112
|
+
stack: _typeof(reason) === 'object' ? reason.stack : null,
|
|
113
|
+
timestamp: Date.now(),
|
|
114
|
+
location: window.location.href
|
|
115
|
+
};
|
|
116
|
+
sendErrorToAnalytics(errorData);
|
|
117
|
+
} catch (e) {
|
|
118
|
+
// SDK 错误处理自身不能再抛异常,避免死循环
|
|
119
|
+
logger.warn('Failed to handle unhandled rejection:', e);
|
|
120
|
+
}
|
|
107
121
|
}
|
|
108
122
|
|
|
109
123
|
// 初始化错误处理
|
|
110
124
|
export function initErrorHandler() {
|
|
111
125
|
if (isInitialized) return;
|
|
112
|
-
logger.log('Error handling is enabled');
|
|
113
126
|
window.addEventListener('error', handleError, true);
|
|
114
127
|
window.addEventListener('unhandledrejection', handleUnhandledRejection);
|
|
115
128
|
isInitialized = true;
|
|
@@ -118,9 +131,7 @@ export function initErrorHandler() {
|
|
|
118
131
|
// 清理错误监听器
|
|
119
132
|
export function cleanupErrorHandler() {
|
|
120
133
|
if (!isInitialized) return;
|
|
121
|
-
logger.log('Cleaning up error handlers');
|
|
122
134
|
window.removeEventListener('error', handleError, true);
|
|
123
135
|
window.removeEventListener('unhandledrejection', handleUnhandledRejection);
|
|
124
136
|
isInitialized = false;
|
|
125
|
-
logger.log('Error handlers cleaned up successfully');
|
|
126
137
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../src/lib/init.ts"],"names":[],"mappings":"AAsBA;;;;GAIG;AACH,wBAAgB,UAAU,CACxB,OAAO,GAAE;IAAE,SAAS,CAAC,EAAE,OAAO,CAAA;CAAO,EACrC,OAAO,GAAE,MAAuB,GAC/B,IAAI,CA2DN;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAEvC;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CACtB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,YAAY,CAAC,EAAE,MAAM,GACpB,IAAI,
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../src/lib/init.ts"],"names":[],"mappings":"AAsBA;;;;GAIG;AACH,wBAAgB,UAAU,CACxB,OAAO,GAAE;IAAE,SAAS,CAAC,EAAE,OAAO,CAAA;CAAO,EACrC,OAAO,GAAE,MAAuB,GAC/B,IAAI,CA2DN;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAEvC;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CACtB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,YAAY,CAAC,EAAE,MAAM,GACpB,IAAI,CAwGN"}
|
package/dist/esm/lib/init.js
CHANGED
|
@@ -107,7 +107,11 @@ export function initRLog(serv, appId, cdnConfigUrl) {
|
|
|
107
107
|
|
|
108
108
|
// 清理过期的 session 数据(异步,不阻塞初始化)
|
|
109
109
|
setTimeout(function () {
|
|
110
|
-
|
|
110
|
+
try {
|
|
111
|
+
cleanupStaleSessions();
|
|
112
|
+
} catch (error) {
|
|
113
|
+
logger.warn('Failed to cleanup stale sessions:', error);
|
|
114
|
+
}
|
|
111
115
|
}, 0);
|
|
112
116
|
|
|
113
117
|
// 设置SDK日志上报接口地址,并自动加入黑名单避免循环上报
|
|
@@ -124,17 +128,14 @@ export function initRLog(serv, appId, cdnConfigUrl) {
|
|
|
124
128
|
// 获取配置
|
|
125
129
|
config = getConfig(); // 检查采集总开关
|
|
126
130
|
if (config.enable) {
|
|
127
|
-
_context.next =
|
|
131
|
+
_context.next = 3;
|
|
128
132
|
break;
|
|
129
133
|
}
|
|
130
|
-
logger.log('SDK is disabled by config');
|
|
131
134
|
return _context.abrupt("return");
|
|
132
|
-
case
|
|
135
|
+
case 3:
|
|
133
136
|
isErrorMode = config.captureMode === 'error';
|
|
134
137
|
if (isErrorMode) {
|
|
135
138
|
// ===== 错误采集模式初始化 =====
|
|
136
|
-
logger.log('Initializing in error capture mode');
|
|
137
|
-
|
|
138
139
|
// 创建 ErrorTrigger 实例(只负责状态切换)
|
|
139
140
|
errorTriggerInstance = new ErrorTrigger({
|
|
140
141
|
beforeDuration: (_config$errorCapture = config.errorCapture) === null || _config$errorCapture === void 0 ? void 0 : _config$errorCapture.beforeDuration,
|
|
@@ -147,16 +148,32 @@ export function initRLog(serv, appId, cdnConfigUrl) {
|
|
|
147
148
|
}
|
|
148
149
|
|
|
149
150
|
// 启动录制(事件将写入 Storage)
|
|
150
|
-
|
|
151
|
+
try {
|
|
152
|
+
startRecord();
|
|
153
|
+
} catch (error) {
|
|
154
|
+
logger.error('Failed to start recording:', error);
|
|
155
|
+
}
|
|
151
156
|
|
|
152
157
|
// 在启动上传循环前,先将孤儿 session 的残留数据塞入当前 storage 队列头部
|
|
153
158
|
// 确保上传循环启动时这些数据已经就位,会被优先消费上传
|
|
159
|
+
_context.prev = 6;
|
|
154
160
|
_context.next = 9;
|
|
155
161
|
return flushOrphanSessions();
|
|
156
162
|
case 9:
|
|
163
|
+
_context.next = 14;
|
|
164
|
+
break;
|
|
165
|
+
case 11:
|
|
166
|
+
_context.prev = 11;
|
|
167
|
+
_context.t0 = _context["catch"](6);
|
|
168
|
+
logger.warn('Failed to flush orphan sessions:', _context.t0);
|
|
169
|
+
case 14:
|
|
157
170
|
// 注入取消回调(解除 uploader/worker-manager → init 的循环依赖)
|
|
158
171
|
cancelCallback = function cancelCallback() {
|
|
159
|
-
|
|
172
|
+
try {
|
|
173
|
+
cancelRlog({}, 'upload failure');
|
|
174
|
+
} catch (error) {
|
|
175
|
+
logger.error('Failed to cancel SDK via upload failure callback:', error);
|
|
176
|
+
}
|
|
160
177
|
};
|
|
161
178
|
setCancelCallback(cancelCallback);
|
|
162
179
|
setWorkerCancelCallback(cancelCallback);
|
|
@@ -164,25 +181,36 @@ export function initRLog(serv, appId, cdnConfigUrl) {
|
|
|
164
181
|
// 启动统一上传循环
|
|
165
182
|
// 错误模式下:idle 时跳过上传,uploading 时上传,状态由 ErrorTrigger 控制
|
|
166
183
|
// 全量模式下:持续轮询上传
|
|
167
|
-
|
|
184
|
+
try {
|
|
185
|
+
startUploadLoop(normalizedServUrl, appId);
|
|
186
|
+
} catch (error) {
|
|
187
|
+
logger.error('Failed to start upload loop:', error);
|
|
188
|
+
}
|
|
168
189
|
|
|
169
190
|
// 初始化路由监控
|
|
170
|
-
|
|
191
|
+
try {
|
|
192
|
+
initRouterMonitor(config.routerMonitor);
|
|
193
|
+
} catch (error) {
|
|
194
|
+
logger.warn('Failed to initialize router monitor:', error);
|
|
195
|
+
}
|
|
171
196
|
|
|
172
197
|
// 判断是否启用错误监听上报:
|
|
173
198
|
// 1. 错误采集模式下强制启用(错误捕获模式必须依赖错误监听初始化)
|
|
174
199
|
// 2. 非错误模式下,根据用户 error 配置决定,默认不启用
|
|
175
200
|
enableError = isErrorMode || ((_config$error = config.error) !== null && _config$error !== void 0 ? _config$error : false);
|
|
176
201
|
if (enableError) {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
202
|
+
try {
|
|
203
|
+
initErrorHandler();
|
|
204
|
+
} catch (error) {
|
|
205
|
+
logger.warn('Failed to initialize error handler:', error);
|
|
206
|
+
}
|
|
180
207
|
}
|
|
181
|
-
|
|
208
|
+
logger.log('Initialized successfully');
|
|
209
|
+
case 22:
|
|
182
210
|
case "end":
|
|
183
211
|
return _context.stop();
|
|
184
212
|
}
|
|
185
|
-
}, _callee);
|
|
213
|
+
}, _callee, null, [[6, 11]]);
|
|
186
214
|
}))).catch(function (error) {
|
|
187
215
|
logger.error('Failed to initialize SDK', error);
|
|
188
216
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"net.d.ts","sourceRoot":"","sources":["../../../src/lib/net.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAc/C;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI,GAAG,IAAI,CAErE;AAmBD,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAmBhD;AAwED,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAgBpD;AAiCD,wBAAgB,QAAQ,CAAC,CAAC,EAAE,OAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"net.d.ts","sourceRoot":"","sources":["../../../src/lib/net.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAc/C;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI,GAAG,IAAI,CAErE;AAmBD,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAmBhD;AAwED,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAgBpD;AAiCD,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