Monday, 9 September 2013

Chrome Extension: Listening to Events in Background

Chrome Extension: Listening to Events in Background

I am building an extension which uses FireBreath-NPAPI. I require an event
listener running in the background which will trigger a new tab when an
event occurs.
Plugin Architecture:
Background.html: The background page loads the plugin and waits for an
event to occur.
<html><head>
<script src="init.js"></script>
</head>
<body onload="load()">
<object id="plugin0" type="application/x-bohemian" width="300"
height="300"><param name="onload" value="pluginLoaded" /></object>
</body>
</html>
init.js: Once the plugin is loaded, init.js attaches an eventListener and
waits for the event to occur.
function pluginLoaded() {
document.getElementById("plugin0").addEventListener("login",
function(){
//open new tab here.
}
});
But this does not seem to be working.
Temporary solution: For now I inject the plugin object and eventListener
to each page using chrome.tabs.executeScript in content_scripts. But this
creates a lot on instances of the plugin and is not theoretically running
in the background. Anyone knows a way to put eventListener in
background.html?
Thanks in advance!

No comments:

Post a Comment