Files
overleaf-cep/services/web/frontend/js/features/pdf-preview/util/pdf-caching-flags.ts
T
Jakob Ackermann f3f6a8a8e0 [web] add clsi-cache prompts (#29281)
* [web] add clsi-cache prompts

* [web] add new editor variant to segmentation

* [web] add tests for useNewEditorVariant

* [web] adjust start of using clsi-cache in split-test

GitOrigin-RevId: c9c5b1eff2ceefb65ef82516d9074cb971cb4c48
2025-10-24 08:05:42 +00:00

39 lines
1.4 KiB
TypeScript

import getMeta from '../../../utils/meta'
import { debugConsole } from '@/utils/debugging'
const hasTextEncoder = typeof TextEncoder !== 'undefined'
if (!hasTextEncoder) {
debugConsole.warn('TextEncoder is not available. Disabling pdf-caching.')
}
const isOpera =
// userAgentData is experimental and not currently in the Navigator type
Array.isArray((navigator as any).userAgentData?.brands) &&
(navigator as any).userAgentData.brands.some(
(b: { brand: string }) => b.brand === 'Opera'
)
if (isOpera) {
debugConsole.warn('Browser cache is limited in Opera. Disabling pdf-caching.')
}
function isFlagEnabled(flag: string): boolean {
if (!hasTextEncoder) return false
if (isOpera) return false
return getMeta('ol-splitTestVariants')?.[flag] === 'enabled'
}
export const cachedUrlLookupEnabled = isFlagEnabled(
'pdf-caching-cached-url-lookup'
)
export const prefetchingEnabled = isFlagEnabled('pdf-caching-prefetching')
export const prefetchLargeEnabled = isFlagEnabled('pdf-caching-prefetch-large')
export const enablePdfCaching = isFlagEnabled('pdf-caching-mode')
export const trackPdfDownloadEnabled = isFlagEnabled('track-pdf-download')
export const projectOwnerHasPremiumOnPageLoad = getMeta(
'ol-projectOwnerHasPremiumOnPageLoad'
)
export const fallBackToClsiCache =
projectOwnerHasPremiumOnPageLoad &&
(isFlagEnabled('populate-clsi-cache') ||
isFlagEnabled('populate-clsi-cache-for-prompt'))