有没有办法让打包的托管chrome扩展程序请求Chrome更新呢?

时间:2013-06-05 15:53:17

标签: google-chrome web-applications google-chrome-extension

通常,浏览器会每隔几个小时检查一次扩展程序更新,您可以通过单击"立即更新扩展程序来手动覆盖此更新。按钮。我想让它无缝化,并让我的扩展能够更新可用的时刻。通过Ajax,它检查值得服务器,并知道有可用的更新。我想让它们告诉浏览器更新它。这可能吗?

这是外部托管的打包扩展程序:http://developer.chrome.com/dev/extensions/hosting.html

更新:这是正常工作的代码!

的index.html

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Hello World</title>
    <link href="styles/main.css" rel="stylesheet">
    <script src="test.js"></script>
</head>
<body>
    <h1>Hello, World 2 again 17!</h1>
</body>
</html>

test.js(侦听文档点击并告诉后台更新的内容脚本)

window.onload = function()
{
    document.body.onclick = function()
    {
        chrome.runtime.requestUpdateCheck(function(status) {
                if (status == "update_available") {
                    console.log("update pending...");
                } else if (status == "no_update") {
                    console.log("no update found");
                } else if (status == "throttled") {
                    console.log("Oops, I'm asking too frequently - I need to back off.");
                }
        });
    }
}

main.js(后台脚本)

//You need to put reload in this callback
chrome.runtime.onUpdateAvailable.addListener(function(details) {
  console.log("updating to version " + details.version);
  chrome.runtime.reload();
});

1 个答案:

答案 0 :(得分:2)

您是否尝试过使用chrome.runtime.requestUpdateCheck()?你的代码可能是这样的:

chrome.runtime.requestUpdateCheck(function(status,details){});
chrome.runtime.onUpdateAvailable(function(details){
    console.log('Updating to version: ' + details.version);
    chrome.runtime.reload();
});
相关问题