Skip to content

fix(platform): don't shadow window #4622

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 17, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions src/lib/core/platform/platform.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import {Injectable} from '@angular/core';

declare const window: any;

// Whether the current platform supports the V8 Break Iterator. The V8 check
// is necessary to detect all Blink based browsers.
const hasV8BreakIterator = typeof(window) !== 'undefined' ?
(window.Intl && (window.Intl as any).v8BreakIterator) :
(typeof(Intl) !== 'undefined' && (Intl as any).v8BreakIterator);
const hasV8BreakIterator = (typeof(Intl) !== 'undefined' && (Intl as any).v8BreakIterator);

/**
* Service to detect the current platform by comparing the userAgent strings and
Expand All @@ -22,14 +18,14 @@ export class Platform {
TRIDENT = /(msie|trident)/i.test(navigator.userAgent);

// EdgeHTML and Trident mock Blink specific things and need to be excluded from this check.
BLINK = !!(window.chrome || hasV8BreakIterator) && !!CSS && !this.EDGE && !this.TRIDENT;
BLINK = !!((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;

/** Browsers and Platform Types */
IOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
IOS = /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.
Expand Down