From 7947ebbaf24eb86ac4cee89ec5a85adf5b9b29c7 Mon Sep 17 00:00:00 2001 From: Myk Melez Date: Wed, 15 Oct 2014 01:04:32 -0700 Subject: [PATCH] ensure we don't fill up browser history over time --- libs/pipe.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libs/pipe.js b/libs/pipe.js index 04ee8500..24c0e29e 100644 --- a/libs/pipe.js +++ b/libs/pipe.js @@ -79,6 +79,18 @@ var DumbPipe = { }, handleEvent: function(event) { + // To ensure we don't fill up the browser history over time, we navigate + // "back" every time the other side navigates us "forward" by changing + // the hash. This will trigger a second hashchange event; to avoid getting + // messages twice, we only get them for the second hashchange event, + // i.e. once we've returned to the hashless page, at which point a second + // call to window.history.back() will have had no effect. + var hash = window.location.hash; + window.history.back(); + if (window.location.hash != hash) { + return; + } + this.send({ command: "get" }, function(envelopes) { envelopes.forEach((function(envelope) { //console.log("inner recv: " + JSON.stringify(envelope));