Skip to content

Instantly share code, notes, and snippets.

@MeoMix
Created July 21, 2015 01:35
Show Gist options
  • Save MeoMix/e4f5c9f2d0c94fb1bc79 to your computer and use it in GitHub Desktop.
Save MeoMix/e4f5c9f2d0c94fb1bc79 to your computer and use it in GitHub Desktop.
// Create the port needed to communicate with the parent extension.
this.initializePort = function() {
this.port = chrome.runtime.connect({
name: 'youTubeIFrameConnectRequest'
});
// The extension can request the *exact* time of YouTube's video player.
// Respond with that value, but also include a timestamp to account for the time it takes to send the postMessage.
this.port.onMessage.addListener(function(message) {
if (message === 'getCurrentTimeHighPrecision') {
var currentTime = this.videoStream === null ? 0 : this.videoStream.currentTime;
this.port.postMessage({
timestamp: performance.now(),
currentTimeHighPrecision: currentTime
});
}
}.bind(this));
}.bind(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment