From 6face740f59fc9406c555116f2bb9ce52711bff3 Mon Sep 17 00:00:00 2001 From: Adam Gschwender Date: Wed, 4 May 2016 20:25:35 -0400 Subject: [PATCH] Force redirect when pushState encounters an error Version 9.1 of Safari allows a maximum of 100 calls to pushState. Subsequent calls to pushState throw a SecurityError: DOM Exception 18: An attempt was made to break through the security policy of the user agent. --- mithril.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/mithril.js b/mithril.js index 2f66d2cc..607809a0 100644 --- a/mithril.js +++ b/mithril.js @@ -1617,8 +1617,16 @@ var method = replaceHistory ? "replaceState" : "pushState" computePreRedrawHook = setScroll computePostRedrawHook = function () { - global.history[method](null, $document.title, - modes[m.route.mode] + currentRoute) + try { + global.history[method](null, $document.title, + modes[m.route.mode] + currentRoute) + } catch (err) { + // In the event of a pushState or replaceState failure, + // fallback to a standard redirect. This is specifically + // to address a Safari security error when attempting to + // call pushState more than 100 times. + $location[m.route.mode] = currentRoute + } } redirect(modes[m.route.mode] + currentRoute) } else {