79507226

Date: 2025-03-13 17:45:57
Score: 0.5
Natty:
Report link

More testing, and changes & finally got it to work.

Seems you can't fetch from a content script?

anyhoo, if anyone else needs this... it seems to be workin

content script


async function refresh() {    
        browser.runtime.sendMessage({
        status:  "load"
  });  
    setTimeout(refresh,30000);  // 30 sec
};
refresh();

background script

browser.runtime.onInstalled.addListener(() => {

function handleMessage(request) { 

let url       = "https://www.bungie.net/Platform/Settings";

 fetch(url)
    .then(res  => res.json())
    .then(data => {
      let c = data.Response.systems.Destiny2;
      let msg = c.enabled ? "up" : "down";     
      if( msg === "up" ) {
                browser.browserAction.setIcon({   
                     path: "icons/leaf-64.png"
               });       
      } 
     else if ( msg === "down" ){
            browser.browserAction.setIcon({   
                     path: "icons/redleaf-64.png"
           });     
      } 
    })  
    .catch(err => {   
    });  


     
};
 browser.runtime.onMessage.addListener( handleMessage  );

});
Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Greenman