pdf-caching-flags.js 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. import getMeta from '../../../utils/meta'
  2. import { debugConsole } from '@/utils/debugging'
  3. const hasTextEncoder = typeof TextEncoder !== 'undefined'
  4. if (!hasTextEncoder) {
  5. debugConsole.warn('TextEncoder is not available. Disabling pdf-caching.')
  6. }
  7. const isOpera =
  8. Array.isArray(navigator.userAgentData?.brands) &&
  9. navigator.userAgentData.brands.some(b => b.brand === 'Opera')
  10. if (isOpera) {
  11. debugConsole.warn('Browser cache is limited in Opera. Disabling pdf-caching.')
  12. }
  13. function isFlagEnabled(flag) {
  14. if (!hasTextEncoder) return false
  15. if (isOpera) return false
  16. return getMeta('ol-splitTestVariants')?.[flag] === 'enabled'
  17. }
  18. export const cachedUrlLookupEnabled = isFlagEnabled(
  19. 'pdf-caching-cached-url-lookup'
  20. )
  21. export const prefetchingEnabled = isFlagEnabled('pdf-caching-prefetching')
  22. export const prefetchLargeEnabled = isFlagEnabled('pdf-caching-prefetch-large')
  23. export const enablePdfCaching = isFlagEnabled('pdf-caching-mode')
  24. export const trackPdfDownloadEnabled = isFlagEnabled('track-pdf-download')
  25. export const projectOwnerHasPremiumOnPageLoad = getMeta(
  26. 'ol-projectOwnerHasPremiumOnPageLoad'
  27. )
  28. export const fallBackToClsiCache =
  29. projectOwnerHasPremiumOnPageLoad && isFlagEnabled('populate-clsi-cache')