Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome Browser Action click not working

I am trying to create chrome extension, 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?

like image 490
Andriy Drozdyuk Avatar asked Dec 21 '09 05:12

Andriy Drozdyuk


People also ask

What is browser action onclicked event?

browser​Action​.onClicked:- Fired when a browser action icon is clicked. This event will not fire if the browser action has a popup. Show activity on this post. I had some problems too while trying to create a chrome extension. Make sure you reload the extension after any change to the manifest.json or the background page.

How do I enable right click on Chrome extensions?

Browser Extensions Click on “Add to Chrome” button to install the extension on your browser. After installing, open the webpage and click on the extension icon on the address bar. Select, “Enable Right Click” option to copy the content from the webpage with right-click.

Should I use browser action icons?

Don't use browser actions for features that make sense for only a few pages. Use page actions instead. Do use big, colorful icons that make the most of the 16x16-dip space. Browser action icons should seem a little bigger and heavier than page action icons.

How do I use the chrome action API?

In order to use the chrome.action API, you need to specify a "manifest_version" of 3 or higher and include the action key in your manifest file. ... ... Each of these values is optional; an empty dictionary is technically allowed. These properties are described more below. The icon is the main image used in the toolbar button.


1 Answers

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.

like image 102
Mohamed Mansour Avatar answered Sep 18 '22 15:09

Mohamed Mansour