firefox addon sdk:获取页面加载时间

firefox addon sdk: get page load time

使用此 Firefox Addon SDK 示例时:

var tabs = require("sdk/tabs");
tabs.open({
  url: "http://www.example.com",
  onReady: runScript
});

function runScript(tab) {
  tab.attach({
    contentScript: "document.body.style.border = '5px solid red';"
  });
  console.log(tab.title);
}

如何获取页面加载时间并将其打印到控制台?

(就像 app.telemetry 插件一样 - http://www.apptelemetry.com/de/page-speed-monitor.html

只需使用Navigation Timing API:

window.onload = function(){
  setTimeout(function(){
    var t = performance.timing;
    console.log(t.loadEventEnd - t.responseEnd);
  }, 0);
}

请注意,它是一个 Javascript API,因此它必须 运行 在 Content Script 中(即,它不会在你的 lib/main 中工作。 js 或 index.js 文件)。