diff --git a/swh/web/assets/src/bundles/browse/snapshot-navigation.js b/swh/web/assets/src/bundles/browse/snapshot-navigation.js
index c9a931166d926bc9695f1312d8b51a8059498ee3..8ade39fbde3173d43e0ab97f79d91cc7bc1dce08 100644
--- a/swh/web/assets/src/bundles/browse/snapshot-navigation.js
+++ b/swh/web/assets/src/bundles/browse/snapshot-navigation.js
@@ -5,7 +5,7 @@
  * See top-level LICENSE file for more information
  */
 
-export function initSnapshotNavigation(snapshotContext) {
+export function initSnapshotNavigation(snapshotContext, branch) {
 
   function setBranchesTabActive() {
     $('.swh-releases-switch').removeClass('active');
@@ -44,7 +44,7 @@ export function initSnapshotNavigation(snapshotContext) {
     });
 
     if (snapshotContext) {
-      if (snapshotContext.branch) {
+      if (branch) {
         setBranchesTabActive();
       } else {
         setReleasesTabActive();
diff --git a/swh/web/templates/includes/top-navigation.html b/swh/web/templates/includes/top-navigation.html
index c206291ff4ba926d8e06acb6ce214c199a36aa85..1738d142e3e6444a9592729a268f87a7c4eb8ad3 100644
--- a/swh/web/templates/includes/top-navigation.html
+++ b/swh/web/templates/includes/top-navigation.html
@@ -89,6 +89,11 @@ See top-level LICENSE file for more information
 </div>
 
 <script>
-  var snapshotContext = {{ snapshot_context|jsonify }};
-  swh.browse.initSnapshotNavigation(snapshotContext);
+  var snapshotContext = false;
+  var branch = false;
+  {% if snapshot_context %}
+    snapshotContext = true;
+    branch = {{ snapshot_context.branch|jsonify }};
+  {% endif %}
+  swh.browse.initSnapshotNavigation(snapshotContext, branch);
 </script>