0

I have written a sample extension to just add new tab to chrome in background page. It's not working. I am new to chrome extension, can you please help me?

manifest.json

{
  "manifest_version": 2,

  "name": "My extension",
  "description": "Test Extension.",
  "version": "1.0",
  "background": {
   "page": "bg.html"
   },

  "permissions": [
    "history",
    "tabs"
  ],
  "browser_action": {
    "default_icon": "icon.png"
  }
}

bg.html

chrome.browserAction.onClicked.addListener(function(activeTab)
{
    var newURL = "www.google.com";
    chrome.tabs.create({ url: newURL });
});
Naman
  • 2,569
  • 4
  • 27
  • 44

1 Answers1

1

Try to rename bg.html to bg.js and change manifest background declaration like this

manifest.json:

  ...
  "background": {
    "scripts": ["bg.js"]
  },
  ...

bg.js:

chrome.browserAction.onClicked.addListener(function(activeTab)
{
    var newURL = "www.google.com";
    chrome.tabs.create({ url: newURL });
});
Kirween
  • 1,472
  • 1
  • 19
  • 24
  • Thanks for help. I am new to this. Can you help me as why was java script required? Why it didn't work with a simple html background page as suggested in http://stackoverflow.com/questions/3188384/google-chrome-extensions-open-new-tab-when-clicking-a-toolbar-icon – Naman Feb 18 '14 at 16:19
  • Inline javascript is not allowed in html background page. You can use script tag `` and keep your manifest declaration with `"page"` – Kirween Feb 18 '14 at 16:34