feat(qa): 探针v3——contentWindow读取时间线+元素代际编号锁真凶

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
zizi 2026-06-11 02:41:30 +00:00
parent 47f9f48a98
commit 7ab0cfacc3

View File

@ -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 静默丢失
// TOPiframe 元素增删监视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); }
}
})();
"""