Reputation: 25870
Usually, the browser checks for extension updates every few hours and you can manually override this by clicking the "update extensions now" button. I want to make this seamless and give my extension the ability to update the moment one is available. Via Ajax, it checks worth the server and knows an update is available. I want it to them tell the browser to update it. Is this possible?
This is a packaged extension that is hosted externally: http://developer.chrome.com/dev/extensions/hosting.html
UPDATE: This is the working code!
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 (the content script that listens for document click and tells background to update)
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 (the background script)
//You need to put reload in this callback
chrome.runtime.onUpdateAvailable.addListener(function(details) {
console.log("updating to version " + details.version);
chrome.runtime.reload();
});
Upvotes: 1
Views: 356
Reputation: 8201
Have you tried using chrome.runtime.requestUpdateCheck()
? Your code could be something like this:
chrome.runtime.requestUpdateCheck(function(status,details){});
chrome.runtime.onUpdateAvailable(function(details){
console.log('Updating to version: ' + details.version);
chrome.runtime.reload();
});
Upvotes: 2