From 7ab0cfacc36c9802effbcf5bce31f57282742cec Mon Sep 17 00:00:00 2001 From: zizi Date: Thu, 11 Jun 2026 02:41:30 +0000 Subject: [PATCH] =?UTF-8?q?feat(qa):=20=E6=8E=A2=E9=92=88v3=E2=80=94?= =?UTF-8?q?=E2=80=94contentWindow=E8=AF=BB=E5=8F=96=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E7=BA=BF+=E5=85=83=E7=B4=A0=E4=BB=A3=E9=99=85=E7=BC=96?= =?UTF-8?q?=E5=8F=B7=E9=94=81=E7=9C=9F=E5=87=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Fable 5 --- .../orchestrator/probe_bridge_channel.py | 58 +++++++++++++------ 1 file changed, 41 insertions(+), 17 deletions(-) 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); } } })(); """