Apple  Wang
Apple Wang

Reputation: 245

chrome extension about browser action

I want to alert some message when i click the broweraction icon,there is my code,but it doesn't work,can some one help me? thanks!!

manifest.json

{
  "brower_action":{ "default_icon":"test.png"},
  "background_page":"background.html",
  "permissions":["tabs","http://*/*","https://*/"]
}

script.js

chrome.browserAction.onClicked.addListener(function(tab) {
  chrome.tabs.executeScript(
  null, {code:"alert('test')"});
});

background.html

<html>
  <head>
    <script src="background.js"></script>
  </head>
  <body></body>
</html>

Upvotes: 2

Views: 572

Answers (1)

abraham
abraham

Reputation: 47913

All you need in script.js is:

chrome.browserAction.onClicked.addListener(function(tab) {
  alert('test');
});

Upvotes: 1

Related Questions