Skip to content
This repository has been archived by the owner on Aug 10, 2023. It is now read-only.

Commit

Permalink
Add some backwards compatibility for older browsers (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
omrilotan authored Jan 17, 2021
1 parent e40a64e commit c632b42
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 12 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "page-timing",
"version": "3.1.0",
"version": "3.1.1",
"description": "⏱ Collect and measure browser performance metrics",
"keywords": [
"browser",
Expand Down Expand Up @@ -39,7 +39,7 @@
"@lets/wait": "^2.0.2",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"eslint": "^7.17.0",
"eslint": "^7.18.0",
"eslint-plugin-log": "^1.2.7",
"karma": "^6.0.0",
"karma-chrome-launcher": "^3.1.0",
Expand All @@ -50,6 +50,6 @@
"regenerator-runtime": "^0.13.7",
"tti-polyfill": "^0.2.2",
"web-vitals": "^1.1.0",
"webpack": "^5.14.0"
"webpack": "^5.15.0"
}
}
2 changes: 1 addition & 1 deletion play/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ window.addEventListener(

TTI.getFirstConsistentlyInteractive().then((result) => {
console.log('tti', performance.now());
window.performance_information.time_to_interactive = result;
window.performance_information.time_to_interactive = result || undefined;
print();
}).catch(console.error);

Expand Down
4 changes: 2 additions & 2 deletions src/assets/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getEntries } from '../getEntries/index.js';
import { getType } from '../get-type/index.js';
import { number } from '../number/index.js';
import { number, isNaN } from '../number/index.js';

const FINAL_ASSET_PREFIX = 'final_asset';

Expand All @@ -23,7 +23,7 @@ export async function assets() {
}

for (const key in metrics) {
if (Number.isNaN(metrics[key])) {
if (isNaN(metrics[key])) {
metrics[key] = undefined;
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/elapsed/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { isFinite } from '../number/index.js';

export async function elapsed() {
const page_time_elapsed = window.performance.now();

return Number.isFinite(page_time_elapsed)
return isFinite(page_time_elapsed)
? { page_time_elapsed }
: {}
;
Expand Down
8 changes: 5 additions & 3 deletions src/getEntries/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ export const getEntries = (...entryTypes) => new Promise(
return;
}

const entries = entryTypes.map(
(entryType) => window.performance.getEntriesByType(entryType)
).flat();
const entries = [].concat(
...entryTypes.map(
(entryType) => window.performance.getEntriesByType(entryType)
)
);

if (entries.length) {
resolve(entries);
Expand Down
4 changes: 2 additions & 2 deletions src/navigation/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getEntries } from '../getEntries/index.js';
import { number } from '../number/index.js';
import { number, isNaN } from '../number/index.js';
import { snakeCase } from '../snake-case/index.js';

/**
Expand Down Expand Up @@ -49,7 +49,7 @@ export async function navigation() {
if (navigation) {
return Object.assign(
...METRICS.filter(
(metric) => !Number.isNaN(navigation[metric])
(metric) => !isNaN(navigation[metric])
).map(
(metric) => ({ [snakeCase(metric)]: number(navigation[metric]) })
)
Expand Down
5 changes: 5 additions & 0 deletions src/number/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,8 @@ export function number(input) {

return value;
}

export {
isNaN,
isFinite
};

0 comments on commit c632b42

Please sign in to comment.