@@ -176,11 +176,15 @@ export const wsClientCode = `
176176
177177 /** 通过 HTTP POST 发送执行结果(失败自动重试一次,确保 CLI 不超时) */
178178 function postResult(result) {
179+ console.log('[Pilot] postResult sending, success=' + result.success + ', instance=' + __pilot_instanceId);
179180 fetch(apiUrl('/__pilot/result'), {
180181 method: 'POST',
181182 headers: { 'Content-Type': 'application/json', 'X-Pilot-Instance': __pilot_instanceId, 'X-Pilot-Title': document.title || '' },
182183 body: JSON.stringify(result)
183- }).catch(function() {
184+ }).then(function(resp) {
185+ console.log('[Pilot] postResult response status=' + resp.status);
186+ }).catch(function(err) {
187+ console.log('[Pilot] postResult failed, retrying in 200ms: ' + err.message);
184188 /** 后台 tab 或网络抖动导致首次失败时,200ms 后重试一次 */
185189 setTimeout(function() {
186190 fetch(apiUrl('/__pilot/result'), {
@@ -204,21 +208,27 @@ export const wsClientCode = `
204208
205209 /** 执行代码并发送结果的通用处理 */
206210 function handleCode(code) {
211+ console.log('[Pilot] handleCode received, isExecuting=' + isExecuting + ', code=' + code.slice(0, 40));
207212 if (isExecuting) {
208213 pendingCode = code;
214+ console.log('[Pilot] handleCode queued (already executing)');
209215 return;
210216 }
211217 isExecuting = true;
218+ console.log('[Pilot] execCode starting...');
212219 var result = execCode(code);
220+ console.log('[Pilot] execCode done, typeof result=' + typeof result + ', isPromise=' + (result && typeof result.then === 'function'));
213221 /** 等待 Vue nextTick + 浏览器渲染后再采集 snapshot,确保 DOM 已更新
214222 * 后台 tab 时 requestAnimationFrame 不触发,直接发送结果 */
215223 function sendWithSnapshot(result) {
216224 /** 安全采集 snapshot,出错时不阻塞结果发送 */
217225 function safeSnapshot() {
218226 try { return window.__pilot_snapshot ? window.__pilot_snapshot() : undefined; } catch(e) { return undefined; }
219227 }
228+ console.log('[Pilot] sendWithSnapshot, hidden=' + document.hidden + ', hasSnapshot=' + !!window.__pilot_snapshot);
220229 if (window.__pilot_snapshot && !document.hidden) {
221230 requestAnimationFrame(function() {
231+ console.log('[Pilot] rAF callback, sending result');
222232 result.snapshot = safeSnapshot();
223233 sendResult(result);
224234 /** exec 完成,检查是否有排队的代码需要执行 */
@@ -228,12 +238,14 @@ export const wsClientCode = `
228238 } else if (window.__pilot_snapshot) {
229239 /** 后台 tab 时 rAF 不触发,用 setTimeout 兜底确保 snapshot 采集 */
230240 setTimeout(function() {
241+ console.log('[Pilot] setTimeout callback (background tab), sending result');
231242 result.snapshot = safeSnapshot();
232243 sendResult(result);
233244 isExecuting = false;
234245 if (pendingCode) { var next = pendingCode; pendingCode = null; handleCode(next); }
235246 }, 50);
236247 } else {
248+ console.log('[Pilot] no snapshot function, sending result directly');
237249 sendResult(result);
238250 isExecuting = false;
239251 if (pendingCode) { var next = pendingCode; pendingCode = null; handleCode(next); }
@@ -256,11 +268,13 @@ export const wsClientCode = `
256268 window.__pilot_es = es;
257269
258270 es.addEventListener('code', function(e) {
271+ console.log('[Pilot] SSE code event received, gen=' + myGen + ', data=' + e.data.slice(0, 40));
259272 if (myGen !== window.__pilot_gen) return;
260273 handleCode(e.data);
261274 });
262275
263276 es.addEventListener('reload', function() {
277+ console.log('[Pilot] SSE reload event received, bridge_active=' + !!window.__pilot_bridge_active);
264278 es.close();
265279 /** Console Bridge 模式下不 reload(控制台注入的代码会丢失) */
266280 if (!window.__pilot_bridge_active) {
0 commit comments