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).

Still happening for me, too. Version 17.5 (19618.2.12.11.6)

We're experience similar issues within MacOS on Safari v17.5. It seems that any browser.runtime.sendMessage call that awaits a response will lock up the background script.

Beyond this, we're seeing that if the extension popup is opened, the pending sendMessage calls resolve and receive the sendResponse returned by the browser.runtime.onMessage listener within the background script.

This has been fixed in the 17.6.1 update.

@AaronScandit

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 iOS extension issues. Background script stops working
 
 
Q