Should I worry about Safari shutting down roughly 30 seconds after building and running my app extension?

I'm in the process of porting over the logic from the background scripts of a Chrome/Firefox web extension to a Safari App Extension. I'm very new to Xcode, so it's taking some time learning how to interpret and confront the issues I'm encountering.


I have a test project up and running, my content scripts are getting injected successfully into Safari, and I have updated the messaging logic to account for the different API's used in Safari App Extensions. Dispatching messages back and forth between Swift and Javascript is working. I was just about ready to get into migrating the Javascript logic over to Swift, but after I switched the scheme to my app extension to make use of Xcode's console, errors started appearing and Safari is now closing about 30 seconds after I run the project if I do nothing in the browser. If I click on the extension's toolbar item or setup a timer to dispatch a message to the Safari principle class, the browser will remain open for a few minutes, then eventually closes.


Through a ton of searching, I have only found a few threads that may correlate to what I'm experiencing, so I'm not sure where to go from here. One post on StackOverflow mentioned "the Xcode debugger has a tendency to kill the extension process if it doesn't receive any events from the content script" (safari app extension crashes after a few seconds for hello world project), but I'm not sure if that is what is happening on my end.


One thing that makes this more confusing is the error message I see the most is: "Safari[2803:95905] [Process] kill() returned unexpected error 1." I've found quite a few posts online mentioning this is a known bug with WKWebViews, but none of these post are referring to Safari App Extensions. It looks like most developers running into the bug are coding for iOS apps.


Is anyone else running into this and/or other error messages that appear to be killing their Safari App Extension process, thus shutting down, maybe even crashing, the Safari instance created after running their Xcode project? If so, has any figured out a way to fix the problem and what is the solution? I have tried starting over from scratch with a brand new Safari App Extension project, and the same errors are exhibited. Is this all normal behavior??


Here is a portion of the console logging I see every time Safari closes/crashes (not sure which at this point). Sometimes there is more information, and sometimes there is less, but the errors displayed are mostly always the same:


2019-12-12 18:13:08.917857-0800 Safari[2803:95905] Metal API Validation Enabled
2019-12-12 18:13:09.159014-0800 Safari[2803:95988] Bogus event on event stream listener.
2019-12-12 18:13:09.159101-0800 Safari[2803:96452] Bogus event on event stream listener.
2019-12-12 18:13:09.214558-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:09.372862-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:09.373012-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:09.378587-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:09.378758-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:09.483250-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:09.483355-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:09.485804-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:09.490306-0800 Safari[2803:95905] [logging-persist] cannot open file at line 43353 of [378230ae7f]
2019-12-12 18:13:09.490385-0800 Safari[2803:95905] [logging-persist] os_unix.c:43353: (0) open(/var/db/DetachedSignatures) - Undefined error: 0
2019-12-12 18:13:09.522278-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:09.522382-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:09.522447-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:09.522498-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:09.551921-0800 Safari[2803:95942] [RemotePlistController] The downloaded plist could not be loaded: Error Domain=NSCocoaErrorDomain Code=260 "The file couldn’t be opened because it doesn’t exist."
2019-12-12 18:13:09.577117-0800 Safari[2803:95905] [PerSitePreferences] Failed to set up all website policies before timeout
2019-12-12 18:13:09.578903-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:09.731939-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:09.753432-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:09.753519-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:09.753611-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:09.753669-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:09.891540-0800 Safari[2803:95905] [Safari] extractOptions:140: *** unknown hint identifier 'kCGImageSourceTypeIdentifierHint:dyn.age8u' -- ignoring...
2019-12-12 18:13:09.898688-0800 Safari[2803:95940] [RemotePlistController] The downloaded plist could not be loaded: Error Domain=NSCocoaErrorDomain Code=260 "The file couldn’t be opened because it doesn’t exist."
2019-12-12 18:13:09.921347-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:09.921500-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:09.921578-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:09.921635-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:09.922366-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:09.922439-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:09.922498-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:09.922545-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:09.922917-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:09.923024-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:09.923306-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:09.923363-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:09.923909-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:09.924171-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:09.946914-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:09.947027-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:10.044157-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:10.159500-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:10.159683-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:10.166124-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:10.500702-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:10.501052-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:10.504431-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:10.610748-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:10.861719-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:12.053141-0800 Safari[2803:95940] Creating client/daemon connection: 3889E9E5-F875-40CA-A484-27A377D595B9
2019-12-12 18:13:12.057331-0800 Safari[2803:95940] Got the query meta data reply for: com.apple.MobileAsset.CoreSuggestions, response: 0
2019-12-12 18:13:12.093342-0800 Safari[2803:95940] Consumed extension
2019-12-12 18:13:12.097874-0800 Safari[2803:95940] Got the query meta data reply for: com.apple.MobileAsset.CoreSuggestions, response: 0
2019-12-12 18:13:15.802250-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:15.805448-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:15.833848-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:15.835537-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:15.842346-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:15.844550-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:15.846696-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1
2019-12-12 18:13:15.847707-0800 Safari[2803:95905] [Process] kill() returned unexpected error 1


The last line in the console (not shown in the above logging snippet) always states, "Program ended with exit code: 0". This is also confusing, because I believe that is telling me the extension closed without any errors. With all the error messages above that line, I'm not sure how to interpret what seems to be a pretty big discrepancy.


Any help anyone can provide would be MUCH appreciated!

>developers running into the bug


File one of your own, and see what comes back...

I don't know if you have found this yet, but closing every 30 seconds thing is answered here https://stackoverflow.com/a/56733433/3199106


It supposedly doesn't kill the background process in production that quickly

Thanks so much for the reply. I saw the the post you linked. It's actually the stackoverlow link in my original post, which I should have changed to a plain URL like you did =) One of the things I'm concerned about is all of the errors getting reported through the console. I've seen posts where otheres are confused about errors as well, but I'm not finding any answers for what they are actually telling the developer. Are you seeing a ton of error messages when Safari closes too?


It is really good to know that the background process doesn't close so quickly in production. Hopefully it won't be a problem for what we're trying to accomplish.

Should I worry about Safari shutting down roughly 30 seconds after building and running my app extension?
 
 
Q