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

Commit 4a593db

Browse files
frederikprijckgkalpak
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 #15474 Closes #15633
1 parent ad4fef0 commit 4a593db

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/ng/sniffer.js

+3
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

+19
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)