@aiyiran/myclaw 1.1.145 → 1.1.148

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.
@@ -19,7 +19,7 @@
19
19
 
20
20
  window.__OPENCLAW_DEBUG_PROBE_INSTALLED__ = true;
21
21
 
22
- const PROBE_VERSION = "probe_001";
22
+ const PROBE_VERSION = "probe_002";
23
23
  const MAX_TEXT_LENGTH = 1000;
24
24
  const MAX_STACK_LENGTH = 3000;
25
25
  const MAX_ELEMENT_TEXT_LENGTH = 80;
@@ -227,6 +227,66 @@
227
227
  });
228
228
  }
229
229
 
230
+ // 去重:避免 setTimeout 拦截 和 window.error 事件 重复上报同一个错误
231
+ const _reportedErrorKeys = new Set();
232
+
233
+ function reportRuntimeError(message, filename, lineno, colno, stack) {
234
+ const key = truncate(message, 200);
235
+ if (_reportedErrorKeys.has(key)) return;
236
+ _reportedErrorKeys.add(key);
237
+ sendEvent("runtime-error", {
238
+ message: truncate(message || "Unknown runtime error", MAX_TEXT_LENGTH),
239
+ filename: filename || "",
240
+ lineno: lineno || null,
241
+ colno: colno || null,
242
+ stack: truncate(stack || "", MAX_STACK_LENGTH)
243
+ });
244
+ }
245
+
246
+ // 拦截 setTimeout / setInterval,捕获回调里的同步异常
247
+ function setupAsyncErrorCapture() {
248
+ const _origSetTimeout = window.setTimeout;
249
+ const _origSetInterval = window.setInterval;
250
+
251
+ window.setTimeout = function (fn, delay) {
252
+ const args = Array.prototype.slice.call(arguments, 2);
253
+ if (typeof fn !== "function") return _origSetTimeout.apply(window, arguments);
254
+ return _origSetTimeout.call(window, function () {
255
+ try {
256
+ fn.apply(this, args);
257
+ } catch (e) {
258
+ reportRuntimeError(
259
+ e && e.message ? e.message : String(e),
260
+ e && e.fileName ? e.fileName : "",
261
+ e && e.lineNumber ? e.lineNumber : null,
262
+ e && e.columnNumber ? e.columnNumber : null,
263
+ e && e.stack ? e.stack : ""
264
+ );
265
+ throw e;
266
+ }
267
+ }, delay);
268
+ };
269
+
270
+ window.setInterval = function (fn, delay) {
271
+ const args = Array.prototype.slice.call(arguments, 2);
272
+ if (typeof fn !== "function") return _origSetInterval.apply(window, arguments);
273
+ return _origSetInterval.call(window, function () {
274
+ try {
275
+ fn.apply(this, args);
276
+ } catch (e) {
277
+ reportRuntimeError(
278
+ e && e.message ? e.message : String(e),
279
+ e && e.fileName ? e.fileName : "",
280
+ e && e.lineNumber ? e.lineNumber : null,
281
+ e && e.columnNumber ? e.columnNumber : null,
282
+ e && e.stack ? e.stack : ""
283
+ );
284
+ throw e;
285
+ }
286
+ }, delay);
287
+ };
288
+ }
289
+
230
290
  function setupRuntimeErrorListener() {
231
291
  window.addEventListener(
232
292
  "error",
@@ -249,19 +309,14 @@
249
309
  return;
250
310
  }
251
311
 
252
- // JS 运行时报错
253
- sendEvent("runtime-error", {
254
- message: truncate(event.message || "Unknown runtime error", MAX_TEXT_LENGTH),
255
- filename: event.filename || "",
256
- lineno: event.lineno || null,
257
- colno: event.colno || null,
258
- stack: truncate(
259
- event.error && event.error.stack
260
- ? event.error.stack
261
- : "",
262
- MAX_STACK_LENGTH
263
- )
264
- });
312
+ // JS 运行时报错(兜底,可能已被 setTimeout 拦截器上报)
313
+ reportRuntimeError(
314
+ event.message,
315
+ event.filename,
316
+ event.lineno,
317
+ event.colno,
318
+ event.error && event.error.stack ? event.error.stack : ""
319
+ );
265
320
  },
266
321
  true
267
322
  );
@@ -289,6 +344,7 @@
289
344
  }
290
345
 
291
346
  function init() {
347
+ setupAsyncErrorCapture();
292
348
  setupConsoleListener();
293
349
  setupRuntimeErrorListener();
294
350
  setupUnhandledRejectionListener();
@@ -1173,7 +1173,8 @@
1173
1173
  iframe.focus();
1174
1174
  // HTML 作品已由服务端注入 debug probe,挂上调试记录收集器开始录制。
1175
1175
  // 其余类型(图片/视频/PDF…)不录制。collector 不存在时静默跳过。
1176
- if (isHtml && typeof window.startDebugRecord === 'function') {
1176
+ var isDebugFile = asset.path && asset.path.replace(/\\/g, '/').indexOf('debug/') === 0;
1177
+ if (isHtml && !isDebugFile && typeof window.startDebugRecord === 'function') {
1177
1178
  var debugContext = {
1178
1179
  claw: lastKnownClawName,
1179
1180
  workspace: getWorkspaceId(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiyiran/myclaw",
3
- "version": "1.1.145",
3
+ "version": "1.1.148",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {