diff --git a/src/browser-detect.service.spec.ts b/src/browser-detect.service.spec.ts index a7a206c..3b257f8 100644 --- a/src/browser-detect.service.spec.ts +++ b/src/browser-detect.service.spec.ts @@ -4,7 +4,8 @@ import { TestBed, async, inject } from '@angular/core/testing'; import { BrowserDetectService } from './browser-detect.service'; import { WindowTokenModule, WINDOW } from "ngx-window-token"; -const chromeWindows10 = 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36'; +const chrome57Windows10 = 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36'; +const chrome54Windows10 = 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2987.133 Safari/537.36'; const firefox27 = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0'; const firefox26 = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:26.0) Gecko/20100101 Firefox/26.0'; const MSIE10 = 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E)'; @@ -27,8 +28,11 @@ describe('Service: BrowserDetect', () => { }); }); - it('chrome is supported', inject([BrowserDetectService], (service: BrowserDetectService) => { - expect(service.isBrowserSupport(chromeWindows10)).toBeTruthy(); + it('chrome 57 is supported', inject([BrowserDetectService], (service: BrowserDetectService) => { + expect(service.isBrowserSupport(chrome57Windows10)).toBeTruthy(); + })); + it('chrome 54 is not supported', inject([BrowserDetectService], (service: BrowserDetectService) => { + expect(service.isBrowserSupport(chrome54Windows10)).toBeFalsy(); })); }); diff --git a/src/browser-detect.service.ts b/src/browser-detect.service.ts index 104171a..631f254 100644 --- a/src/browser-detect.service.ts +++ b/src/browser-detect.service.ts @@ -8,7 +8,9 @@ export class BrowserDetectService { public isBrowserSupport(ua: string): boolean { // tslint:disable-next-line:no-string-literal if (!!this.window['chrome'] && !!this.window['chrome']['webstore']) { - return true; + const match = /(?:Chrome|Crios|Crmo)\/(\d+\.\d+?)/.exec(ua); + const ver = +match[1]; + return !!match[0] && !isNaN(ver) && ver >= 55; // Chrome 55+ } else if (ua.indexOf('MSIE') !== -1) { return ua.indexOf('MSIE 10') !== -1; // filter out all IE but IE10 } else if (ua.indexOf('Edge') !== -1 || ua.indexOf('Trident') !== -1) {