@aiyiran/myclaw 1.1.148 → 1.1.152

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_002";
22
+ const PROBE_VERSION = "probe_003";
23
23
  const MAX_TEXT_LENGTH = 1000;
24
24
  const MAX_STACK_LENGTH = 3000;
25
25
  const MAX_ELEMENT_TEXT_LENGTH = 80;
@@ -135,6 +135,13 @@
135
135
  };
136
136
  }
137
137
 
138
+ const _isInIframe = (function () {
139
+ try { return window.parent !== window; } catch (e) { return false; }
140
+ })();
141
+
142
+ // 保存原始 console.log,防止 probe 覆盖后造成递归
143
+ const _nativeLog = console.log.bind(console);
144
+
138
145
  function sendEvent(type, payload) {
139
146
  const event = {
140
147
  type,
@@ -145,7 +152,7 @@
145
152
  };
146
153
 
147
154
  try {
148
- if (window.parent && window.parent !== window) {
155
+ if (_isInIframe) {
149
156
  window.parent.postMessage(
150
157
  {
151
158
  source: "OPENCLAW_DEBUG_PROBE",
@@ -154,6 +161,9 @@
154
161
  },
155
162
  "*"
156
163
  );
164
+ } else {
165
+ // 独立页面模式:直接打到控制台,方便本地调试
166
+ _nativeLog("[PROBE]", type, payload);
157
167
  }
158
168
  } catch (error) {
159
169
  // 不让 probe 影响学生作品运行
@@ -558,9 +558,6 @@
558
558
  } else if (rec.workspace) {
559
559
  lines.push("调试记录:" + rec.workspace + "/debug/debug-record.html");
560
560
  }
561
- if (rec.entryFile) {
562
- lines.push("正在调试的文件:" + rec.entryFile);
563
- }
564
561
  lines.push("");
565
562
  }
566
563
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiyiran/myclaw",
3
- "version": "1.1.148",
3
+ "version": "1.1.152",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -449,9 +449,15 @@ def inject_probe_into_html(html_bytes):
449
449
  )
450
450
 
451
451
  tag = f'<script {PROBE_MARKER_ATTR}="{version}">\n{src}\n</script>'
452
- idx = html.lower().rfind("</body>")
453
- if idx != -1:
454
- html = html[:idx] + tag + "\n" + html[idx:]
452
+ # 注入到 <body> 开头而非 </body> 前,确保 probe 在游戏脚本之前加载,
453
+ # 能捕获 init() 等同步执行阶段的报错。
454
+ body_open = html.lower().find("<body")
455
+ if body_open != -1:
456
+ body_tag_end = html.find(">", body_open)
457
+ if body_tag_end != -1:
458
+ html = html[:body_tag_end + 1] + "\n" + tag + html[body_tag_end + 1:]
459
+ else:
460
+ html = html + "\n" + tag
455
461
  else:
456
462
  html = html + "\n" + tag
457
463
  return html.encode("utf-8")