Naman
Naman

Reputation: 2669

Chrome extension background page not adding new tab?

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 });
});

Upvotes: 0

Views: 370

Answers (1)

Kirween
Kirween

Reputation: 1538

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 });
});

Upvotes: 1

Related Questions