diff --git a/docs/agent-specs/2026-06-09-agent-loop-v1/orchestrator/probe_bridge_channel.py b/docs/agent-specs/2026-06-09-agent-loop-v1/orchestrator/probe_bridge_channel.py index 3d53f34b..215eb19b 100644 --- a/docs/agent-specs/2026-06-09-agent-loop-v1/orchestrator/probe_bridge_channel.py +++ b/docs/agent-specs/2026-06-09-agent-loop-v1/orchestrator/probe_bridge_channel.py @@ -71,25 +71,49 @@ PROBE_JS = r""" var docId = Math.random().toString(36).slice(2, 8); window.__wxprobeDocId = docId; console.log('[WXPROBE] DOCBOOT@' + TAG + ' docId=' + docId + ' href=' + String(location.href).slice(0, 50)); - // 仅 TOP:监视 iframe 元素增删(元素重建会废弃旧 WindowProxy → 旧引用 postMessage 静默丢失) + // 仅 TOP:①iframe 元素增删监视(DOMContentLoaded 后装——document-start 时 documentElement 尚 null) + // ②contentWindow 读取监听:每次读取=应用侧(attachBridge 等)取代理的时刻; + // 给元素编号 eid,时间线可证「bridge 拿的是哪一代元素的代理」。 if (TAG === 'TOP') { - try { - new MutationObserver(function (muts) { - muts.forEach(function (mu) { - var scan = function (nodes, act) { - for (var i = 0; i < nodes.length; i++) { - var n = nodes[i]; - if (n && n.tagName === 'IFRAME') { console.log('[WXPROBE] IFRAME-' + act); } - else if (n && n.querySelectorAll) { - if (n.querySelectorAll('iframe').length) { console.log('[WXPROBE] IFRAME-' + act + '(嵌套)'); } + var installObserver = function () { + try { + new MutationObserver(function (muts) { + muts.forEach(function (mu) { + var scan = function (nodes, act) { + for (var i = 0; i < nodes.length; i++) { + var n = nodes[i]; + if (!n) continue; + if (n.tagName === 'IFRAME') { console.log('[WXPROBE] IFRAME-' + act + ' ' + (n.__wxeid || '未编号')); } + else if (n.querySelectorAll && n.querySelectorAll('iframe').length) { + var fs = n.querySelectorAll('iframe'); + for (var j = 0; j < fs.length; j++) { console.log('[WXPROBE] IFRAME-' + act + '(嵌套) ' + (fs[j].__wxeid || '未编号')); } + } } - } - }; - scan(mu.addedNodes || [], 'ADDED'); - scan(mu.removedNodes || [], 'REMOVED'); - }); - }).observe(document.documentElement, { childList: true, subtree: true }); - } catch (e) { } + }; + scan(mu.addedNodes || [], 'ADDED'); + scan(mu.removedNodes || [], 'REMOVED'); + }); + }).observe(document.documentElement, { childList: true, subtree: true }); + } catch (e) { console.log('[WXPROBE] 观察器安装失败: ' + e); } + }; + if (document.readyState === 'loading') { window.addEventListener('DOMContentLoaded', installObserver); } + else { installObserver(); } + try { + var desc = Object.getOwnPropertyDescriptor(HTMLIFrameElement.prototype, 'contentWindow'); + var eidSeq = 0; + Object.defineProperty(HTMLIFrameElement.prototype, 'contentWindow', { + configurable: true, + get: function () { + if (!this.__wxeid) { this.__wxeid = 'el' + (++eidSeq); } + var w = desc.get.call(this); + var docId = null; + try { docId = w && w.__wxprobeDocId || null; } catch (e) { } + console.log('[WXPROBE] CWGET ' + this.__wxeid + ' connected=' + this.isConnected + + ' null=' + (w === null) + ' docId=' + docId); + return w; + } + }); + } catch (e) { console.log('[WXPROBE] contentWindow 监听安装失败: ' + e); } } })(); """