browser.ts 950 B

123456789101112131415161718192021
  1. export const copyToClipboard = (text: string) => {
  2. navigator.clipboard.writeText(text)
  3. }
  4. // @ts-ignore not worth typing
  5. export const isFirefox = (): boolean => typeof InstallTrigger !== 'undefined'
  6. // @ts-ignore not worth typing
  7. export const isChromiumBased = (): boolean => !!window.chrome
  8. // Seen in https://stackoverflow.com/a/9851769
  9. // it will check for the global chrome object for chromium based browsers and
  10. // it will check Firefox's API to install add-ons which as of now all firefox versions have
  11. // to detect if the users browser it's one where the polkadot extension can be installed on
  12. export const isAllowedBrowser = () => isFirefox() || isChromiumBased()
  13. export const isBrowserOutdated = !('ResizeObserver' in window) || !('IntersectionObserver' in window)
  14. export const openInNewTab = (url: string, local?: boolean) => {
  15. const origin = window.location.origin
  16. window.open(`${local ? origin : ''}${url}`, '_blank')?.focus()
  17. }