import { Inject, Injectable, } from '@angular/core'; import BrowserTypesEnum from './browser-types.enum'; @Injectable() export default class BrowserDetectorService { private _browserType: BrowserTypesEnum; constructor( @Inject('window') private _window: Window, ) { this._browserType = this._getBrowserType(); } public isFirefox() { return this._browserType === BrowserTypesEnum.Firefox; } public isSafari() { return this._browserType === BrowserTypesEnum.Safari; } public isChrome() { return this._browserType === BrowserTypesEnum.Chrome; } private _getBrowserType() { const nativeWindow = this._window; if (nativeWindow.navigator.userAgent .match(/Firefox/) ) { return BrowserTypesEnum.Firefox; } else if ( nativeWindow.navigator.userAgent.match(/Safari/) && !nativeWindow.navigator.userAgent.match(/Chrome/) ) { return BrowserTypesEnum.Safari; } return BrowserTypesEnum.Chrome; } }