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

Commit aedb762

Browse files
author
Shane Tomlinson
committed
fix(metrics): Reduce the number of localStorage errors in Sentry.
crosstab writes to localStorage every 3 seconds to find out if any other tabs are open. Errors are reported to Sentry on every write if localStorage data is unable to be written to disk. Inter-tab communication is done via BroadcastChannels if the browser has support and falls back to crosstab if not. If the browser supports BroadcastChannels, abort crosstab initialization issue #3414
1 parent db0813e commit aedb762

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

app/scripts/vendor/crosstab.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@
5050
setItemAllowed = false;
5151
}
5252

53+
// begin FxA addition
54+
var hasBroadcastChannel = typeof window.BroadcastChannel === 'function';
55+
// end FxA addition
56+
5357
// Other reasons
5458
var frozenTabEnvironment = false;
5559

@@ -72,6 +76,11 @@
7276
if (!setItemAllowed) {
7377
reasons.push('localStorage.setItem not allowed');
7478
}
79+
// begin FxA addition
80+
if (hasBroadcastChannel) {
81+
reasons.push('BroadcastChannel is supported, use it instead');
82+
}
83+
// end FxA addition
7584

7685
if (reasons.length > 0) {
7786
errorMsg += ': ' + reasons.join(', ');
@@ -640,7 +649,9 @@
640649
};
641650

642651
crosstab.id = util.generateId();
643-
crosstab.supported = !!localStorage && window.addEventListener && !isMobile && setItemAllowed;
652+
// begin FxA addition (hasBroadcastChannel)
653+
crosstab.supported = !!localStorage && window.addEventListener && !isMobile && setItemAllowed && ! hasBroadcastChannel;
654+
// end FxA addition
644655
crosstab.util = util;
645656
crosstab.broadcast = broadcast;
646657
crosstab.broadcastMaster = broadcastMaster;
@@ -696,7 +707,19 @@
696707
var PING_TIMEOUT = 500;
697708

698709
function getStoredTabs() {
699-
var storedTabs = getLocalStorageItem(util.keys.TABS_KEY);
710+
// begin FxA modification to add the try/catch
711+
// the old code was:
712+
// var storedTabs = getLocalStorageItem(util.keys.TABS_KEY);
713+
var storedTabs;
714+
try {
715+
// crosstab.supported is not set on the initial call
716+
// to getStoredTabs. An exception can occur if localStorage
717+
// is supported but the accessor functions except.
718+
storedTabs = getLocalStorageItem(util.keys.TABS_KEY);
719+
} catch (e) {
720+
// ignore error
721+
}
722+
// end FxA modification
700723
util.tabs = storedTabs || util.tabs || {};
701724
return util.tabs;
702725
}

0 commit comments

Comments
 (0)