-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
ref(browser)!: Drop Safari 14 support - remove navigationStart fallback and pagehide listeners
#21293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
ref(browser)!: Drop Safari 14 support - remove navigationStart fallback and pagehide listeners
#21293
Changes from all commits
1f82e57
66ba1a4
8bbc4b3
284e5ea
f3d6abc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,36 +22,21 @@ export interface OnHiddenCallback { | |
| } | ||
|
|
||
| /** | ||
| * Sentry-specific change: | ||
| * Calls the passed callback when the page transitions to hidden. | ||
| * | ||
| * This function's logic was NOT updated to web-vitals 4.2.4 or 5.x but we continue | ||
| * to use the web-vitals 3.5.2 version due to having stricter browser support. | ||
| * Uses the `visibilitychange` event exclusively, which is well-supported | ||
| * across all modern browsers. | ||
| * | ||
| * PR with context that made the changes: | ||
| * https://github.com/GoogleChrome/web-vitals/pull/442/files#r1530492402 | ||
| * | ||
| * The PR removed listening to the `pagehide` event, in favour of only listening to | ||
| * the `visibilitychange` event. This is "more correct" but some browsers we still | ||
| * support (Safari <14.4) don't fully support `visibilitychange` or have known bugs | ||
| * with respect to the `visibilitychange` event. | ||
| * | ||
| * TODO (v11): If we decide to drop support for Safari 14.4, we can use the logic | ||
| * from web-vitals 4.2.4. In this case, we also need to update the integration tests | ||
| * that currently trigger the `pagehide` event to simulate the page being hidden. | ||
| * | ||
| * @param {OnHiddenCallback} cb - Callback to be executed when the page is hidden or unloaded. | ||
| * @param {OnHiddenCallback} cb - Callback to be executed when the page is hidden. | ||
| * | ||
| * @deprecated use `whenIdleOrHidden` or `addPageListener('visibilitychange')` instead | ||
| */ | ||
| export const onHidden = (cb: OnHiddenCallback) => { | ||
| const onHiddenOrPageHide = (event: Event) => { | ||
| if (event.type === 'pagehide' || WINDOW.document?.visibilityState === 'hidden') { | ||
| const onHiddenCallback = (event: Event) => { | ||
| if (WINDOW.document?.visibilityState === 'hidden') { | ||
| cb(event); | ||
| } | ||
| }; | ||
|
|
||
| addPageListener('visibilitychange', onHiddenOrPageHide, { capture: true, once: true }); | ||
| // Some browsers have buggy implementations of visibilitychange, | ||
| // so we use pagehide in addition, just to be safe. | ||
| addPageListener('pagehide', onHiddenOrPageHide, { capture: true, once: true }); | ||
| addPageListener('visibilitychange', onHiddenCallback, { capture: true }); | ||
| }; | ||
|
Comment on lines
39
to
42
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: The Suggested FixRestore the Prompt for AI Agent
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a page load cleans up all event listeners and the integration is only set up once, so this doesn't cause a memory leak. also matches |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,9 +80,9 @@ let cachedTimeOrigin: number | null | undefined = null; | |
| /** | ||
| * Gets the time origin and the mode used to determine it. | ||
| * | ||
| * Unfortunately browsers may report an inaccurate time origin data, through either performance.timeOrigin or | ||
| * performance.timing.navigationStart, which results in poor results in performance data. We only treat time origin | ||
| * data as reliable if they are within a reasonable threshold of the current time. | ||
| * Unfortunately browsers may report inaccurate time origin data through performance.timeOrigin, | ||
| * which results in poor results in performance data. We only treat time origin data as reliable | ||
| * if it is within a reasonable threshold of the current time. | ||
| * | ||
| * TODO: move to `@sentry/browser-utils` package. | ||
| */ | ||
|
|
@@ -104,25 +104,7 @@ function getBrowserTimeOrigin(): number | undefined { | |
| } | ||
| } | ||
|
|
||
| // TODO: Remove all code related to `performance.timing.navigationStart` once we drop support for Safari 14. | ||
| // `performance.timeSince` is available in Safari 15. | ||
| // see: https://caniuse.com/mdn-api_performance_timeorigin | ||
|
|
||
| // While performance.timing.navigationStart is deprecated in favor of performance.timeOrigin, performance.timeOrigin | ||
| // is not as widely supported. Namely, performance.timeOrigin is undefined in Safari as of writing. | ||
| // Also as of writing, performance.timing is not available in Web Workers in mainstream browsers, so it is not always | ||
| // a valid fallback. In the absence of an initial time provided by the browser, fallback to the current time from the | ||
| // Date API. | ||
| // eslint-disable-next-line typescript/no-deprecated | ||
| const navigationStart = performance.timing?.navigationStart; | ||
| if (typeof navigationStart === 'number') { | ||
| const navigationStartDelta = Math.abs(navigationStart + performanceNow - dateNow); | ||
| if (navigationStartDelta < threshold) { | ||
| return navigationStart; | ||
| } | ||
| } | ||
|
Comment on lines
-117
to
-123
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some tests still assert the |
||
|
|
||
| // Either both timeOrigin and navigationStart are skewed or neither is available, fallback to subtracting | ||
| // timeOrigin is skewed or unavailable, fallback to subtracting | ||
| // `performance.now()` from `Date.now()`. | ||
| return dateNow - performanceNow; | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.