Skip to content

Commit c07000a

Browse files
frederikprijckellimist
authored andcommitted
fix($sniffer): allow history for NW.js apps
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 angular#15474 Closes angular#15633
1 parent 30d82b6 commit c07000a

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/ng/sniffer.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ function $SnifferProvider() {
2525
// (see https://developer.chrome.com/apps/api_index). If sandboxed, they can be detected by
2626
// the presence of an extension runtime ID and the absence of other Chrome runtime APIs
2727
// (see https://developer.chrome.com/apps/manifest/sandbox).
28+
// (NW.js apps have access to Chrome APIs, but do support `history`.)
29+
isNw = $window.nw && $window.nw.process,
2830
isChromePackagedApp =
31+
!isNw &&
2932
$window.chrome &&
3033
($window.chrome.app && $window.chrome.app.runtime ||
3134
!$window.chrome.app && $window.chrome.runtime && $window.chrome.runtime.id),

test/ng/snifferSpec.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,25 @@ describe('$sniffer', function() {
4545
});
4646

4747

48+
it('should be true on NW.js apps (which look similar to Chrome Packaged Apps)', function() {
49+
var mockWindow = {
50+
history: {
51+
pushState: noop
52+
},
53+
chrome: {
54+
app: {
55+
runtime: {}
56+
}
57+
},
58+
nw: {
59+
process: {}
60+
}
61+
};
62+
63+
expect(sniffer(mockWindow).history).toBe(true);
64+
});
65+
66+
4867
it('should be false on Chrome Packaged Apps', function() {
4968
// Chrome Packaged Apps are not allowed to access `window.history.pushState`.
5069
// In Chrome, `window.app` might be available in "normal" webpages, but `window.app.runtime`

0 commit comments

Comments
 (0)