Skip to content

Commit 0d7fb9c

Browse files
committed
refactor($browser): wrap Get(history.state) in try/catch
Reportedly, MSIE can throw under certain conditions when fetching this attribute. Will confirm before landing. Fixes angular#10367
1 parent 41f03e4 commit 0d7fb9c

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/ng/browser.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,22 @@ function Browser(window, document, $log, $sniffer) {
235235

236236
// This variable should be used *only* inside the cacheState function.
237237
var lastCachedState = null;
238+
function getCurrentState() {
239+
try {
240+
var state = history.state;
241+
if (state === void 0) {
242+
state = null;
243+
}
244+
return state;
245+
} catch (e) {
246+
// MSIE can reportedly throw when there is no state (UNCONFIRMED).
247+
return null;
248+
}
249+
}
250+
238251
function cacheState() {
239252
// This should be the only place in $browser where `history.state` is read.
240-
cachedState = window.history.state;
241-
cachedState = isUndefined(cachedState) ? null : cachedState;
253+
cachedState = getCurrentState();
242254

243255
// Prevent callbacks fo fire twice if both hashchange & popstate were fired.
244256
if (equals(cachedState, lastCachedState)) {

0 commit comments

Comments
 (0)