带有后台页面的Chrome扩展程序不能使用清单版本2 [英] Chrome Extension With Background Page Not Working With Manifest Version 2

查看:118
本文介绍了带有后台页面的Chrome扩展程序不能使用清单版本2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的Chrome扩展程序,它在Google Chrome中显示一个小图标。点击后,它会加载我网站的搜索页面,然后将其重定向到右侧页面。 $ b

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



现在,Google强制我更新为显示版本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__,
图标:{
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>

我需要添加/更改哪些内容才能使用清单版本2?

解决方案

您只需从背景页面中删除脚本标记。以下是background.js(而不是background.html)的样子:

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

在后台移除'page'属性。添加'脚本'属性:

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


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?

解决方案

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

这篇关于带有后台页面的Chrome扩展程序不能使用清单版本2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆