2012-11-10 73 views
2

我有显示在谷歌浏览器一个小图标,简单的Chrome扩展。点击后,它会加载我的网站的搜索页面,该页面会将您重定向到正确的页面。Chrome扩展使用后台页面未正与清单第2版

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

,谷歌正在迫使我更新,而不是1.清单第2版,不过这打破了我的工作的延伸。

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> 

,我需要添加/修改怎么把它与清单第2版的工作?

+0

可能重复[端口错误而改变从清单V1到V2的Chrome扩展程序(http://stackoverflow.com/questions/11913575/port-error-while-changing-chrome -extension-from-manifest-v1-v2) –

回答

8

你只需要从后台页面中删除脚本标签。以下是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 }); 
    }); 
}); 

并在后台删除'page'属性。添加“脚本”属性:

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

它的工作!多谢,伙计。 –

+0

总是乐于帮助 –

+0

我可以知道使用'“背景”:{ “脚本”:“background.js”] }'这行....请我快速响应! –

相关问题