我如何向安装了扩展程序的每个人发送通知?
我正在使用,new Notification(...)
但通知只是为我发送。
感谢你所做的一切
好吧,这需要扩展中已经完成的许多工作,才能在不更新扩展的情况下做到这一点。
例如,您的扩展程序可以定期在您的网站上查找新的通知。
如果需要更紧急,则需要保持与服务器的WebSocket连接,或者使用某种方式的推送服务,例如gcm
Max Worg刚才提到的API 。
这就是说,用这一切,你需要得到大家的支持已经到位在扩展。
好的,但是假设您没有这种支持,或者不需要那么频繁。
通常的做法是使用扩展程序更新,在该更新程序中,您将为用户添加一条消息,并使用“发行说明”版本增加一个变量,以便该变量仅显示一次。一个好主意是为此使用chrome.storage.sync
,这样就不会多次使用户烦恼。
var message = "Sup user, check this out!";
var message_version = 4; // Update this when you want to show a new one
chrome.storage.sync.get(
{message_version: 0}, // Provide default
function(data) {
if(data.message_version < message_version) {
notify(message); // TODO: implement notify()
// Alternatively, open a page with the notice with chrome.tabs.create()
chrome.storage.sync.set({message_version: message_version});
}
}
);
你可以看到一个真实的例子在这里(使用的混合localStorage
和chrome.storage
)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句