From d873a9173f8c73b561704cd477251a4473ec8331 Mon Sep 17 00:00:00 2001 From: Giacomo De Liberali Date: Sun, 14 Jul 2019 19:59:50 +0200 Subject: [PATCH] Fix Webpack global scope issue In webpack 4 (Angular 8) the `_global = ...` will return undefined causing "Cannot read property WebSocket of undefined" --- lib/browser.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/browser.js b/lib/browser.js index c11cea9d..51d19792 100644 --- a/lib/browser.js +++ b/lib/browser.js @@ -1,4 +1,9 @@ -var _global = (function() { return this; })(); +var _global = (function () { + if (!this && typeof global !== 'undefined') { + return global; + } + return this; +})(); var NativeWebSocket = _global.WebSocket || _global.MozWebSocket; var websocket_version = require('./version');