如何让谷歌PageAction示例扩展在谷歌Chrome上运行
How to get the google PageAction sample extension working on Google Chrome as supplied?
这可能是我在做一些愚蠢的事情,但我不知道是什么。我正在尝试让一个示例谷歌Chrome页面扩展演示工作。演示的来源可以在这里找到:http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extensions/docs/examples/api/pageAction/
这是一个简单的程序,有两个代码文件——manifest和一个background.js文件。这是背景.js:
// Called when the url of a tab changes.
function checkForValidUrl(tabId, changeInfo, tab) {
// If the letter 'g' is found in the tab's URL...
if (tab.url.indexOf('g') > -1) {
// ... show the page action.
chrome.pageAction.show(tabId);
}
};
// Listen for any changes to the URL of any tab.
chrome.tabs.onUpdated.addListener(checkForValidUrl);
这是manifest.json文件:
{
"name": "Page action by URL",
"version": "1.0",
"description": "Shows a page action for urls which have the letter 'g' in them.",
"background": { "scripts": ["background.js"] },
"page_action" :
{
"default_icon" : "icon-19.png",
"default_title" : "There's a 'G' in this URL!"
},
"permissions" : [
"tabs"
],
"icons" : {
"48" : "icon-48.png",
"128" : "icon-128.png"
},
"manifest_version": 2
}
正如所写的,这段代码对我不起作用。Chrome加载扩展插件很好,但当我导航到URL中有g的页面时,没有图标显示。
我找到了这个答案:如何为特定页面显示page_action?
所以我尝试了以下-
创建了一个background.html文件:
<html><head><script> ... cut and pasted contents of background.js above </script></head></html>
将manifest.json更改为manifest_version:1,而不是manifest_version:2
- 将manifest.json中的background属性更改为background_page:"background.html"
这非常有效。
但是我绝对不能用background.js文件和manifest_version=2来运行这个东西。
所以我想知道如何使用manifest_version=2和background.js文件。此外,这甚至很重要吗?也就是说,每个人都只是使用manifest_version=1,而不担心这类事情吗?
您使用的是什么版本的Chrome?我19岁了,一切都很顺利。这些新的背景选项在18岁时出现,因此该示例确实应该使用minimum_chrome_version
键来避免这个问题。如果非trunk文档没有指向在这些文档所使用的Chrome版本中不起作用的示例,那也会很好。
http://code.google.com/chrome/extensions/trunk/manifestVersion.html
这个页面上写着。。。。
不建议在Chrome 17或更低版本中设置manifest_version 2。如果您的扩展需要在旧版本的Chrome中工作,请坚持目前是版本1。我们之前会给你充分的警告版本1停止工作。
有点傻,是吗?如果他们的Chrome版本是预清单版本2,为什么我们不能有后台和后台页面作为依据?。。。我试过了,它抱怨background_page不适用于manifest版本2,也没有安装它。所以你可能想暂时推迟使用manifest版2
尽管阅读这些版本2的文档并开始使用它将要强制执行的一些实践(例如没有内联脚本)是一个很好的主意。
另一个可能导致此问题的因素:
我遇到这个问题是因为我忘记按照示例在清单中包含declarativeContent权限。
希望这能帮助到别人。。。
- .scroll()函数在上次更新后在谷歌chrome中定位闪烁
- 如何让JS脚本在导航后继续运行(谷歌chrome控制台)
- 如何知道你右键点击谷歌chrome扩展是什么
- 对齐底部的DIV-谷歌Chrome扩展
- 当我用ctrl+p搜索时,为什么要在谷歌chrome上使用inspect来调试缺少显示文件js
- 从谷歌chrome中的任何网页获取所有tel标签
- 如何缩小我的谷歌chrome扩展's的javascript文件
- 当页面加载时,使谷歌chrome浏览器成为全屏浏览器
- 谷歌Chrome元素仍然存在:即使从光标移开,也要悬停
- 谷歌Chrome Chrome.usb/Chrome.hid锁定设备
- 我的jquery代码在谷歌chrome控制台中工作,而不是在保存它之后
- 谷歌Chrome扩展在用Javascript打开的弹出窗口中工作吗
- 基本的谷歌chrome扩展消息传递不起作用
- 如何操作谷歌chrome's PRINT选项
- 谷歌Chrome在范围滑块禁用时卡住了's的更改功能
- 谷歌Chrome日期选择器事件
- 如何允许在谷歌chrome中通过触摸屏放大和缩小iframe
- 谷歌chrome和FPS的奇怪行为
- 点击时禁用提交按钮,将阻止表单在谷歌Chrome上提交
- AngularJS-谷歌Chrome扩展中的动态链接断开