Chrome Extension With Background Page Not Working With Manifest Version 2

后端 未结 1 1959
难免孤独
难免孤独 2021-01-15 05:35

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.

1条回答
  •  执念已碎
    2021-01-15 06:01

    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"]
      },
    

    0 讨论(0)
提交回复
热议问题