Safari Web Extension background script becomes unresponsive after 30 seconds

I'm experiencing a Safari Web Extension issue where the non-persistant background script seems to crash after 30 seconds even when the content script is messaging it.

Here is a minimal-reproducible example. When running in an emulator, the background script will stay responsive forever. However, when running on a physical device, the background script becomes non-responsive after 30 seconds of activity. It never becomes responsive again until I toggle the extensions enable/disable toggle, after which it stays active for 30 seconds and then crashes again.

Some additional findings...

If you look through the content script code you'll see that I am calling runtime.sendMessage every 1 second which always causes the background script to crash after 30 seconds.

I started to play with the 1 second interval to see if it behaved differently. Increasing it to 2 seconds caused a crash after 15 calls (also 30 seconds). Increasing the interval to 3 seconds caused a crash after 10 calls (also 30 seconds).

Increasing to 4 seconds causes the background script to behave how I'd expect... that is it never crashes and is able to respond to the sendMessage request forever.

Please read carefully my post on stackoverflow

Also I created a repo on Github to test by yourself the method discussed in my post on Safari (MacOS & iOS newest versions) and on Chromium/Firefox.

Happy testing :)

This issue should be resolved in the latest iOS 17.6 and iOS 18 betas. Please check these releases to see if your extension still runs into issues. If your extension still encounters issues, please file Feedback at http://feedbackassistant.apple.com/ with a sample project and sysdiagnose.

I installed latest iOS 18 beta and the same exact issue described above still exists.

Everything works as expected on iOS versions older than iOS 17.4.x

This has been fixed in the 17.6.1 update.

@alexkates

Has this problem been resolved? I am facing the same issue, so if you have solved it, please let me know what you did. I have reported in the post below that I am facing the same issue. https://forums.developer.apple.com/forums/thread/764594

Safari Web Extension background script becomes unresponsive after 30 seconds
 
 
Q