title: Chrome Extension - Blob from Background to Context script
body: <p>I have a chrome extension attempting to record the active tab and save the blob to local storage.</p>
  
  <p>The <code>chrome.tabCapture</code> is called based on a command issued by the user, after 5 seconds, the recording is stopped and make a new blob from the recorded chunks, proceed to download the file.</p>
  
  <p>When the file is downloaded the file is 0 Bytes, when putting a breakpoint before, inspecting the blob it is greater than 0 Bytes. Eventually attempting to return the blob to the context script in the <code>sendResponse</code> callback.</p>
  
  <p>Curious if anything is sticking out as to why the blob is empty when downloading or retruning to the context script.</p>
  
  <p>Following the documentation at: <a href="https://developers.google.com/web/updates/2016/01/mediarecorder" rel="nofollow noreferrer">https://developers.google.com/web/updates/2016/01/mediarecorder</a></p>
  
  <p><strong>background.js</strong>   </p>
  
  <pre><code>chrome.tabCapture.capture(captureOptions, function (stream) {
      if (!stream)
          return;
      var recordedChunks = [];
      var options = {
          mimeType: 'video/webm; codecs=vp9',
      };
  
      var mediaRecorder = new MediaRecorder(stream, options);
      mediaRecorder.ondataavailable = function (event) {
          if (event.data.size &gt; 0) {
              recordedChunks.push(event.data);
          }
      }
      mediaRecorder.start();
      setTimeout(function(){
          stopRecording(stream, mediaRecorder, recordedChunks);
      }, 5000);
  })
  
  
   var stopRecording = function (stream, mediaRecorder, recordedChunks) {
     mediaRecorder.stop();
     var blob = new Blob(recordedChunks, {
         type: 'video/webm'
     });
     var url = URL.createObjectURL(blob);
     var a = document.createElement('a');
     document.body.appendChild(a);
     a.style = 'display: none';
     a.href = url;
     a.download = 'test.webm';
     a.click();
     URL.revokeObjectURL(url);
     stream.getVideoTracks()[0].stop();
   };
  </code></pre>