PerformanceObserver 在 Firefox 中抛出错误,在 Chrome 中工作

标签 performance pagespeed observers mutation-observers

我正在实现 PerformanceObserver 来跟踪“first-paint”和“first-contentful-paint”。

const observer = new PerformanceObserver((list) => {
  for (const entry of list.getEntries()) {
    if (typeof(Storage) !== 'undefined') {

      if (entry.name === 'first-paint') {
        localStorage.setItem(rumMetrics.RUM_METRICS_FIRST_PAINT, entry.startTime);
      }
      else if (entry.name === 'first-contentful-paint') {
        localStorage.setItem(rumMetrics.RUM_METRICS_FIRST_CONTENTFUL_PAINT, entry.startTime);
      }
    }
    else {
      console.log('local storage is not supported here. RUM metrics won\'t be recorded.');
    }
  }
});

observer.observe({ entryTypes: ['paint'] });

这在 Chrome 中完美运行,但在 Firefox 中会引发错误

TypeError: The expression cannot be converted to return the specified type. (line: observer.observe({ entryTypes: ['paint'] });)

最佳答案

更新 1:2018 年 4 月 20 日

Mozilla 已确认该错误,并且它也影响 FF61 Nightly

Confirmed

原始答案

确认即使在开发者版本中这也是一个错误。

FF Deve

Bug

下面是相同的错误

https://bugzilla.mozilla.org/show_bug.cgi?id=1454581

关于PerformanceObserver 在 Firefox 中抛出错误,在 Chrome 中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49790138/

相关文章:

android - findViewById 的效率

javascript - 仅使用 JavaScript 延迟图像并不能消除 PageSpeed 警告

html - 将 CSS 放入文档头部但我没有头部?

脚本运行时的 php 垃圾回收

c# - 在 C# 中存储矩阵值的快速且有用的方法

r - 加速计算每列 3 元组的行中位数

ruby-on-rails - 无法摆脱 Google 的 pagespeed 洞察警告(该网站有一个阻止 css)

C++ 自己的观察者模式

java - 如何在不持有线程的情况下通知所有观察者?

swift - 如何在不打印两次数据的情况下重新加载 UITableView?