{"version":3,"file":"onHidden.js","sources":["../../../../../src/metrics/web-vitals/lib/onHidden.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 { WINDOW } from '../../../types';\nimport { addPageListener } from './globalListeners';\n\nexport interface OnHiddenCallback {\n (event: Event): void;\n}\n\n/**\n * Sentry-specific change:\n *\n * This function's logic was NOT updated to web-vitals 4.2.4 or 5.x but we continue\n * to use the web-vitals 3.5.2 version due to having stricter browser support.\n *\n * PR with context that made the changes:\n * https://github.com/GoogleChrome/web-vitals/pull/442/files#r1530492402\n *\n * The PR removed listening to the `pagehide` event, in favour of only listening to\n * the `visibilitychange` event. This is \"more correct\" but some browsers we still\n * support (Safari <14.4) don't fully support `visibilitychange` or have known bugs\n * with respect to the `visibilitychange` event.\n *\n * TODO (v11): If we decide to drop support for Safari 14.4, we can use the logic\n * from web-vitals 4.2.4. In this case, we also need to update the integration tests\n * that currently trigger the `pagehide` event to simulate the page being hidden.\n *\n * @param {OnHiddenCallback} cb - Callback to be executed when the page is hidden or unloaded.\n *\n * @deprecated use `whenIdleOrHidden` or `addPageListener('visibilitychange')` instead\n */\nexport const onHidden = (cb: OnHiddenCallback) => {\n const onHiddenOrPageHide = (event: Event) => {\n if (event.type === 'pagehide' || WINDOW.document?.visibilityState === 'hidden') {\n cb(event);\n }\n };\n\n addPageListener('visibilitychange', onHiddenOrPageHide, { capture: true, once: true });\n // Some browsers have buggy implementations of visibilitychange,\n // so we use pagehide in addition, just to be safe.\n addPageListener('pagehide', onHiddenOrPageHide, { capture: true, once: true });\n};\n"],"names":["WINDOW","addPageListener"],"mappings":";;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AASA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;MACa,QAAA,GAAW,CAAC,EAAE,KAAuB;AAClD,EAAE,MAAM,kBAAA,GAAqB,CAAC,KAAK,KAAY;AAC/C,IAAI,IAAI,KAAK,CAAC,SAAS,UAAA,IAAcA,YAAM,CAAC,QAAQ,EAAE,eAAA,KAAoB,QAAQ,EAAE;AACpF,MAAM,EAAE,CAAC,KAAK,CAAC;AACf,IAAI;AACJ,EAAE,CAAC;;AAEH,EAAEC,+BAAe,CAAC,kBAAkB,EAAE,kBAAkB,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAA,EAAM,CAAC;AACxF;AACA;AACA,EAAEA,+BAAe,CAAC,UAAU,EAAE,kBAAkB,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAA,EAAM,CAAC;AAChF;;;;"}