import { storageIsSupported } from './utils/local-storage'
import cloudflareFetchHander from './cloudflare-fetch-handler'

const fetchIsSupported = 'fetch' in window

if (fetchIsSupported && storageIsSupported('localStorage')) {
  const nativeFetch = window.fetch

  window.fetch = (...args) => {
    return nativeFetch(...args).then(cloudflareFetchHander)
  }
}
