javascript - 具有后台页面的 Chrome 扩展程序不适用于 list 版本 2

标签 javascript html google-chrome google-chrome-extension

我有一个简单的 chrome 扩展程序,它在 Google Chrome 中显示一个小图标。点击后,它会加载我网站的搜索页面,这会将您重定向到正确的页面。

https://chrome.google.com/webstore/detail/w3patrol-watch-over-any-w/addcgpijdjacmndaadfgcpbfinagiplm是扩展名。

现在,Google 强制我更新到 list 版本 2,而不是 1。但这会破坏我的工作扩展。

manifest.json 中,我添加了 manifest_version 2,但从那时起,当我点击它时,该图标不再起作用。

{
   "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
}

这是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>

我需要添加/更改什么才能使其与 list 版本 2 一起使用?

最佳答案

您只需要从后台页面中删除脚本标签即可。 background.js(而不是 background.html)应该是这样的:

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

并删除背景中的“页面”属性。添加“脚本”属性:

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

关于javascript - 具有后台页面的 Chrome 扩展程序不适用于 list 版本 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13320499/

相关文章:

javascript - 将溢出的内容从一个 div 转移到另一个 div

javascript - 选择输入框时,屏幕键盘会调整应用程序大小 Apache Cordova Visual Studio?

javascript - Chrome 在“立即购买”按钮上触发双重操作

php - 如何在 Google Chrome 上加载脚本而不阻塞整个页面?

javascript - jQuery 通过带方括号的动态名称选择元素(fiddle incl)

javascript - 如何将 JavaScript 数组传递给 DataTable() 中的函数

javascript - 更改浏览器选项卡会意外触发焦点事件,尤其是在 Google Chrome 中

html - CSS 参数?

mysql - WebSQL 和 MySQL 同步

html - chrome 中选择列表上的滚动条