diff options
Diffstat (limited to 'shared/logger/node_modules/@sentry-internal/tracing/esm/browser/web-vitals/lib')
8 files changed, 306 insertions, 0 deletions
diff --git a/shared/logger/node_modules/@sentry-internal/tracing/esm/browser/web-vitals/lib/bindReporter.js b/shared/logger/node_modules/@sentry-internal/tracing/esm/browser/web-vitals/lib/bindReporter.js new file mode 100644 index 0000000..dc66278 --- /dev/null +++ b/shared/logger/node_modules/@sentry-internal/tracing/esm/browser/web-vitals/lib/bindReporter.js @@ -0,0 +1,28 @@ +const bindReporter = ( + callback, + metric, + reportAllChanges, +) => { + let prevValue; + let delta; + return (forceReport) => { + if (metric.value >= 0) { + if (forceReport || reportAllChanges) { + delta = metric.value - (prevValue || 0); + + // Report the metric if there's a non-zero delta or if no previous + // value exists (which can happen in the case of the document becoming + // hidden when the metric value is 0). + // See: https://github.com/GoogleChrome/web-vitals/issues/14 + if (delta || prevValue === undefined) { + prevValue = metric.value; + metric.delta = delta; + callback(metric); + } + } + } + }; +}; + +export { bindReporter }; +//# sourceMappingURL=bindReporter.js.map diff --git a/shared/logger/node_modules/@sentry-internal/tracing/esm/browser/web-vitals/lib/generateUniqueID.js b/shared/logger/node_modules/@sentry-internal/tracing/esm/browser/web-vitals/lib/generateUniqueID.js new file mode 100644 index 0000000..dfde3bb --- /dev/null +++ b/shared/logger/node_modules/@sentry-internal/tracing/esm/browser/web-vitals/lib/generateUniqueID.js @@ -0,0 +1,27 @@ +/* + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Performantly generate a unique, 30-char string by combining a version + * number, the current timestamp with a 13-digit number integer. + * @return {string} + */ +const generateUniqueID = () => { + return `v3-${Date.now()}-${Math.floor(Math.random() * (9e12 - 1)) + 1e12}`; +}; + +export { generateUniqueID }; +//# sourceMappingURL=generateUniqueID.js.map diff --git a/shared/logger/node_modules/@sentry-internal/tracing/esm/browser/web-vitals/lib/getActivationStart.js b/shared/logger/node_modules/@sentry-internal/tracing/esm/browser/web-vitals/lib/getActivationStart.js new file mode 100644 index 0000000..e7b7f65 --- /dev/null +++ b/shared/logger/node_modules/@sentry-internal/tracing/esm/browser/web-vitals/lib/getActivationStart.js @@ -0,0 +1,25 @@ +import { getNavigationEntry } from './getNavigationEntry.js'; + +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +const getActivationStart = () => { + const navEntry = getNavigationEntry(); + return (navEntry && navEntry.activationStart) || 0; +}; + +export { getActivationStart }; +//# sourceMappingURL=getActivationStart.js.map diff --git a/shared/logger/node_modules/@sentry-internal/tracing/esm/browser/web-vitals/lib/getNavigationEntry.js b/shared/logger/node_modules/@sentry-internal/tracing/esm/browser/web-vitals/lib/getNavigationEntry.js new file mode 100644 index 0000000..89a65a5 --- /dev/null +++ b/shared/logger/node_modules/@sentry-internal/tracing/esm/browser/web-vitals/lib/getNavigationEntry.js @@ -0,0 +1,53 @@ +import { WINDOW } from '../../types.js'; + +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +const getNavigationEntryFromPerformanceTiming = () => { + // eslint-disable-next-line deprecation/deprecation + const timing = WINDOW.performance.timing; + // eslint-disable-next-line deprecation/deprecation + const type = WINDOW.performance.navigation.type; + + const navigationEntry = { + entryType: 'navigation', + startTime: 0, + type: type == 2 ? 'back_forward' : type === 1 ? 'reload' : 'navigate', + }; + + for (const key in timing) { + if (key !== 'navigationStart' && key !== 'toJSON') { + // eslint-disable-next-line deprecation/deprecation + navigationEntry[key] = Math.max((timing[key ] ) - timing.navigationStart, 0); + } + } + return navigationEntry ; +}; + +const getNavigationEntry = () => { + if (WINDOW.__WEB_VITALS_POLYFILL__) { + return ( + WINDOW.performance && + ((performance.getEntriesByType && performance.getEntriesByType('navigation')[0]) || + getNavigationEntryFromPerformanceTiming()) + ); + } else { + return WINDOW.performance && performance.getEntriesByType && performance.getEntriesByType('navigation')[0]; + } +}; + +export { getNavigationEntry }; +//# sourceMappingURL=getNavigationEntry.js.map diff --git a/shared/logger/node_modules/@sentry-internal/tracing/esm/browser/web-vitals/lib/getVisibilityWatcher.js b/shared/logger/node_modules/@sentry-internal/tracing/esm/browser/web-vitals/lib/getVisibilityWatcher.js new file mode 100644 index 0000000..fb86cc2 --- /dev/null +++ b/shared/logger/node_modules/@sentry-internal/tracing/esm/browser/web-vitals/lib/getVisibilityWatcher.js @@ -0,0 +1,54 @@ +import { WINDOW } from '../../types.js'; +import { onHidden } from './onHidden.js'; + +/* + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +let firstHiddenTime = -1; + +const initHiddenTime = () => { + // If the document is hidden and not prerendering, assume it was always + // hidden and the page was loaded in the background. + return WINDOW.document.visibilityState === 'hidden' && !WINDOW.document.prerendering ? 0 : Infinity; +}; + +const trackChanges = () => { + // Update the time if/when the document becomes hidden. + onHidden(({ timeStamp }) => { + firstHiddenTime = timeStamp; + }, true); +}; + +const getVisibilityWatcher = ( + +) => { + if (firstHiddenTime < 0) { + // If the document is hidden when this code runs, assume it was hidden + // since navigation start. This isn't a perfect heuristic, but it's the + // best we can do until an API is available to support querying past + // visibilityState. + firstHiddenTime = initHiddenTime(); + trackChanges(); + } + return { + get firstHiddenTime() { + return firstHiddenTime; + }, + }; +}; + +export { getVisibilityWatcher }; +//# sourceMappingURL=getVisibilityWatcher.js.map diff --git a/shared/logger/node_modules/@sentry-internal/tracing/esm/browser/web-vitals/lib/initMetric.js b/shared/logger/node_modules/@sentry-internal/tracing/esm/browser/web-vitals/lib/initMetric.js new file mode 100644 index 0000000..498c63d --- /dev/null +++ b/shared/logger/node_modules/@sentry-internal/tracing/esm/browser/web-vitals/lib/initMetric.js @@ -0,0 +1,46 @@ +import { WINDOW } from '../../types.js'; +import { generateUniqueID } from './generateUniqueID.js'; +import { getActivationStart } from './getActivationStart.js'; +import { getNavigationEntry } from './getNavigationEntry.js'; + +/* + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +const initMetric = (name, value) => { + const navEntry = getNavigationEntry(); + let navigationType = 'navigate'; + + if (navEntry) { + if (WINDOW.document.prerendering || getActivationStart() > 0) { + navigationType = 'prerender'; + } else { + navigationType = navEntry.type.replace(/_/g, '-') ; + } + } + + return { + name, + value: typeof value === 'undefined' ? -1 : value, + rating: 'good', // Will be updated if the value changes. + delta: 0, + entries: [], + id: generateUniqueID(), + navigationType, + }; +}; + +export { initMetric }; +//# sourceMappingURL=initMetric.js.map diff --git a/shared/logger/node_modules/@sentry-internal/tracing/esm/browser/web-vitals/lib/observe.js b/shared/logger/node_modules/@sentry-internal/tracing/esm/browser/web-vitals/lib/observe.js new file mode 100644 index 0000000..94b7351 --- /dev/null +++ b/shared/logger/node_modules/@sentry-internal/tracing/esm/browser/web-vitals/lib/observe.js @@ -0,0 +1,37 @@ +/** + * Takes a performance entry type and a callback function, and creates a + * `PerformanceObserver` instance that will observe the specified entry type + * with buffering enabled and call the callback _for each entry_. + * + * This function also feature-detects entry support and wraps the logic in a + * try/catch to avoid errors in unsupporting browsers. + */ +const observe = ( + type, + callback, + opts, +) => { + try { + if (PerformanceObserver.supportedEntryTypes.includes(type)) { + const po = new PerformanceObserver(list => { + callback(list.getEntries() ); + }); + po.observe( + Object.assign( + { + type, + buffered: true, + }, + opts || {}, + ) , + ); + return po; + } + } catch (e) { + // Do nothing. + } + return; +}; + +export { observe }; +//# sourceMappingURL=observe.js.map diff --git a/shared/logger/node_modules/@sentry-internal/tracing/esm/browser/web-vitals/lib/onHidden.js b/shared/logger/node_modules/@sentry-internal/tracing/esm/browser/web-vitals/lib/onHidden.js new file mode 100644 index 0000000..78bb128 --- /dev/null +++ b/shared/logger/node_modules/@sentry-internal/tracing/esm/browser/web-vitals/lib/onHidden.js @@ -0,0 +1,36 @@ +import { WINDOW } from '../../types.js'; + +/* + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +const onHidden = (cb, once) => { + const onHiddenOrPageHide = (event) => { + if (event.type === 'pagehide' || WINDOW.document.visibilityState === 'hidden') { + cb(event); + if (once) { + removeEventListener('visibilitychange', onHiddenOrPageHide, true); + removeEventListener('pagehide', onHiddenOrPageHide, true); + } + } + }; + addEventListener('visibilitychange', onHiddenOrPageHide, true); + // Some browsers have buggy implementations of visibilitychange, + // so we use pagehide in addition, just to be safe. + addEventListener('pagehide', onHiddenOrPageHide, true); +}; + +export { onHidden }; +//# sourceMappingURL=onHidden.js.map |
