0

I have created a simple addon which bookmarks the active tab in a specific folder when clicked. The addon is consisted of two .js files, the background.js and the popup.js. The background.js does the heavy work and sends some date values to the popup.js after the bookmarking is done, which then displays them in a popup window. it also displays an 'OK' text on the addon button. After 2 seconds both the popup window and the button text clear out automatically. Everything works fine, the bookmarking and when showing and closing the popup and the badge.

Here is the problem though. If I happen to close the popup window during those 2 seconds by clicking anywhere in the page or the browser, the badge text doesnt clear out. Until I click the button again next time and repeat the process by letting the popup close by itself this time, then the text clears out.

So what causes this and how can I fix it? I need to clear out the badge text, even if I manually close the popup window during those 2 seconds.

here is the code for the popup.js

// Listener calls background 
document.addEventListener("DOMContentLoaded", function () {
    backGround = chrome.extension.getBackgroundPage();    
    backGround.browserOnClickAxn(insertText);
});


// Set text   
function insertText (msg) {
    var message = "To find your saved tabs, look in the folder ";
    message = message + "<br>";
    message = message + "<strong>";
    message = message + "\""+msg+"\"";
    message = message + "</strong>";
    message = message + "<br><br>";
    message = message + " under ";
    message = message + "<br>";
    message = message + "<strong>";
    message = message + "\"Other Bookmarks/BOOKMARKS/VARIOUS\""; 
    message = message + "</strong>";  
    message = message + "<br><br>"; 
    document.getElementById('msg').innerHTML = message;   
    setBadgeText('OK!');
setTimeout(function () {
setBadgeText('');
window.close();
}, 2000);
}


function setBadgeText(text) {
chrome.browserAction.setBadgeBackgroundColor({
  color: '#32cd32'
});
  chrome.browserAction.setBadgeText({
    text: text
  });
}
KilliK
  • 11
  • 7
  • The popup is automatically destroyed when hidden so its code and timers stop running. Set the timer in background.js in onMessage listener and [send a message from popup.js](https://developer.chrome.com/extensions/messaging) instead of calling setTimeout. – wOxxOm Nov 07 '19 at 16:52
  • ok, I fixed it, thank you very much for the help. You have helped me many times in this site, wOxxOm, I appreciate it. cheers. – KilliK Nov 08 '19 at 01:41

0 Answers0