<分区>
是否有任何好的工具可以让开发人员正确调试使用 postMessage 在窗口之间发送的消息? ?
或者可能是 Firebug 的插件?
最佳答案
Firebug (as of 1.11 beta 1)通过 monitorEvents()
支持这一点。你可以这样做:
$("iframe").each(function(i, e) {
console.log("Monitoring messages sent to: iframe(" + i + ")#" + $(this).attr("id"));
monitorEvents(this.contentWindow, "message");
// Send a test message to this iframe
this.contentWindow.postMessage("Hi iframe - " + i, "*");
});
console.log("Monitoring messages sent to window");
monitorEvents(window, "message");
// Send a test message to the window
window.postMessage("Hi window", "*");
(@Pierre:感谢您提到 feature request )
编辑: Also works in Chrome , 虽然当我尝试上面的代码时遇到了 document.domain
值不相同的安全错误,因此这两个实现的行为可能略有不同。
更新:我有 submitted a feature request向 Chrome 团队询问 postMessage 事件是否出现在时间轴中。另外,我发现了一个 extension called JScript Tricks它可以在页面加载时将任意 JavaScript 代码注入(inject)页面。您可以向其中添加以下代码以在页面加载后监视事件。它工作得很好,尽管它可能会错过立即发生的事件(例如,在加载之前,如果可能的话)。
(function($) {
var $window = $(window);
$window.add("iframe").on("message", function(e) {
console.log("Received messsage from " + e.originalEvent.origin + ", data = " + e.originalEvent.data);
});
})(jQuery);
关于javascript - 任何好的 HTML5 Javascript postMessage API 调试器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3053809/