Chrome extension: creating a new tab after clicking on a notification

function notify(notifyMessage) {
    var options = {
        type: "basic",
        title: "My Extension",
        message: notifyMessage,
        iconUrl: "hello.png"
      };
    chrome.notifications.create("", options, function(notificationId) {
      setTimeout(function(){
        chrome.notifications.clear(notificationId, function(){});
      }, 2000);
    });
    chrome.notifications.onClicked.addListener(function(notificationId, byUser) {
        chrome.tabs.create({url: "http://www.google.com"});
    });
}

With this function, when I run notifyfor the first time and click on the notification, it creates one tab. When I run it a second time and click, it creates two tabs, etc. How can I reorganize my code to create only one tab each time?

+4
source share
1 answer

chrome.notifications.onClicked.addListener onclick , . onclick : 3 , 3 , .

, , onclick.

: , , , , , .

chrome.notifications.create. "", .

+8

Source: https://habr.com/ru/post/1545276/


All Articles