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

Commit 3b8163b

Browse files
caitppetebacondarwin
authored andcommitted
fix($browser): don't crash if history.state access causes error in IE
Reportedly, MSIE can throw under certain conditions when fetching this attribute. We don't have a reliable reproduction for this but it doesn't do any real harm to wrap access to this variable in a try-catch block. Fixes #10367 Closes #10369
1 parent 2907a02 commit 3b8163b

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/ng/browser.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,19 @@ function Browser(window, document, $log, $sniffer) {
233233
fireUrlChange();
234234
}
235235

236+
function getCurrentState() {
237+
try {
238+
return history.state;
239+
} catch (e) {
240+
// MSIE can reportedly throw when there is no state (UNCONFIRMED).
241+
}
242+
}
243+
236244
// This variable should be used *only* inside the cacheState function.
237245
var lastCachedState = null;
238246
function cacheState() {
239247
// This should be the only place in $browser where `history.state` is read.
240-
cachedState = window.history.state;
248+
cachedState = getCurrentState();
241249
cachedState = isUndefined(cachedState) ? null : cachedState;
242250

243251
// Prevent callbacks fo fire twice if both hashchange & popstate were fired.

0 commit comments

Comments
 (0)