Maintain the background process running as long as the Safari process is alive

In the current Safari App Extension framework the background Swift process can be removed by the OS at any point while Safari is still running. This creates multiple issues:

1. You cannot store any state about the tab in the background, which is neccessary if you want to update the button label and icon, or context menu options based on the state of the tab

2. There may be a big delay between user pressing the extension button and any visible response, since the background app extension process needs to be reinitialized if it got killed.


My question is whether there is a way to maintain the background app extension process running for as long as Safari itself is open and/or would that be considered bad practice? If it is, what would be the way to mitigate the issues outlined above?

Replies

Were you able to get a solution for this issue @adomasven? I believe I'm running into something similar where Safari closes after about 30 seconds of running the extension. For development, there definitely needs to be some sort of flag we can set to force the Safari instance to stay open. For production, we would need some way to listen for the extension being closed so we could reinstantiate it if needed. Like the OP said, we don't know how long the delay will be for a user interacting with the code in the extension, and if it's closed, there's no way to rerun it, so far as I know.


Does anyone have any information on how to keep the extension running? Is there any events we can tie into in order to hear when it closes and then respond accordingly? If so, how do we go about reinstantiating the exension if it's closed?

You are asking about something else and I answered you in your topic, but as for my own question, we have now deployed the extension to a beta branch of our users and the background process does not seem to be killed all that often (or possibly at all). I don't know if this will change in the future but for now it works well.

Thanks again for your reply on my post and for the extra details on your experiecne with your own extension in beta testing. It's really good to know from someone's actual, hands on experience how things are working in non-development context.