title: Get current time of Youtube Video on youtube.com (e.g. document.getElementById('movie_player').getCurrentTime())
body: <p>I'm creating a Google Chrome extension that relies on knowing the current time of a video being played on 'youtube.com'. I know, in principle, that <code>document.getElementById('movie_player').getCurrentTime()</code> should return this, but invoking this in a content script injected into the page produces:</p>
  
  <blockquote>
    <p>Uncaught TypeError:
    document.getElementById('movie_player').getCurrentTime is not a
    function(…)</p>
  </blockquote>
  
  <p>I am able to run the command in the Chrome console and get a proper return value.</p>
  
  <p>And before this is flagged up as a duplicate question, I want to point out that I'm talking about doing this on 'youtube.com'. I dont know if I should expect special behavior, but this is definitely a different context than other questions I've found on stackoverflow.</p>
  
  <p>To help, below is the simplest code I could come up with to reproduce this problem. To get it working, you'll need to <a href="https://developer.chrome.com/extensions/getstarted#unpacked" rel="noreferrer">load this as an unpacked extension</a>. Then navigate to any youtube video. Click on the extension icon and click the "Start The Test" button. Also make sure you have the console open (<kbd>F12</kbd>).</p>
  
  <p>Thanks in advance for suggestions for how to make this method work, or another way I can get the info I need (e.g. I looked into getting the share at time value but couldnt figure that one out). As a last resort, I'm considering replacing the youtube player with my own iframe and trying that way.</p>
  
  <p>popup.html</p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;title&gt;Getting Started Extension's Popup&lt;/title&gt;
      &lt;script src='popup.js'&gt;&lt;/script&gt;
  
    &lt;/head&gt;
    &lt;body&gt;
      &lt;input type='button' id='start' value='Start The Test'&gt;&lt;/input&gt;
      &lt;p id="messages"&gt;&lt;/p&gt;
      &lt;p id="result"&gt;&lt;/p&gt;
    &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p>popup.js</p>
  
  <pre><code>// Add listener for start button
  document.addEventListener('DOMContentLoaded', function() {
      document.getElementById("start").addEventListener('click', process_video);
  });
  
  
  function process_video() {
      chrome.tabs.executeScript(null, {file: 'test.js'});
  }
  </code></pre>
  
  <p>test.js</p>
  
  <pre><code>player = document.getElementById('movie_player');
  console.log(player);
  console.log(player.getCurrentTime()); // ERROR IN QUESTION IS PRODUCED WITH THIS COMMAND
  </code></pre>
  
  <p>manifest.json</p>
  
  <pre><code>{
    "manifest_version": 2,
  
    "name": "It's a placeholder",
    "description": "This is only a test",
    "version": "1.0",
  
    "browser_action": {
      "default_popup": "popup.html",
      "default_title": "My Test"
    },
  
    "permissions": [
      "activeTab",
      "http://localhost/*",
      "https://www.youtube.com/*"
    ]
  
  }
  </code></pre>