Search code examples
javascriptyoutubegruntjsnode-webkit

Node WebKit and YouTube: chrome is not defined


I'm developing an app for Android, iOS, Mac OS and Windows using PhoneGap and Node-WebKit. This application has embedded youtube videos.

These youtube videos are working fine in my Mobile app (Android/iPhone) using PhoneGap, but if I test it on my Mac (building the app using grunt node-webkit builder) I get the following error:

Uncaught ReferenceError: chrome is not defined
www-embed-player.js:184

I tried to check that line and there is some code like:

chrome.cast.requestSession(v(this.Lc,this)

I'm embedding the videos using an iframe:

<iframe src="http://www.youtube.com/embed/rjKRQYmi1Lk" frameborder="0" allowfullscreen="" ></iframe>

Anybody knows how can I solve it?

Thank you!


Solution

  • It looks like this is related to the Chromecast Chrome plugin. I'm assuming you have

    "webkit": {
        "plugin": true
    }
    

    in your manifest for flash, so the Chromecast plugin is also getting loaded. Then when it tries to interact with the YouTube player it fails.

    Try removing the Chromecast plugin to see if this resolves the issue. if so then your options are:

    1. Remove the Chromecast plugin, there isn't a way to only load specific plugins in node-webkit that I'm aware of. This may not be the best solution especially if you are distributing your app.

    2. Use another method to load the YouTube video. I use the JavaScript Player API and I don't have any issues. You can find my example here:

      https://gist.github.com/octalmage/03a054bb27d597a9f095

      And the API reference:

      https://developers.google.com/youtube/js_api_reference#Embedding

    3. Load your HTML over a local webserver. This error seems to be caused by using the file:// protocol so loading your HTML using a local webserver might resolve the issue. I personally use this with method 2 to get past the restricted playback errors (https://cloudup.com/cUXiDgrYBOm) but I'm not sure if it will fix your issue alone.

    Edit: I just realized I get this error with webkit plugin set to false, try setting it to true! The video works for me without any changes when webkit plugin is enabled. The error does flash before the video plays though.

    https://cloudup.com/c6VyHbIyyez