From 12ad4f6df8f2714e12b0da3c189bd8768ce63e39 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 11 Jan 2018 15:49:29 -0500 Subject: [PATCH] safari device checks and tests --- .../browserPlatformUtils.service.spec.ts | 20 +++++++++++++++++++ src/services/browserPlatformUtils.service.ts | 2 ++ 2 files changed, 22 insertions(+) diff --git a/src/services/browserPlatformUtils.service.spec.ts b/src/services/browserPlatformUtils.service.spec.ts index 7527d85257..9c2500c569 100644 --- a/src/services/browserPlatformUtils.service.spec.ts +++ b/src/services/browserPlatformUtils.service.spec.ts @@ -81,5 +81,25 @@ describe('Browser Utils Service', () => { const browserPlatformUtilsService = new BrowserPlatformUtilsService(); expect(browserPlatformUtilsService.getDevice()).toBe(DeviceType.Edge); }); + + it('should detect safari', () => { + Object.defineProperty(navigator, 'userAgent', { + configurable: true, + value: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/602.4.8 (KHTML, like Gecko) Version/10.0.3 Safari/602.4.8' + }); + + const browserPlatformUtilsService = new BrowserPlatformUtilsService(); + expect(browserPlatformUtilsService.getDevice()).toBe(DeviceType.Safari); + }); + + it('should detect vivaldi', () => { + Object.defineProperty(navigator, 'userAgent', { + configurable: true, + value: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.97 Safari/537.36 Vivaldi/1.94.1008.40' + }); + + const browserPlatformUtilsService = new BrowserPlatformUtilsService(); + expect(browserPlatformUtilsService.getDevice()).toBe(DeviceType.Vivaldi); + }); }); }); diff --git a/src/services/browserPlatformUtils.service.ts b/src/services/browserPlatformUtils.service.ts index b58e5b81e3..6d59d17384 100644 --- a/src/services/browserPlatformUtils.service.ts +++ b/src/services/browserPlatformUtils.service.ts @@ -68,6 +68,8 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService this.deviceCache = DeviceType.Edge; } else if (navigator.userAgent.indexOf(' Vivaldi/') !== -1) { this.deviceCache = DeviceType.Vivaldi; + } else if (navigator.userAgent.indexOf('Safari') !== -1 && navigator.userAgent.indexOf('Chrome') === -1) { + this.deviceCache = DeviceType.Safari; } else if ((window as any).chrome) { this.deviceCache = DeviceType.Chrome; }