我正在将逻辑从 Chrome/Firefox Web 扩展的后台脚本移植到 Safari 应用扩展。我对 Xcode 很陌生,所以需要一些时间来学习如何解释和面对我遇到的问题。
我已经启动并运行了一个测试项目,我的内容脚本已成功注入 Safari,并且我更新了消息传递逻辑以说明 Safari App Extensions 中使用的不同 API。在 Swift 和 Javascript 之间来回发送消息是有效的。我正准备开始将 Javascript 逻辑迁移到 Swift,但是在我将方案切换到我的应用程序扩展以使用 Xcode 的控制台后,开始出现错误,并且 Safari 现在在我运行项目大约 30 秒后关闭,如果我在浏览器中什么都不做。如果我单击扩展的工具栏项或设置一个计时器来向 Safari 主体类发送消息,浏览器将保持打开几分钟,然后最终关闭。
通过大量搜索,我只找到了一些可能与我正在经历的事情相关的线程,所以我不知道从这里去哪里。StackOverflow 上的一篇文章提到“如果 Xcode 调试器没有收到来自内容脚本的任何事件,它倾向于终止扩展进程”(对于 hello world 项目,safari 应用程序扩展在几秒钟后崩溃),但我不是确定这是否是我这边发生的事情。
让这更令人困惑的一件事是我看到最多的错误消息是:“Safari[2803:95905] [Process] kill() 返回了意外错误 1。” 这很令人困惑,因为我在网上发现了很多帖子提到这是 WKWebViews 的一个已知错误,但这些帖子都没有提到 Safari 应用程序扩展。看起来大多数遇到该错误的开发人员都在为 iOS 应用程序编写代码。
是否有其他人遇到此错误消息和其他错误消息,这些错误消息似乎正在杀死他们的 Safari 应用程序扩展进程,从而关闭,甚至可能崩溃,运行他们的 Xcode 项目后创建的 Safari 实例?如果是这样,有没有找到解决问题的方法以及解决方案是什么?我尝试使用全新的 Safari App Extension 项目从头开始,并且出现了相同的错误。这都是正常的行为吗??
这是我每次 Safari 关闭/崩溃时看到的控制台日志的一部分(目前不确定是哪个)。有时信息更多,有时信息更少,但显示的错误大多始终相同:
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
控制台中的最后一行(上面的日志片段中未显示)始终显示“程序以退出代码结束:0”。这也让我感到困惑,因为我相信这告诉我扩展程序已关闭而没有任何错误。对于该行上方的所有错误消息,我不确定如何解释似乎是一个很大的差异。
任何人都可以提供的任何帮助将不胜感激!