erkserkserks / h264ify

A Chrome extension that makes YouTube stream H.264 videos instead of VP8/VP9 videos
MIT License
1.02k stars 113 forks source link

Embed Into Website #31

Open Adam759 opened 7 years ago

Adam759 commented 7 years ago

Hello,

I am a developer of a game addon which uses YouTube embedded player as its video player. We host the embedded player on a site on GitHub Pages. However, the game in which it plays has a very outdated chromium that is very glitchy with any

<head>

<script>
function inject () {
console.log("MP4 / WEBM DISABLE RAN");
  // return a custom MIME type checker that can defer to the original function
  function makeModifiedTypeChecker(origChecker) {
    // Check if a video type is allowed
    return function (type) {
      if (type === undefined) return '';
      var disallowed_types = ['webm', 'vp8', 'vp9', 'mp4', 'video/mp4', 'avc1'];
      // If video type is in disallowed_types, say we don't support them
      for (var i = 0; i < disallowed_types.length; i++) {
        if (type.indexOf(disallowed_types[i]) !== -1) return '';
      }
      // Otherwise, ask the browser
      return origChecker(type);
    };
  }
  // Override video element canPlayType() function
  var videoElem = document.createElement('video');
  var origCanPlayType = videoElem.canPlayType.bind(videoElem);
  videoElem.__proto__.canPlayType = makeModifiedTypeChecker(origCanPlayType);
  // Override media source extension isTypeSupported() function
  var mse = window.MediaSource;
  // Check for MSE support before use
  if (mse === undefined) return;
  var origIsTypeSupported = mse.isTypeSupported.bind(mse);
  mse.isTypeSupported = makeModifiedTypeChecker(origIsTypeSupported);
}

inject();
</script>
</head>

By debugging and placing console.logs I have verified that it does indeed run, but it does not disable the video types. It works when in the addon but not embedded on the website, it is the same browser as well. Any help would be greatly appreciated!

Adam759 commented 7 years ago

I just realized something crucial: the code gets injected into the iframe of the YouTube player. Upon trying to get it to inject into the iframe of the embedded player, I found unfortunately that the same origin policy kicked in. Does anyone know of a way to get around this and still force an injection into the iframe? If so it would be tremendously helpful.