Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
fix($sniffer): allow history for NW.js apps
Browse files Browse the repository at this point in the history
Previously `$sniffer` incorrectly detected NW.js apps as Chrome Packaged Apps,
disallowing them to use the history API.

This commit correctly detects NW.js apps and allows them to use the History API.

Fixes #15474

Closes #15633
  • Loading branch information
frederikprijck authored and gkalpak committed Jan 26, 2017
1 parent ad4fef0 commit 4a593db
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/ng/sniffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ function $SnifferProvider() {
// (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).
// (NW.js apps have access to Chrome APIs, but do support `history`.)
isNw = $window.nw && $window.nw.process,
isChromePackagedApp =
!isNw &&
$window.chrome &&
($window.chrome.app && $window.chrome.app.runtime ||
!$window.chrome.app && $window.chrome.runtime && $window.chrome.runtime.id),
Expand Down
19 changes: 19 additions & 0 deletions test/ng/snifferSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,25 @@ describe('$sniffer', function() {
});


it('should be true on NW.js apps (which look similar to Chrome Packaged Apps)', function() {
var mockWindow = {
history: {
pushState: noop
},
chrome: {
app: {
runtime: {}
}
},
nw: {
process: {}
}
};

expect(sniffer(mockWindow).history).toBe(true);
});


it('should be false on Chrome Packaged Apps', function() {
// Chrome Packaged Apps are not allowed to access `window.history.pushState`.
// In Chrome, `window.app` might be available in "normal" webpages, but `window.app.runtime`
Expand Down

0 comments on commit 4a593db

Please sign in to comment.