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

前端之家收集整理的这篇文章主要介绍了任何适合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);
原文链接:https://www.f2er.com/html5/168686.html

猜你在找的HTML5相关文章