参考文档
1.自动升级–扩展开发文档
2.Autoupdating - Google Chrome
配置文件
我们直接在manifest.json中设置update_url
{
…
"update_url": "http://ursb.org/chrome/test/update.php",
…
}
update.php也可以为静态的xml文件地址,不过为了动态更新方便,直接用php读取数据库或者文本等等操作。。
输出的xml文件格式如下:
第一二行不用理解,第三行的
appid为我们的扩展的ID,如何查看?直接生成crx后,拖入扩展程序页面即可看到(需要开发者选项)
然后关键的就是updatecheck这个节点了,codebase为更新的crx文件地址,version为更新的crx版本,这个版本要和crx文件中的版本一致。
更新代码
简单随手写了下,需要的拿去。。
<?php
/*
* Chrome升级xml类
* by Holger
* at 2014-10-06
*/
class ChromeUpdate{
protected $aid = "";
protected $crx = "";
protected $ver = "";
function __construct($appId, $crxUrl, $version){
$this->aid = $appId;
$this->crx = $crxUrl;
$this->ver = $version;
}
function show(){
header("Content-Type: text/xml;");
$dom = new DOMDocument("1.0", "UTF-8");
$gup = $dom->createElement("gupdate");
$app = $dom->createElement("app");
$chk = $dom->createElement("updatecheck");
$gup->setAttribute("xmlns", "http://www.google.com/update2/response");
$gup->setAttribute("protocol", "2.0");
$app->setAttribute("appid", $this->aid);
$chk->setAttribute("codebase", $this->crx);
$chk->setAttribute("version", $this->ver);
$app->appendChild($chk);
$gup->appendChild($app);
$dom->appendChild($gup);
echo $dom->saveXML();
}
}
?>