Skip to content

Commit 2367e09

Browse files
committed
Avoid CSP errors in Chrome apps by using global var detection.
Fixes #301.
1 parent a7981c3 commit 2367e09

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

es6-shim.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,15 @@
144144
}());
145145

146146
/*jshint evil: true */
147-
var getGlobal = new Function('return this;');
147+
var getGlobal = function () {
148+
// the only reliable means to get the global object is
149+
// `Function('return this')()`
150+
// However, this causes CSP violations in Chrome apps.
151+
if (typeof self !== 'undefined') { return self; }
152+
if (typeof window !== 'undefined') { return window; }
153+
if (typeof global !== 'undefined') { return global; }
154+
throw new Error('unable to locate global object');
155+
};
148156
/*jshint evil: false */
149157

150158
var globals = getGlobal();

0 commit comments

Comments
 (0)