任何适合HTML5 Javascript postMessage API的调试器?

有没有什么好的工具,允许开发人员正确地调试窗口与 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代码注入到页面中.您可以添加以下代码以在页面加载后监视事件.它工作得很好,尽管它可能会错过立即发生的事件(例如在上载之前,如果可能的话).

(function($) {
    var $window = $(window);
    $window.add("iframe").on("message",function(e) {
        console.log("Received messsage from " + e.originalEvent.origin + ",data = " + e.originalEvent.data);
    });
})(jQuery);

相关文章

HTML5和CSS3实现3D展示商品信息的代码
利用HTML5中的Canvas绘制笑脸的代码
Html5剪切板功能的实现
如何通过HTML5触摸事件实现移动端简易进度条
Html5移动端获奖无缝滚动动画实现
关于HTML5和CSS3实现机器猫的代码