通常、ブラウザは数時間ごとに拡張機能の更新をチェックします。[拡張機能を今すぐ更新] ボタンをクリックすると、これを手動で上書きできます。これをシームレスにして、拡張機能が利用可能になった瞬間に更新できるようにしたいと考えています。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();
});