我的 chrome 扩展一直向这个函数抛出错误
function messageReceived(message) {
// A message is an object with a data property that
// consists of key-value pairs.
// Pop up a notification to show the GCM message.
chrome.notifications.create(getNotificationId(), {
title: message.data.name,
iconUrl: 'assets/img/cat.jpg',
type: 'basic',
message: message.data.prompt,
buttons : [
{ title: "Accept" },
{ title: "Reject" }
]
}, function() {});
}
错误:
Unchecked runtime.lastError while running notifications.create: Some of the required properties are missing: type, iconUrl, title and message. at messageReceived
然而,这些都是真实存在的。每次我添加以下函数时都会出现错误
function notificationBtnClicked(notification, ibtn) {
console.log(notification)
console.log(ibtn)
if (ibtn==0) {
chrome.storage.local.get("name", function(name){
chrome.storage.local.get("email",function(email){
//call other users
var email = email
var name = name
$.ajax({
url: 'some api',
data:'{email:email, name:name}',
ajax:true,
success: function(result)
{
alert(result);
}
});
});
})
}else {
//snooze
}
}
但是,我不明白这是什么问题。我通过下载一些 chrome 扩展程序检查了 chrome.storage,您可以在其中查看它。
为什么错误不正确? :/
chrome.gcm.onMessage.addListener(messageReceived);
chrome.notifications.onButtonClicked.addListener(notificationBtnClicked);
最佳答案
确保所有必需的通知属性都有它们的值。您使用的“iconUrl”必须是数据 URL、blob URL 或与 'notification.create' 所需的扩展程序的 .crx 文件中的资源相关的 URL。方法。请注意您使用的 Chrome 版本。
此外,包括回调并检查 chrome.runtime.lastError
function callback() {
if (chrome.runtime.lastError) {
console.log(chrome.runtime.lastError.message);
} else {
// Tab exists
}
}
关于javascript - Chrome 扩展 - GCM 通知抛出错误但信息存在吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35677913/