1

I'm developing a website using Youtube iframe API, and I would like a Chrome extension (Musixmatch, that I'm not developing myself) to be allowed in the Youtube iframes on my website when used on Google Chrome, for users who have that extension installed, so that they could have the lyrics displayed on the music videos.

It is unclear to me if I would be able to make it happen - is it something that has to be allowed by Musixmatch, or can I actually do something? This question is not specific to the Musixmatch extension. It seems that some Chrome extensions are automatically called by Youtube iframe API, so I thought it might be possible to call specific ones.

I have a hard time finding information about that on the internet. I think this post refers to the same issue, but from the point of view of the Chrome extension developer: https://stackoverflow.com/questions/27739727/how-to-make-chrome-extension-work-in-iframe. Here is a post about Youtube API triggering a specific Chrome extension: Chrome YouTube cast_sender.js console error.

Any help or insight would be appreciated!

Community
  • 1
  • 1
Kaarotte
  • 31
  • 5

2 Answers2

0

I don't think you can do it, since extensions decide themselves when to inject their code, not the other way around. YouTube would not normally "call" any extension, Chromecast being an exception - but it's by Google, YT expects it.

For example, in case of YouTube this logic is probably contained in the match patterns specified in the extension's manifest. Without changing the manifest, you can't "convince" Chrome to inject it to somewhere else.

Alternatively, the checks may be run-time in the code. Again, without changing that, if an extension does not expect to be injected into YT's embed pages it will not be.

Xan
  • 74,770
  • 16
  • 179
  • 206
  • Yeah, when I saw the Chromecast extension calls on my Youtube iframe I started hoping that I could make other extensions work in there - apparently it's not possible :( Thanks! – Kaarotte May 06 '15 at 17:56
-1

I'm not 100% clear on the scope of your question. If you're asking if an extension can access the DOM of an iframe, then the answer is no -- the CSP model very explicitly forbids this. You can do a postMessage to an iframe from an extension (just as you would from the page itself ... using the contentWindow object), but with postMessage you can still only trigger exposed methods, and they're already available via the YouTube iframe API.

If your question is about being able to hear iframe API events and control the player via the iframe API, then yes ... this is possible. You'll need to inject a script into the page that can hear the events and trigger API methods, and that injected script can then talk to your background page to do other things your extension needs to do. there are several SO questions about how to do this ... here's a recent one:

Youtube player API in Chrome extension

Community
  • 1
  • 1
jlmcdonald
  • 13,408
  • 2
  • 54
  • 64
  • Basically I want the extension to work on the Youtube iframe on my website the same way it's working on the Youtube website. If Musixmatch is allowed, it will display the lyrics if I watch a video on Youtube.com; but it won't if I watch it on my website. I'm developing the website containing the Youtube iframe, I'm not developing the extension. My question is: is there something that can be done on my side? I'm still processing your answer but I don't think you answered my question - thanks for the input though, I hope my comment helps you get what my question was. – Kaarotte May 05 '15 at 17:20
  • Ahhh ... got it. So you aren't coding the extension yourself. That does help me know what you're asking, but unfortunately it also leads me to say that this will likely not work the way you want it to; when a YouTube player is in an iframe embedded on someone else's site, it uses a slightly different DOM structure and slightly different API inside the iFrame than the player does when it's on YouTube.com. But the closer you could get to mimicking how things are on YouTube.com, the better you'll be ... for example, YouTube.com gives its player the id "movie_player" and exposes API events there. – jlmcdonald May 05 '15 at 21:39
  • I'll try working in this direction, thanks a lot for the advice – Kaarotte May 06 '15 at 14:15