Skip to content
Browse files

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
  • Loading branch information...
caitp authored and petebacondarwin committed Dec 8, 2014
1 parent 2fe9b1d commit 92767c098feaf8c58faf2d67f882305019d8160e
Showing with 9 additions and 1 deletion.
  1. +9 −1 src/ng/browser.js
@@ -233,11 +233,19 @@ function Browser(window, document, $log, $sniffer) {

function getCurrentState() {
try {
return history.state;
} catch (e) {
// MSIE can reportedly throw when there is no state (UNCONFIRMED).

// This variable should be used *only* inside the cacheState function.
var lastCachedState = null;
function cacheState() {
// This should be the only place in $browser where `history.state` is read.
cachedState = window.history.state;
cachedState = getCurrentState();
cachedState = isUndefined(cachedState) ? null : cachedState;

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

0 comments on commit 92767c0

Please sign in to comment.
You can’t perform that action at this time.