Skip to content

Commit

Permalink
fix(universal): gate platform checks on being on browser (#4635)
Browse files Browse the repository at this point in the history
Related to #308
  • Loading branch information
jelbourn authored May 19, 2017
1 parent f11d46e commit e4c7601
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/lib/core/platform/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,27 @@ export class Platform {
isBrowser: boolean = typeof document === 'object' && !!document;

/** Layout Engines */
EDGE = /(edge)/i.test(navigator.userAgent);
TRIDENT = /(msie|trident)/i.test(navigator.userAgent);
EDGE = this.isBrowser && /(edge)/i.test(navigator.userAgent);
TRIDENT = this.isBrowser && /(msie|trident)/i.test(navigator.userAgent);

// EdgeHTML and Trident mock Blink specific things and need to be excluded from this check.
BLINK = !!((window as any).chrome || hasV8BreakIterator) && !!CSS && !this.EDGE && !this.TRIDENT;
BLINK = this.isBrowser &&
(!!((window as any).chrome || hasV8BreakIterator) && !!CSS && !this.EDGE && !this.TRIDENT);

// Webkit is part of the userAgent in EdgeHTML, Blink and Trident. Therefore we need to
// ensure that Webkit runs standalone and is not used as another engine's base.
WEBKIT = /AppleWebKit/i.test(navigator.userAgent) && !this.BLINK && !this.EDGE && !this.TRIDENT;
WEBKIT = this.isBrowser &&
/AppleWebKit/i.test(navigator.userAgent) && !this.BLINK && !this.EDGE && !this.TRIDENT;

/** Browsers and Platform Types */
IOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !(window as any).MSStream;
IOS = this.isBrowser && /iPad|iPhone|iPod/.test(navigator.userAgent) && !(window as any).MSStream;

// It's difficult to detect the plain Gecko engine, because most of the browsers identify
// them self as Gecko-like browsers and modify the userAgent's according to that.
// Since we only cover one explicit Firefox case, we can simply check for Firefox
// instead of having an unstable check for Gecko.
FIREFOX = /(firefox|minefield)/i.test(navigator.userAgent);
FIREFOX = this.isBrowser && /(firefox|minefield)/i.test(navigator.userAgent);

// Trident on mobile adds the android platform to the userAgent to trick detections.
ANDROID = /android/i.test(navigator.userAgent) && !this.TRIDENT;
ANDROID = this.isBrowser && /android/i.test(navigator.userAgent) && !this.TRIDENT;
}

0 comments on commit e4c7601

Please sign in to comment.