user560913
user560913

Reputation: 315

Listening to NPAPI events in background.html

I am using FireBreath. I want to listen to events in the background.html/background.js and perform actions once an event is recieved.

Here is the code:

background.html

<html><head>

<script src="cons.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>

cons.js

document.getElementById("plugin0").addEventListener("login", function(){
    console.log("chrome extension party!");
}, false);

But when I trigger an event from the NPAPI plugin the console.log message is not getting displayed.

I am able to recieve the event and perform functions when I put it inside a normal html page opened by the plugin(other than backgroundpage) using chrome.tabs.executeScript.

Am I doing something wrong?

Thanks in advance!

Upvotes: 0

Views: 168

Answers (1)

taxilian
taxilian

Reputation: 14324

Most likely you aren't waiting for the plugin to be loaded before you try to add the listener; you can the onload param telling it to run pluginLoaded() when it loads, so try moving your line in cons.js into a function pluginLoaded() { ... }.

Upvotes: 2

Related Questions