Vincent M.
Vincent M.

Reputation: 156

Use chromecast inside chrome extension

I am trying to developp an extension to add chromecast capabilities to a website that doesn't support it. The idea is to inject in the page the require javascript code to modify a default html 5 player with a one that support chromecast. I am trying using CastVideos-chrome and CastHelloVideo-chrome from github.

I first download the cast_sender.js and inject it with content_scripts directive in the manifest.json of my extension. I can see in the javascript console the message "Found cast extension: boadgeojelhgndaghljhdicfkmllpafd ". I then add a second a second javascript file using again content_scripts directive which is largly inspire by example codes from github. The code is block in :

if (!chrome.cast || !chrome.cast.isAvailable) {
  setTimeout(this.initializeCastPlayer.bind(this), 1000);
  return;
}

I add debug to see value of chrome.cast and chrome.cast.isAvailable. chrome.cast contains lot of information generated by cast_send.js and

<script>src=​"chrome-extension:​/​/​boadgeojelhgndaghljhdicfkmllpafd/​cast_sender.js">​</script>

​is injected in the website code but chrome.cast.isAvailable is never defined.

Is there some limitation to use chromecast inside a extension and is there to achieve what I want ?

Upvotes: 3

Views: 651

Answers (2)

T.CK
T.CK

Reputation: 421

The first thing I noticed was the syntax. Change the following:

<script>src=​"chrome-extension:​/​/​boadgeojelhgndaghljhdicfkmllpafd/​cast_sender.js">​</script>

To:

<script src="chrome-extension:​/​/​boadgeojelhgndaghljhdicfkmllpafd/​cast_sender.js" type="text/javascript"></script>

Upvotes: 0

kalman
kalman

Reputation: 654

It looks like you might be dealing with 2 different JS worlds here, the world of the page (main world) and the world of the extension (content script).

See https://developer.chrome.com/extensions/content_scripts#execution-environment

Upvotes: 1

Related Questions