@shopify/performance
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -10,2 +10,8 @@ # Changelog | ||
## [1.0.3] - 2019-01-11 | ||
### Fixed | ||
- Fixed an issue where browsers supporting some custom timing types (but not `PerformanceObserver`) would throw while trying to create an instance of `PerformanceObserver` | ||
## [1.0.2] - 2019-01-11 | ||
@@ -12,0 +18,0 @@ |
@@ -9,2 +9,3 @@ import { Navigation } from './navigation'; | ||
export declare class Performance { | ||
readonly supportsObserver: boolean; | ||
readonly supportsMarks: boolean; | ||
@@ -11,0 +12,0 @@ readonly supportsNavigationEntries: boolean; |
@@ -12,2 +12,3 @@ "use strict"; | ||
var _this = this; | ||
this.supportsObserver = utilities_1.hasGlobal('PerformanceObserver'); | ||
this.supportsMarks = utilities_1.hasGlobal('PerformanceMark'); | ||
@@ -14,0 +15,0 @@ this.supportsNavigationEntries = utilities_1.hasGlobal('PerformanceNavigationTiming'); |
@@ -21,11 +21,22 @@ "use strict"; | ||
function withEntriesOfType(type, handler) { | ||
var initialEntries = performance.getEntriesByType(type); | ||
initialEntries.forEach(function (entry) { return handler(entry); }); | ||
var observer = new PerformanceObserver(function (entries) { | ||
entries.getEntriesByType(type).forEach(function (entry) { return handler(entry); }); | ||
}); | ||
observer.observe({ | ||
entryTypes: [type], | ||
buffered: true, | ||
}); | ||
try { | ||
var initialEntries = performance.getEntriesByType(type); | ||
initialEntries.forEach(function (entry) { return handler(entry); }); | ||
if (!hasGlobal('PerformanceObserver')) { | ||
return; | ||
} | ||
var observer = new PerformanceObserver(function (entries) { | ||
entries.getEntriesByType(type).forEach(function (entry) { return handler(entry); }); | ||
}); | ||
observer.observe({ | ||
entryTypes: [type], | ||
buffered: true, | ||
}); | ||
} | ||
catch (error) { | ||
// Browser support here is weird. Some browsers support getting | ||
// the initial entries, but don't support performance observers. | ||
// Some throw errors when invalid types are passed, others don't. | ||
// We're being very protective here, but I think it's the only way. | ||
} | ||
} | ||
@@ -32,0 +43,0 @@ exports.withEntriesOfType = withEntriesOfType; |
{ | ||
"name": "@shopify/performance", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "description": "Primitives for collecting browser performance metrics.", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
40148
854