I have a service worker with an onMessage listener.
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
longRunningTask()
.then(handleResult)
sendResponse({success: true})
return true
})
When I send the message to trigger this, the longRunningTask will begin, but it takes quite a while to execute, so the service worker will suspend itself and cancel the task before it finishes.
How can I prevent the service worker from ending prematurely?