2

I have a simple chrome extension which displays a little icon in Google Chrome. On click, it loads a search page of my site, which in term redirects you to the right page.

https://chrome.google.com/webstore/detail/w3patrol-watch-over-any-w/addcgpijdjacmndaadfgcpbfinagiplm is the extension.

Now, Google is forcing me to update to manifest version 2, instead of 1. But this is breaking my working extension.

In manifest.json I have added manifest_version 2, but since then the icon does not work anymore when I click on it.

{
   "background": {
    "page": "background.html"
    },
   "browser_action": {
      "default_icon": "icon19.png",
      "default_title": "__MSG_default_title__"
   },
   "default_locale": "en",
   "description": "__MSG_description__",
   "icons": {
      "128": "icon128.png",
      "19": "icon19.png",
      "48": "icon48.png"
   },
   "name": "__MSG_name__",
   "permissions": [ "tabs", "http://*.w3patrol.com/" ],
   "update_url": "http://clients2.google.com/service/update2/crx",
   "version": "1.0",
   "manifest_version": 2
}

This is background.html

<script type="text/javascript">
chrome.browserAction.onClicked.addListener(function(tab) {
    chrome.tabs.getSelected(null,function(tab) {
        chrome.tabs.create( { url: "http://w3patrol.com/search.php?q=" +tab.url } );
    });
});

</script>

What do I need to add/change to get it working with manifest version 2?

Mr.Boon
  • 2,024
  • 7
  • 35
  • 48
  • possible duplicate of [Port error while changing chrome extension from manifest v1 to v2](http://stackoverflow.com/questions/11913575/port-error-while-changing-chrome-extension-from-manifest-v1-to-v2) – Rob W Nov 10 '12 at 08:41

1 Answers1

9

You just need to remove the script tag from your background page. Here's how background.js(instead of background.html) should look like:

chrome.browserAction.onClicked.addListener(function(tab) {
    chrome.tabs.getSelected(null,function(tab) {
        chrome.tabs.create( { url: "http://w3patrol.com/search.php?q=" +tab.url } );
    });
});

And remove the 'page' property in background. Add 'scripts' property:

  "background": {
    "scripts": ["background.js"]
  },
Kirill Ivlev
  • 12,310
  • 5
  • 27
  • 31
  • May i know the use of ` "background": { "scripts": ["background.js"] },` this line....please respond me fast!! – PHP dev Jul 02 '15 at 05:47