Skip to content

Commit e4c7601

Browse files
authored
fix(universal): gate platform checks on being on browser (#4635)
Related to #308
1 parent f11d46e commit e4c7601

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/lib/core/platform/platform.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,27 @@ export class Platform {
1414
isBrowser: boolean = typeof document === 'object' && !!document;
1515

1616
/** Layout Engines */
17-
EDGE = /(edge)/i.test(navigator.userAgent);
18-
TRIDENT = /(msie|trident)/i.test(navigator.userAgent);
17+
EDGE = this.isBrowser && /(edge)/i.test(navigator.userAgent);
18+
TRIDENT = this.isBrowser && /(msie|trident)/i.test(navigator.userAgent);
1919

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

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

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

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

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

0 commit comments

Comments
 (0)