代码
让我带你走一遍这段代码,以便使其可重现:
$ tree
.
|-- clients
| `-- chrome
| |-- extension
| | `-- manifest.json
| |-- extension.crx
| |-- extension.pem
| `-- updates.xml
`-- web.js
这个扩展实际上只是一个清单文件。
manifest.json
{
"name": "testing auto-updates",
"version": "1.0",
"update_url": "http://localhost:3000/clients/chrome/updates.xml"
}
如您所见,我是在引用一个update_url以实现自动更新的功能。
updates.xml
<?xml version='1.0' encoding='UTF-8'?>
<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>
<app appid='fkphbmkcjefhhnnlhhjlnkellidponel'>
<updatecheck codebase='http://localhost:3000/clients/chrome/extension.crx' version='1.0' />
</app>
</gupdate>
打包扩展会创建extension.crx和extension.pem。
我还制作了一个简单的node.js服务器来提供这些文件:
web.js
var express = require('express');
var app = express.createServer(express.logger());
/* ROUTES */
app.get('/clients/chrome/extension.crx', function(request, response)
{
response.contentType('application/x-chrome-extension');
response.sendfile('clients/chrome/extension.crx');
});
app.get('/clients/chrome/updates.xml', function(request, response)
{
response.sendfile('clients/chrome/updates.xml');
});
/* ROUTES END */
var port = process.env.PORT || 3000;
app.listen(port, function() {
console.log("Listening on " + port);
});
好的,让我们来测试一下。首先,启动服务器:
$ node web.js
Listening on 3000
通过访问http://localhost:3000/clients/chrome/extension.crx来安装扩展。第一次尝试此部分完美地运作。服务器记录了请求:
127.0.0.1 - - [Thu, 26 Apr 2012 22:25:47 GMT] "GET /clients/chrome/extension.crx HTTP/1.1" 304 - "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.19 (KHTML, like Gecko) Ubuntu/11.10 Chromium/18.0.1025.151 Chrome/18.0.1025.151 Safari/535.19"
让我们修改扩展:
- 在 manifest.json 中,将
version
设置为 1.1(而不是 1.0)。 - 在 updates.xml 中,将
version
设置为 1.1(而不是 1.0)。 - 使用与第一次相同的
extention.pem
文件重新打包扩展。 - 创建新的
extension.crx
文件。 - 单击
工具
->扩展程序
->立即更新扩展程序
人们期望在 工具
->扩展程序
中看到扩展的版本号更改为 1.1。
但实际上,什么都没有发生。服务器收到了对 updates.xml
的请求,但没有收到对 extension.crx
的请求。