Javascript nofitication创建的chrome扩展api不';不要出现多次

Javascript nofitication创建的chrome扩展api不';不要出现多次,javascript,jquery,google-chrome,google-chrome-extension,Javascript,Jquery,Google Chrome,Google Chrome Extension,我现在正在开发一个Chrome扩展 我想在一定条件下发出通知 我可以显示一次通知消息 但是,一旦通知消息出现,即使我重新加载网页,它也不会再次显示通知消息 我被这个问题困住了 请任何人帮帮我 提前感谢:) manifest.json { "name": "test", "version": "0.1", "manifest_version": 2, "permissions": [ "tabs", "notifications", "http://*/*" ], "backgroun

我现在正在开发一个Chrome扩展

我想在一定条件下发出通知

我可以显示一次通知消息

但是,一旦通知消息出现,即使我重新加载网页,它也不会再次显示通知消息

我被这个问题困住了

请任何人帮帮我

提前感谢:)

manifest.json

{
"name": "test",
"version": "0.1",
"manifest_version": 2,

"permissions": [
    "tabs", "notifications", "http://*/*"
],

"background": {
    "scripts": ["background.js"],
    "persistent": false
},

"content_scripts": [
    {
        "matches": ["http://*/*"],
        "js": ["myscript.js"]
    }
]
}

myscript.js

var message = {
    text:"hello"
}

chrome.runtime.sendMessage(message, function(response) {

});
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {

var test = chrome.notifications.create(
    'notification',{   
        type: 'basic', 
        title: "title",
        message: request.text,
        iconUrl:"icon.png"
        },

    function(notificationId) {

    } 

);


chrome.notifications.onClosed.addListener(function (notificationId, byUser){

        console.log("this doesn't call as well);
});
background.js

var message = {
    text:"hello"
}

chrome.runtime.sendMessage(message, function(response) {

});
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {

var test = chrome.notifications.create(
    'notification',{   
        type: 'basic', 
        title: "title",
        message: request.text,
        iconUrl:"icon.png"
        },

    function(notificationId) {

    } 

);


chrome.notifications.onClosed.addListener(function (notificationId, byUser){

        console.log("this doesn't call as well);
});

未单击通知时,几秒钟后通知将自动隐藏(但不会关闭)。使用现有通知ID再次调用
create
,不会重新创建或显示通知

调用以删除先前创建的ID为“notification”的通知,然后再调用
chrome.notifications.create

var notificationId = 'notification'; // Whatever
chrome.notifications.clear(notificationId, function() {
    chrome.notifications.create(notificationId, ... );
});
谢谢我在create()方法的回调函数中调用了clear()方法,这就是它不起作用的原因。现在我有了create()方法之外的clear()方法,它终于可以工作了!!!