title: How do I set the volume of a Youtube video?
body: <p>I'm creating an extension that mutes the autoplay video when you navigate to a Youtube channel. It's able to execute content.js when navigating to a Youtube channel and select the video, but how can I set the video's volume? Setting video.volume = 0 does not work like I thought it would.</p>
  
  <p>Background script:</p>
  
  <pre class="lang-js prettyprint-override"><code>'use strict';
  
  chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
  
      if (changeInfo.status == 'complete') {
          const site = tab.url.split('/');
  
          let domain = site[2];
          let page = site[3];
  
          if (page === 'channel' || page === 'user') {
              chrome.tabs.sendMessage(tab.id, {'message': 'loaded_channel_page'});
          }
      }
  });
  </code></pre>
  
  <p>Content script:</p>
  
  <pre class="lang-js prettyprint-override"><code>chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
  
      if (request.message === 'loaded_channel_page' || document.readyState != 'loading') {
  
          let newVolume = 0;
  
          document.addEventListener('yt-navigate-finish', () =&gt; {
              setTimeout(mute, 2000);
          });
  
          function mute() {
              let video = document.querySelector('.html5-main-video');
              video.volume = newVolume;
          }
      }
  })
  </code></pre>