chrome.storage.local not working after a while in Safari extension

40 Views Asked by At

I ported my Chrome extension to Safari iOS/macOS using the Xcode converter.

I inject an email subscription form onto a webpage using a content script, when this form is submitted it sets a value in chrome.storage.local, this is so the form can be hidden from the user from then on.

However, after a while the form starts appearing again to my users who have already submitted it previously.

This has also happened to me before and I manage to fix it by toggling off and on the extension in Safari settings.

However I'm getting reports from users that its happening to them and toggling doesn't fix it, they have to reinstall the app.

I also can't debug this because the form is hidden for me, so chrome.storage.local is working for me and has been for days.

I've read this could be related to Safari shutting down tabs that haven't been used recently to save battery life? But from what I can see there isn't a way to prevent this from happening due to manifest v3 service_workers?

This is my service worker code:

chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
    if (request.type === 'getUserInfo') {
        if (isSafari) {
            chrome.storage.local.get(['email']).then((result) => {
                sendResponse(result);
            })
            return true;
        }
    }
});

This works fine in Chrome... and Safari until it doesn't...

0

There are 0 best solutions below