Safari web extension becomes unresponsive in Safari 17, macOS 14.0 Sonoma

I develop a web extension. The extension runs on manifest version 2. The extension has been in the Mac app store for about two years, running without issue. Its last update was roughly four months ago.

Recently, I received a couple user reports that, on Safari 17, in macOS 14.0 (Sonoma), the extension would stop working after some time had passed. Today, I updated my own machine to test, and sure enough, after some time passed, the extension stopped working, and became completely unresponsive. Here are some of the symptoms I've observed:

  • The chrome.browserAction.onClicked listener does not fire.
  • The chrome.commands.onCommand listener does not fire.
  • The chrome.contextMenus.onClicked listener does not fire.
  • When the extension is in this unresponsive state, and I inspect the background script, I'm unable to use the console—it too is frozen and unresponsive. I cannot even execute expressions. Activity Monitor shows no unusual activity, and there is nothing in the background script code that would cause the script to hang like this.
  • The browser page itself continues to work.
  • There are no errors reported.

If I quit and reopen Safari, the extension will work again, but then stop working again after some time has passed.

Interestingly, if the extension has become unresponsive, and I open a new tab, all of the previous events that I tried and failed to fire will execute in sudden succession, as if they had all been stuck in a kind of queue and were suddenly released at once.

I've tried a few workarounds, like calling setInterval, or executing recursive promises on timer, just to see if I could somehow keep the background script "alive". But these have not had any effect.

Has anyone else experienced this? Anyone have any tips? Thanks.

Also saw similar issues where background script becomes unresponsive and can't even input any expressions. While debugging, script will become responsive again only after close/reopen of background script debugger.

Curious if you're using sendNativeMessage()? For me, some changes to that method (or removing it) fixed my particular flow and bg script stopped becoming unresponsive.

I tried setting the value for the "persistent" key to true for the background script in manifest.json (version 2), but it didn't help. Has anyone found a solution to this issue?

I updated my computer to macOS 14.2 more than a month ago and have not experienced this issue since then.

Safari web extension becomes unresponsive in Safari 17, macOS 14.0 Sonoma
 
 
Q