0

We are having a chrome extension built using manfiest V3 version.I am trying to use navigator.serviceworker in the background js which is registered as a service worker in the chrome extension but in background.js when running navigator.serviceWorker i am getting it as undefined. I tried using self.navigator.serviceWorker. Is there any way where we can access the serviceworker methods in background script for a chrome extension

I am trying to access serviceworker using

navigator.serviceWorker

in the manfest we have configured the background script in the below way

  "background": {
    "service_worker": "scripts/background.js"
  },

for all the above possible way i am getting as undefined only when doing

console.log("Service worker --> ", navigator.serviceWorker)
  • This API is not defined within the service worker because your code is already inside the service worker environment so it simply doesn't make any sense. What specifically are you trying to achieve? – wOxxOm Feb 23 '23 at 11:16
  • I am trying to implement the following https://developer.chrome.com/blog/longer-esw-lifetimes/#whats-changed I want to increase the service worker lifetime.Any suggestions how we can acheive this – Abhinav Veramosu Feb 23 '23 at 14:20
  • 1
    Your background script is a service worker, so this change applies automatically to your script, but only in the described case of an event, for example chrome.tabs.onUpdated. If you want to prolong the lifetime further, see [this answer](/a/66618269). – wOxxOm Feb 23 '23 at 14:42

0 Answers0