我正在实现 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
原始答案
确认即使在开发者版本中这也是一个错误。
下面是相同的错误
关于PerformanceObserver 在 Firefox 中抛出错误,在 Chrome 中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49790138/