fix(whole-page-capture): increase delay between captures

Chrome added a limit on the number of captures which can be made each
second, which made the whole page capture feature stop working.

This CL fixes this by preventing going over the limit.

Change-Id: Ieee55073de4dad3e496f384b569214c2f19f7191
diff --git a/src/js/background.js b/src/js/background.js
index ff4eaef..1f44f3b 100644
--- a/src/js/background.js
+++ b/src/js/background.js
@@ -91,12 +91,12 @@
         screenshot.docWidth = response.docWidth;
         screenshot.docHeight = response.docHeight;
         screenshot.zoom = response.zoom;
-        setTimeout("screenshot.captureAndScroll()", 100);
+        setTimeout("screenshot.captureAndScroll()", screenshot.captureDelayInMs());
         break;
       case 'scroll_next_done':
         screenshot.scrollXCount = response.scrollXCount;
         screenshot.scrollYCount = response.scrollYCount;
-        setTimeout("screenshot.captureAndScroll()", 100);
+        setTimeout("screenshot.captureAndScroll()", screenshot.captureDelayInMs());
         break;
       case 'scroll_finished':
         screenshot.captureAndScrollDone();
@@ -273,7 +273,14 @@
   init: function() {
     localStorage.screenshootQuality = localStorage.screenshootQuality || 'png';
     screenshot.addMessageListener();
-  }
+  },
+
+  captureDelayInMs: function() {
+    var maxCallsPerSecond = chrome?.tabs?.MAX_CAPTURE_VISIBLE_TAB_CALLS_PER_SECOND;
+    if (!maxCallsPerSecond) return 100;
+
+    return Math.ceil(1000/maxCallsPerSecond) + 10;
+  },
 };
 
 screenshot.init();