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
This commit is contained in:
committed by
Georgios Kalpakas
parent
89f3e3b0af
commit
7019d9f27a
@@ -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),
|
||||
|
||||
@@ -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`
|
||||
|
||||
Reference in New Issue
Block a user