samedi 8 octobre 2016

Chrome extension content script - App is not defined on Ember site

I'm writing a simple Google Chrome extension for twitch.tv channels. The only feature I need is to send a chat message, preferably without using the chat textbox and button explicitly.

By looking through the source code of BetterTTV addon I found the function responsible for sending chat messages:

App.__container__.lookup('controller:chat').currentRoom.tmiRoom.sendMessage('test message');

Now, when I execute this using the console in Chrome DevTools, it works perfectly fine.

However, using it from the extension's content script throws: script1.js:28 Uncaught ReferenceError: App is not defined

The same situation goes when trying to use window.Ember (works in the console, throws not defined in content script).

Just in case, here's the whole test code of content script:

$(document).ready(function() {
    setTimeout(function() {
        main();
    }, 5000);
});

function main() {
    var tmi = App.__container__.lookup('controller:chat').currentRoom;

    tmi.tmiRoom.sendMessage('TEST'); 
}


Although I have some experience in chrome extensions, I've never had to deal with anything about Ember.js. Also I haven't found any similar problems whatsoever.




Aucun commentaire:

Enregistrer un commentaire