noitification创建的chrome扩展api没有;不要出现不止一次

nofitication created chrome extension api doesn't appear more than once

本文关键字:不止一次 没有 创建 chrome 扩展 api noitification      更新时间:2023-09-26

我现在正在开发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) {
});

background.js

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不会重新创建或显示通知。

在调用chrome.notifications.create:之前,调用chrome.notifications.clear以删除以前创建的ID为"notification"的通知。

var notificationId = 'notification'; // Whatever
chrome.notifications.clear(notificationId, function() {
    chrome.notifications.create(notificationId, ... );
});