Hi,
I'm trying to execute some long running code(puppeteer script) from service worker. When I invoke this action from popup by clicking a button, the code starts running.
When the popup loses focus and close during puppeteer navigation, or I manually close the popup - the code execution pauses there, not totally stops. If I open the popup by clicking on the extension icon, the execution resumes from the exact line of code where it was paused last time.
This was working fine on MV2 with background js. I'm totally confused what's happening here. I followed multiple articles where it was suggested to follow some steps to keep the service worker alive. But, nothing works.
The issue is that, service worker is not getting terminated - but just getting paused.
Could anyone help how to fix this issue.
This is the code in my service worker. Simplified actual promises from my actual code, to print numbers to console every second. Please look at the attached video for clear understanding of my issue.
I'm expecting the background code to run even though popup is closed.
async print(i){
return new Promise(function(resolve, reject) {
console.log("i=", i)
setTimeout(() => {
resolve(i)
}, 1000)
});
}
async executePuppeteerCode(tabId, port) {
console.log("tabId", tabId)
for(let i=0; i < 100000; i++){
await this.print(i)
}
}