views:

1082

answers:

4

I am trying to create chrome extention, however my browser action click does not work! I've tried pretty much everything. Here is my setup:

manifest.json:

{
"name": "blah",
"version": "1.0",
"description": "blah",
"browser_action": {
  "default_icon": "icon1.png",
  "popup": "popup.html"
 },  
"permissions": [
  "bookmarks",
  "tabs",
  "http://*/*", 
  "https://*/*"    
],
"background_page": "background.html"
}

popup.html:

<html>
<head>
<script>
<!-- Try adding the listener in popup.html  -->
    chrome.browserAction.onClicked.addListener( function(tab){
    console.log("Hello from popup"); // This does not show up either
    } );
 </script>
</head><body>
 Hello
</body>
</html>

background.html:

<html>
<head>
<script>
console.log("Background.html"); // This gets displayed. O.K.

function hello() {
  console.log("HELLO"); // THIS NEVER GETS DISPLAYED
}

// Supposed to Called when the user clicks on the browser action icon.
chrome.browserAction.onClicked.addListener(hello); 
</script>
</head>
</html>

But no matter how hard i click on the Icon nothing happens and "HELLO" is not printed out in the console! I am using Chrome 4.0.249.43. I installed the Beta version BUT it is exactly the same as the released version (same verion number). Could that be a problem?

Any help appreciated.

A: 

According to the doc:

chrome.browserAction.onClicked.addListener(function(Tab tab) {...});

so:

// Supposed to be called when the user clicks on the browser action icon.    
chrome.browserAction.onClicked.addListener(function(tab) {
    hello();
});

should work

RC
Since he never used or called `tab`, and never used context (`this`), this would make no difference...
K Prime
A: 

Are you sure that you're viewing the correct JavaScript console for the background page, and not for the other tab?

Try having your hello() method set a global variable in the background page, then have a button in popup.html retrieve that variable (using chrome.extension.getBackgroundPage()) and display it as an alert.

dmazzoni
Hi, i edited to show that I tried adding the listener to the popup.html and it doesn't work either...
drozzy
+4  A: 

You cannot have a "popup" with an onclick event. Remove the popup.html from the manifest file. And keep the background page, and it will work.

Mohamed Mansour
That is correct. Popup completely eliminates the onclick event! Took me two days to figure that out.
drozzy
A: 

I met the same problem. and after deleted popup.html, clicked handler work well.

Andy.Tsao