diff --git a/src/ng/sniffer.js b/src/ng/sniffer.js index be6af00029ed..5de405e8c570 100644 --- a/src/ng/sniffer.js +++ b/src/ng/sniffer.js @@ -20,12 +20,14 @@ function $SnifferProvider() { this.$get = ['$window', '$document', function($window, $document) { var eventSupport = {}, + isNw = $window.nw && $window.nw.process, // Chrome Packaged Apps are not allowed to access `history.pushState`. // If not sandboxed, they can be detected by the presence of `chrome.app.runtime` // (see https://developer.chrome.com/apps/api_index). If sandboxed, they can be detected by // the presence of an extension runtime ID and the absence of other Chrome runtime APIs // (see https://developer.chrome.com/apps/manifest/sandbox). isChromePackagedApp = + !isNw && $window.chrome && ($window.chrome.app && $window.chrome.app.runtime || !$window.chrome.app && $window.chrome.runtime && $window.chrome.runtime.id), diff --git a/test/ng/snifferSpec.js b/test/ng/snifferSpec.js index 50f90ec842c7..cb71688730f7 100644 --- a/test/ng/snifferSpec.js +++ b/test/ng/snifferSpec.js @@ -25,6 +25,25 @@ describe('$sniffer', function() { }); + it('should be true if running inside nw.js', function() { + var mockWindow = { + nw: { + process: noop + }, + history: { + pushState: noop + }, + chrome: { + app: { + runtime: noop + } + } + }; + + expect(sniffer(mockWindow).history).toBe(true); + }); + + it('should be false if history or pushState not defined', function() { expect(sniffer({}).history).toBe(false); expect(sniffer({history: {}}).history).toBe(false);