Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
1 line
3.9 KiB
Plaintext
1 line
3.9 KiB
Plaintext
{"version":3,"file":"onFCP.js","sources":["../../../../src/metrics/web-vitals/onFCP.ts"],"sourcesContent":["/*\n * Copyright 2020 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { bindReporter } from './lib/bindReporter';\nimport { getActivationStart } from './lib/getActivationStart';\nimport { getVisibilityWatcher } from './lib/getVisibilityWatcher';\nimport { initMetric } from './lib/initMetric';\nimport { observe } from './lib/observe';\nimport { whenActivated } from './lib/whenActivated';\nimport type { FCPMetric, MetricRatingThresholds, ReportOpts } from './types';\n\n/** Thresholds for FCP. See https://web.dev/articles/fcp#what_is_a_good_fcp_score */\nexport const FCPThresholds: MetricRatingThresholds = [1800, 3000];\n\n/**\n * Calculates the [FCP](https://web.dev/articles/fcp) value for the current page and\n * calls the `callback` function once the value is ready, along with the\n * relevant `paint` performance entry used to determine the value. The reported\n * value is a `DOMHighResTimeStamp`.\n */\nexport const onFCP = (onReport: (metric: FCPMetric) => void, opts: ReportOpts = {}) => {\n whenActivated(() => {\n const visibilityWatcher = getVisibilityWatcher();\n const metric = initMetric('FCP');\n let report: ReturnType<typeof bindReporter>;\n\n const handleEntries = (entries: FCPMetric['entries']) => {\n for (const entry of entries) {\n if (entry.name === 'first-contentful-paint') {\n po!.disconnect();\n\n // Only report if the page wasn't hidden prior to the first paint.\n if (entry.startTime < visibilityWatcher.firstHiddenTime) {\n // The activationStart reference is used because FCP should be\n // relative to page activation rather than navigation start if the\n // page was prerendered. But in cases where `activationStart` occurs\n // after the FCP, this time should be clamped at 0.\n metric.value = Math.max(entry.startTime - getActivationStart(), 0);\n metric.entries.push(entry);\n report(true);\n }\n }\n }\n };\n\n const po = observe('paint', handleEntries);\n\n if (po) {\n report = bindReporter(onReport, metric, FCPThresholds, opts.reportAllChanges);\n }\n });\n};\n"],"names":["whenActivated","getVisibilityWatcher","initMetric","getActivationStart","observe","bindReporter"],"mappings":";;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AAUA;AACO,MAAM,aAAa,GAA2B,CAAC,IAAI,EAAE,IAAI;;AAEhE;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,KAAA,GAAQ,CAAC,QAAQ,EAA+B,IAAI,GAAe,EAAE,KAAK;AACvF,EAAEA,2BAAa,CAAC,MAAM;AACtB,IAAI,MAAM,iBAAA,GAAoBC,yCAAoB,EAAE;AACpD,IAAI,MAAM,MAAA,GAASC,qBAAU,CAAC,KAAK,CAAC;AACpC,IAAI,IAAI,MAAM;;AAEd,IAAI,MAAM,aAAA,GAAgB,CAAC,OAAO,KAA2B;AAC7D,MAAM,KAAK,MAAM,KAAA,IAAS,OAAO,EAAE;AACnC,QAAQ,IAAI,KAAK,CAAC,IAAA,KAAS,wBAAwB,EAAE;AACrD,UAAU,EAAE,CAAE,UAAU,EAAE;;AAE1B;AACA,UAAU,IAAI,KAAK,CAAC,YAAY,iBAAiB,CAAC,eAAe,EAAE;AACnE;AACA;AACA;AACA;AACA,YAAY,MAAM,CAAC,KAAA,GAAQ,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,YAAYC,qCAAkB,EAAE,EAAE,CAAC,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