Skip to content

Commit

Permalink
fix: according to issue list, only support chrome 55+
Browse files Browse the repository at this point in the history
  • Loading branch information
maxisam committed May 9, 2017
1 parent e21a1a9 commit 61588de
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/browser-detect.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)';
Expand All @@ -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();
}));
});

Expand Down
4 changes: 3 additions & 1 deletion src/browser-detect.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

1 comment on commit 61588de

@maxisam
Copy link
Owner Author

@maxisam maxisam commented on 61588de May 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.