Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setInterval not working properly on safari web extension

I've recently ported my chrome extension to safari using the safari web extension converter: https://developer.apple.com/documentation/safariservices/safari_web_extensions/converting_a_web_extension_for_safari.

However, I'm finding that my setInterval calls only executed a set number of times in the background page. When I open the background page for my web extension, I've tried running a simple interval to see the result:

Safari Web Extension Background Page with interval stuck after running set number of times

When I try the same thing for my chrome web extension, the interval runs indefinitely:

Chrome Web Extension Background Page with interval running continuously

If I try to run the interval after opening the dev console for any random web page in Safari, the interval works fine:

Safari content page with interval running continuously

Similarly, a recursive setTimeout function fails in the background page for the web extension:

Recursive setTimeout function in my background page Result of recursive set timeout function in my background page (stops afterwards)

I'm not sure why timers might be failing in background page for Safari. My extension works perfectly fine in chrome/brave/firefox. Thanks!

like image 258
Saurav Pahadia Avatar asked Nov 24 '25 11:11

Saurav Pahadia


1 Answers

When the extension is not active safari browser stops the background process of that specific extension.

Alternative approach: You can create a timeout in the content script and message background from the content script periodically to check your requirement.

like image 128
Mathanolwin Avatar answered Nov 26 '25 01:11

Mathanolwin