我的谷歌浏览器扩展一直向这个函数抛出错误。
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() {});
}
错误:
在运行 notifications.create 时出现未经检查的 runtime.lastError 错误:缺少某些必需的属性:类型、iconUrl、标题和消息。 位于 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.storage的chrome扩展程序进行了检查,并且它确实存在。
为什么错误是不正确的? :/
chrome.gcm.onMessage.addListener(messageReceived);
chrome.notifications.onButtonClicked.addListener(notificationBtnClicked);