index.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * FeHelper Wpo Tools
  3. */
  4. new Vue({
  5. el: '#pageContainer',
  6. data: {
  7. pageTitle: '无',
  8. pageUrl: '无',
  9. timing: null,
  10. headerInfo: null,
  11. tmDefination: {
  12. lookupDomainTime: 'DNS查询耗时',
  13. connectTime: 'TCP连接耗时',
  14. requestTime: '网络请求耗时',
  15. firstPaintTime: '白屏时间',
  16. readyStart: '构建文档流耗时',
  17. domReadyTime: 'DOM树构建耗时',
  18. redirectTime: '重定向耗时',
  19. appcacheTime: '数据缓存耗时',
  20. unloadEventTime: '卸载文档耗时',
  21. initDomTreeTime: '请求完成到可交互',
  22. loadEventTime: '加载事件耗时',
  23. loadTime: '加载总耗时'
  24. }
  25. },
  26. mounted: function () {
  27. // 在tab创建或者更新时候,监听事件,看看是否有参数传递过来
  28. if (location.protocol === 'chrome-extension:') {
  29. chrome.tabs.query({currentWindow: true,active: true, }, (tabs) => {
  30. let activeTab = tabs.filter(tab => tab.active)[0];
  31. chrome.runtime.sendMessage({
  32. type: 'fh-dynamic-any-thing',
  33. thing: 'request-page-content',
  34. tabId: activeTab.id
  35. }).then(resp => {
  36. console.log(resp)
  37. if(!resp && !resp.content) return ;
  38. sessionStorage.setItem('wpo-data', JSON.stringify(resp.content));
  39. this.showTiming(resp.content);
  40. });
  41. });
  42. }
  43. let wpo = JSON.parse(sessionStorage.getItem('wpo-data'));
  44. wpo && this.showTiming(wpo);
  45. },
  46. methods: {
  47. showTiming(wpo) {
  48. this.pageTitle = wpo.pageInfo.title || "无";
  49. this.pageUrl = wpo.pageInfo.url || "无";
  50. this.timing = wpo.time;
  51. this.headerInfo = wpo.header;
  52. },
  53. }
  54. });