为什么我的Chrome扩展不能自动更新? [英] Why isn't my chrome extension auto-updating itself?

查看:246
本文介绍了为什么我的Chrome扩展不能自动更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一个非常基本的Chrome扩展,并设置了一个简单的node.js服务器来测试自动更新功能。服务器托管.crx文件,因此我可以通过访问 http:// localhost:3000 / clients / chrome / extension.crx 来安装扩展程序。但是,当我转到工具 - > 扩展并单击现在更新扩展名,扩展名不会获取新版本。服务器确实收到对 localhost:3000 / clients / chrome / updates.xml 的请求,但没有收到任何对新扩展名.crx文件的请求。我在这里做错了什么?




CODE

让我直接引导您完成代码的重现:

$ tree

 
| - 客户
| ` - chrome
| | - 扩展名
| | ` - manifest.json
| | - extension.crx
| | - extension.pem
| ` - updates.xml
` - web.js

扩展实际上只是清单文件。

manifest.json

 <$ c 
name:测试自动更新,
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());
$ b $ * ROUTES * /

app.get('/ clients / chrome / extension.crx',函数(请求,响应)
{
response.contentType('application / x-chrome-extension');
response.sendfile('clients / chrome / extension.crx');
});
$ b app.get('/ clients / chrome / updates.xml',函数(请求,响应)
{
response.sendfile('clients / chrome / updates.xml ');
});

/ * ROUTES END * /

var port = process.env.PORT || 3000;
$ b app.listen(port,function(){
console.log(Listening on+ port);
});

好的,我们来测试一下。首先,启动服务器:

$ node web.js
$ b

 听取3000 

通过访问 HTTP://本地主机:3000 /客户/铬/ extension.crx 。这部分工作完美的第一次尝试。服务器记录请求:

  127.0.0.1  -   -  [Thu,26 Apr 2012 22:25:47 GMT]GET /clients/chrome/extension.crx HTTP / 1.1304  -  - Mozilla / 5.0(X11; Linux x86_64)AppleWebKit / 535.19(KHTML,如Gecko)Ubuntu / 11.10 Chromium / 18.0.1025.151 Chrome / 18.0.1025.151 Safari /535.19

让我们修改扩展名:


  1. 在manifest.json中,将 version 设置为1.1(intead of 1.0)。
  2. .xml,将 version 设置为1.1(而不是1.0)。 使用相同的 extention.pem 文件。

  3. 创建新的 extension.crx 文件。 / li>
  4. 点击工具 - > 扩展 - > 现在更新扩展程序

预计在<$ c $中将扩展的版本号更改为1.1 c> Tools - > Extensions



相反,没有任何反应。服务器接收到对 updates.xml 的请求,但是对于 extension.crx

解决方案

我认为错误在于您的web.js文件如何为 updates.xml 提供服务。这是我的推理:


  • 我重复了您的设置,并且看到了同样的缺少更新。我做了第二次测试,只使用了我的公共Dropbox文件夹,并且一切都进行的很顺利。
  • 最后,我做了两个更多的测试:一个使用节点托管的更新.xml 指向Dropbox托管的文件,另一个指向托管节点的crx文件的Dropbox托管 updates.xml


结果是,无论何时由Node提供 updates.xml ,Chrome都不会不会正确更新扩展名,当 updates.xml 由Dropbox托管时,无论托管crx文件的人是谁,一切正常。 (并且我更改了清单中的 update_url ,并重建/上传了每个试用版的扩展程序)。

正确为什么发生这种事情对我来说仍然是一个非常大的谜团。以下是我在Chrome中获取 updates.xml 时获得的HTTP响应标头(通常使用地址栏;我不嗅探更新操作中的实际净流量,只是模拟它):

Dropbox:

  HTTP / 1.1 200 OK 
服务器:nginx / 1.0.14
日期:...
Content-Type:application / xml
Transfer-Encoding:chunked
连接:保持活动
x-robots-tag:noindex,nofollow
etag:...
pragma:public
cache-control:max-age = 0
Content-Encoding:gzip

Node.js:

  HTTP / 1.1 200 OK 
X-Powered-By:Express
Content-Type:application / xml
日期:...
Cache-Control:public,max-age = 0
Last-Modified:...
ETag:...
Accept-Ranges:bytes
Content-Length:284
Connection:keep-alive



<我也认为这可能是一个端口问题(也许是Chrome d不想从非80端口更新?),而现在我刚刚发现从端口80上的我自己的Apache服务器为 updates.xml 和crx文件提供服务导致破坏与Node中观察到的问题相同。



我希望我有一个真正的答案,但也许您可以使用Dropbox运行一些测试并最终发现它们的重新采取不同的行动,让Chrome成为他们的更新文件。


I made a really basic chrome extension and set up a simple node.js server to test the auto-update feature. The server hosts the .crx file so I can install the extension without any trouble simply by visiting http://localhost:3000/clients/chrome/extension.crx. But when I go to tools->extensions and click on Update extensions now, the extension does not fetch the new version. The server does receive the request for localhost:3000/clients/chrome/updates.xml, but doesn't receive any request for the new extension.crx file. What am I doing wrong here?


CODE

Let me just walk you through the code to make this reproductible:

$ tree

.
|-- clients
|   `-- chrome
|       |-- extension
|       |   `-- manifest.json
|       |-- extension.crx
|       |-- extension.pem
|       `-- updates.xml
`-- web.js

The extension is really just a manifest file.

manifest.json

{
  "name": "testing auto-updates",
  "version": "1.0",
  "update_url": "http://localhost:3000/clients/chrome/updates.xml"
 }

As you can see, I'm referring to an update_url to make auto-updating possible.

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>

Packaging the extension creates extension.crx and extension.pem.

I also made a simple node.js server to serve the files:

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);
});

Ok, let's test this. First, start the server:

$ node web.js

Listening on 3000

Install the extension by visiting http://localhost:3000/clients/chrome/extension.crx. This part works perfectly on the first try. The server logs the request:

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"

Let's modify the extension:

  1. In manifest.json, set version to 1.1 (intead of 1.0).
  2. In updates.xml, set version to 1.1 (instead of 1.0).
  3. Re-pack extension using the same extention.pem file as the first time.
  4. The new extension.crx file is created.
  5. Click on Tools->Extensions->Update extensions now

One would expect to see the extension's version number change to 1.1 in Tools->Extensions.

Instead, nothing happens. The server receives a request for updates.xml but not for extension.crx.

解决方案

I think the error lies in how your web.js file serves updates.xml. Here's my reasoning:

  • I duplicated your setup and saw the same lack of updates.
  • Then I did a second test, using only my public Dropbox folder, and everything went perfectly.
  • Finally, I did two more tests: one with a Node-hosted updates.xml pointing to a Dropbox-hosted file, and another with a Dropbox-hosted updates.xml pointing to a Node-hosted crx file.

The results was that whenever updates.xml was served by Node, Chrome didn't update the extension correctly, and when updates.xml was hosted by Dropbox, everything when fine, regardless of who hosted the crx file. (And I did change the update_url in the manifest and rebuilt/uploaded the extension for each trial).

Exactly why this happens is still a pretty big mystery to me. Here are the HTTP response headers I get when I fetch updates.xml in Chrome (normally, using the address bar; I'm not sniffing the actual net traffic from the update operation, just simulating it):

Dropbox:

HTTP/1.1 200 OK
Server: nginx/1.0.14
Date: ...
Content-Type: application/xml
Transfer-Encoding: chunked
Connection: keep-alive
x-robots-tag: noindex,nofollow
etag: ...
pragma: public
cache-control: max-age=0
Content-Encoding: gzip

Node.js:

HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: application/xml
Date: ...
Cache-Control: public, max-age=0
Last-Modified: ...
ETag: "..."
Accept-Ranges: bytes
Content-Length: 284
Connection: keep-alive

I thought also it might be a problem with ports (maybe Chrome doesn't like to update from non-80 ports?), and I've now just discovered that serving updates.xml and crx file from my own Apache server on port 80 causes breakage identical to the problem observed with Node.

I wish I had an actual answer for you, but maybe you can run some tests with Dropbox and finally discover what they're doing differently that makes Chrome like their update file.

这篇关于为什么我的Chrome扩展不能自动更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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