Safari iOS extension issues. Background script stops working

Hello there! At our company we have started to deal with an issue in the latest iOS (17.5) version.

It looks like the background script of the extension becomes unresponsive after a short amount of time (around 30 seconds) after performing more than one request to it within a range of 1 - 4 seconds.

How it can be tested? Pretty simple example:

// content.js

const t = 4000 // Using less than 4000ms makes background script unresponsive

async function requestNext() {
    return browser.runtime.sendMessage({ greeting: "getNext" })
}

setInterval(async () => {
    const n = await requestNext()
    console.log("current is: " + n)
}, 4000)
// background.js

let counter = 0

browser.runtime.onMessage.addListener((request, sender, sendResponse) => {
    console.log("Received request: ", request);

    if (request.greeting === "getNext") {
        counter++
        sendResponse(counter);
        return true
    }

});

Whenever the browser.runtime.sendMessage is executed too fast the background script will stop working.

As far as we have been able to check this only can be reproduced after 17.4.1

Why does your background listener return true after calling sendResponse? Returning true is for async responses that are called later.

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.

From our tests on iOS 18 beta, the issue is not fully resolved (so in a sense not solved at all).

While now the workers keep working even after the 30 seconds of use pass, if the user is exiting Safari or the device is locked and unlocked, from that point the listener in background.js does not continue to receive messages (from native or web js).

If Safari is terminated and relaunched, everything starts working again (until user again exists/returns from/to Safari).

Safari iOS extension issues. Background script stops working
 
 
Q