<commit_before>const SERVICE_WORKER_PATH = '/service-worker.js'
const SERVICE_WORKER_SCOPE = '/karrot-push'

export async function hasServiceWorker () {
  return (await getServiceWorkers()).length > 0
}

export async function getServiceWorker () {
  return (await getServiceWorkers())[0]
}

async function getServiceWorkers () {
  if (__ENV.CORDOVA || !window.navigator.serviceWorker) return []
  const registrations = await window.navigator.serviceWorker.getRegistrations()
  return registrations.filter(worker => worker.scope.endsWith(SERVICE_WORKER_SCOPE))
}

async function getOrCreateWorker () {
  const worker = await getServiceWorker()
  if (worker) return worker
  return window.navigator.serviceWorker.register(SERVICE_WORKER_PATH, { scope: SERVICE_WORKER_SCOPE })
}

let messaging
export async function initializeMessaging () {
  const { initializeApp, messaging: initializeMessaging } = await import('./firebase.lib')<commit_msg>handle error when getting list of service workers<commit_after>import * as Sentry from '@sentry/browser'

const SERVICE_WORKER_PATH = '/service-worker.js'
const SERVICE_WORKER_SCOPE = '/karrot-push'

export async function hasServiceWorker () {
  return (await getServiceWorkers()).length > 0
}

export async function getServiceWorker () {
  if (await hasServiceWorker()) return (await getServiceWorkers())[0]
}

async function getServiceWorkers () {
  if (__ENV.CORDOVA || !window.navigator.serviceWorker) return []
  let registrations
  try {
    registrations = await window.navigator.serviceWorker.getRegistrations()
  }
  catch (err) {
    Sentry.captureException(err)
    return []
  }
  return registrations.filter(worker => worker.scope.endsWith(SERVICE_WORKER_SCOPE))
}

async function getOrCreateWorker () {
  const worker = await getServiceWorker()
  if (worker) return worker
  return window.navigator.serviceWorker.register(SERVICE_WORKER_PATH, { scope: SERVICE_WORKER_SCOPE })
}

let messaging
export async function initializeMessaging () {
  const { initializeApp, messaging: initializeMessaging } = await import('./firebase.lib')
{'fraction_non_alphanumeric': 0.1017274472168906, 'fraction_numerical': 0.0019193857965451055, 'mean_word_length': 5.619047619047619, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7532033', 'n_tokens_mistral': 614, 'n_tokens_neox': 605, 'n_words': 144}