diff --git a/core/modules/contextual/contextual.toolbar.js b/core/modules/contextual/contextual.toolbar.js
index 635e745..687d903 100644
--- a/core/modules/contextual/contextual.toolbar.js
+++ b/core/modules/contextual/contextual.toolbar.js
@@ -46,25 +46,27 @@ function initContextualToolbar (context) {
   });
 
   // Show the edit tab while there's >=1 contextual link.
-  var collection = Drupal.contextual.collection;
-  var updateVisibility = function () {
-    model.set('isVisible', collection.length > 0);
-  };
-  collection.on('reset remove add', updateVisibility);
-  updateVisibility();
-
-  // Whenever edit mode is toggled, update all contextual links.
-  model.on('change:isViewing', function() {
-    collection.each(function (contextualModel) {
-      contextualModel.set('isLocked', !model.get('isViewing'));
+  if (Drupal.contextual && Drupal.contextual.collection) {
+    var collection = Drupal.contextual.collection;
+    var updateVisibility = function () {
+      model.set('isVisible', collection.length > 0);
+    };
+    collection.on('reset remove add', updateVisibility);
+    updateVisibility();
+
+    // Whenever edit mode is toggled, update all contextual links.
+    model.on('change:isViewing', function() {
+      collection.each(function (contextualModel) {
+        contextualModel.set('isLocked', !model.get('isViewing'));
+      });
     });
-  });
 
-  // Checks whether localStorage indicates we should start in edit mode
-  // rather than view mode.
-  // @see Drupal.contextualToolbar.VisualView.persist()
-  if (localStorage.getItem('Drupal.contextualToolbar.isViewing') === 'false') {
-    model.set('isViewing', false);
+    // Checks whether localStorage indicates we should start in edit mode
+    // rather than view mode.
+    // @see Drupal.contextualToolbar.VisualView.persist()
+    if (localStorage.getItem('Drupal.contextualToolbar.isViewing') === 'false') {
+      model.set('isViewing', false);
+    }
   }
 }
 
