简体   繁体   中英

Chrome Extension with Service worker, update badge from a 'push' event

I have recently built a Chrome Extension that is coupled with a service worker, which recives push notifications via FCM, this is all working and my Service worker triggers correctly.

I want to be able to set the Chrome Extension Badge text from this function, as my server is updating the extension with the correct count.

Here is the function that I am currently using.

self.addEventListener('push', function(event) {
  if (event.data) {
    let data = event.data.json();

    if (data.count){
        // This is the only function that I can see when I debug the chrome obj
        chrome.runtime.getBackgroundClient().then((bgClient) => {
            console.log(bgClient)
        })
    }
  }
});

I am aware of the chrome.browserAction.setBadgeText({text: count}); function but this does not seem to be available from within the service worker, not can I see a way of accessing my background scripts.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM