对于 hello world 项目,safari 应用扩展在几秒钟后崩溃 [英] safari app extension crashes after a few seconds for hello world project

查看:77
本文介绍了对于 hello world 项目,safari 应用扩展在几秒钟后崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  1. 打开 xcode

  1. open xcode

file > new >project > Cocoa app

file > new >project > Cocoa app

file > new > target > safari 扩展

file > new > target > safari extension

编译并运行扩展

选择野生动物园.

xcode 编译没有错误.

xcode compiles with no errors.

Safari 打开几秒钟然后崩溃.

Safari opens for a few seconds then crashes.

这是调试窗口的输出.

2018-10-10 15:27:18.039905-0700 Safari[1020:16719] [SQLiteStore]未能在以下位置获取数据库存储协调锁/Users//Library/Safari/Favicon Cache/favicons.db-lock:[35:资源暂时不可用] 2018-10-10 15:27:18.040155-0700Safari[1020:16719] [SQLiteStore] 无法获得独占访问权限数据库在file:///Users//Library/Safari/Favicon%20Cache/favicons.db.2018-10-10 15:27:18.041141-0700 Safari [1020:16719] [SQLiteStore]未能在以下位置获取数据库存储协调锁/Users//Library/Safari/Favicon Cache/favicons.db-lock:[35:资源暂时不可用] 2018-10-10 15:27:18.041226-0700Safari[1020:16719] [SQLiteStore] 无法获得独占访问权限数据库在file:///Users//Library/Safari/Favicon%20Cache/favicons.db.2018-10-10 15:27:18.041331-0700 Safari [1020:16719] [SQLiteStore]回退到内存存储 2018-10-10 15:27:18.042877-0700Safari[1020:16719] [FaviconPersistence] 使用内存表示对于数据库/用户//图书馆/Safari/Favicon缓存/favicons.db 2018-10-10 15:27:18.125466-0700 Safari[1020:16771][SQLiteStore] 获取数据库存储协调锁失败/Users//Library/Caches/com.apple.Safari/TabSnapshots/Metadata.db-lock:[35:资源暂时不可用] 2018-10-10 15:27:18.125660-0700Safari[1020:16771] [SQLiteStore] 无法获得独占访问权限数据库在file:///Users//Library/Caches/com.apple.Safari/TabSnapshots/Metadata.db.2018-10-10 15:27:18.235987-0700 Safari [1020:16718] 羊群未能锁定映射文件:errno = 35 2018-10-10 15:27:18.236343-0700Safari [1020:16718] flock 未能锁定地图文件:errno = 352018-10-10 15:27:18.293614-0700 Safari [1020:16718] 无法获取独家访问 AutoFill 更正 SQLite 商店,位于自动填充更正.db.无法获得对自动填充的独占访问权限AutoFillCorrections.db 中的更正 SQLite 存储.2018-10-1015:27:18.299481-0700 Safari[1020:16718] 无法获取独家访问自动填充更正 SQLite 存储在CloudAutoFillCorrections.db.无法获得独占访问权限自动填充更正 SQLite 存储在 CloudAutoFillCorrections.db.2018-10-10 15:27:18.300530-0700 Safari [1020:16718] 无法获取独家访问 AutoFill 更正 SQLite 商店,位于自动填充更正.db.无法获得对自动填充的独占访问权限AutoFillCorrections.db 中的更正 SQLite 存储.2018-10-1015:27:18.304153-0700 Safari [1020:16718] 无法获取独家访问自动填充更正 SQLite 存储在CloudAutoFillCorrections.db.无法获得独占访问权限自动填充更正 SQLite 存储在 CloudAutoFillCorrections.db.2018-10-10 15:27:18.620185-0700 Safari [1020:16763] 无法获取独家访问 AutoFill 更正 SQLite 商店,位于自动填充更正.db.无法获得对自动填充的独占访问权限AutoFillCorrections.db 中的更正 SQLite 存储.2018-10-1015:27:18.623032-0700 Safari [1020:16773] [众包自动填充] 无法读取云自动填充更正集,错误:错误Domain=NSCocoaErrorDomain Code=260 "文件无法打开因为它不存在." 2018-10-10 15:27:18.629453-0700Safari [1020:16763] 无法获得对自动填充的独占访问权限CloudAutoFillCorrections.db 中的更正 SQLite 存储.失败获得对自动填充更正 SQLite 商店的独家访问权CloudAutoFillCorrections.db.2018-10-10 15:27:18.675086-0700Safari[1020:16765] [CloudBookmarks] 获取远程迁移时出错状态:错误域=com.apple.SafariBookmarksSync.CloudBookmarksErrorDomain Code=0(空)" 2018-10-10 15:27:18.771588-0700 Safari[1020:16718][RemotePlistController] 无法加载下载的plist:错误域=NSCocoaErrorDomain 代码=260无法打开文件因为它不存在." 2018-10-10 15:27:19.161007-0700Safari [1020:16773] 无法获得对自动填充的独占访问权限AutoFillCorrections.db 中的更正 SQLite 存储.获取失败独家访问 AutoFill 更正 SQLite 商店,位于自动填充更正.db.2018-10-10 15:27:19.167933-0700Safari [1020:16773] 无法获得对自动填充的独占访问权限CloudAutoFillCorrections.db 中的更正 SQLite 存储.失败获得对自动填充更正 SQLite 商店的独家访问权CloudAutoFillCorrections.db.2018-10-10 15:27:19.279743-0700Safari[1020:16763] [RemotePlistController] 下载的 plist 可以未加载:错误域=NSCocoaErrorDomain Code=260 "文件无法打开,因为它不存在." 2018-10-1015:27:20.064438-0700 Safari[1020:16763] 无法获取独家访问 AutoFillCorrections.db 中的 AutoFill 更正 SQLite 存储.无法获得对自动填充更正 SQLite 的独占访问权限存储在 AutoFillCorrections.db.2018-10-10 15:27:20.081337-0700Safari [1020:16763] 无法获得对自动填充的独占访问权限CloudAutoFillCorrections.db 中的更正 SQLite 存储.失败获得对自动填充更正 SQLite 商店的独家访问权CloudAutoFillCorrections.db.2018-10-10 15:27:20.084003-0700Safari [1020:16763] [CrowdsourcedAutoFill] 既不是本地也不是云可以打开分类校正数据库程序结束于退出代码:0

2018-10-10 15:27:18.039905-0700 Safari[1020:16719] [SQLiteStore] Failed to acquire database store coordination lock at /Users//Library/Safari/Favicon Cache/favicons.db-lock: [35: Resource temporarily unavailable] 2018-10-10 15:27:18.040155-0700 Safari[1020:16719] [SQLiteStore] Failed to acquire exclusive access to database at file:///Users//Library/Safari/Favicon%20Cache/favicons.db. 2018-10-10 15:27:18.041141-0700 Safari[1020:16719] [SQLiteStore] Failed to acquire database store coordination lock at /Users//Library/Safari/Favicon Cache/favicons.db-lock: [35: Resource temporarily unavailable] 2018-10-10 15:27:18.041226-0700 Safari[1020:16719] [SQLiteStore] Failed to acquire exclusive access to database at file:///Users//Library/Safari/Favicon%20Cache/favicons.db. 2018-10-10 15:27:18.041331-0700 Safari[1020:16719] [SQLiteStore] Falling back to an in-memory store 2018-10-10 15:27:18.042877-0700 Safari[1020:16719] [FaviconPersistence] Using in-memory representation for database /Users//Library/Safari/Favicon Cache/favicons.db 2018-10-10 15:27:18.125466-0700 Safari[1020:16771] [SQLiteStore] Failed to acquire database store coordination lock at /Users//Library/Caches/com.apple.Safari/TabSnapshots/Metadata.db-lock: [35: Resource temporarily unavailable] 2018-10-10 15:27:18.125660-0700 Safari[1020:16771] [SQLiteStore] Failed to acquire exclusive access to database at file:///Users//Library/Caches/com.apple.Safari/TabSnapshots/Metadata.db. 2018-10-10 15:27:18.235987-0700 Safari[1020:16718] flock failed to lock maps file: errno = 35 2018-10-10 15:27:18.236343-0700 Safari[1020:16718] flock failed to lock maps file: errno = 35 2018-10-10 15:27:18.293614-0700 Safari[1020:16718] Failed to acquire exclusive access to AutoFill corrections SQLite store at AutoFillCorrections.db. Failed to acquire exclusive access to AutoFill corrections SQLite store at AutoFillCorrections.db. 2018-10-10 15:27:18.299481-0700 Safari[1020:16718] Failed to acquire exclusive access to AutoFill corrections SQLite store at CloudAutoFillCorrections.db. Failed to acquire exclusive access to AutoFill corrections SQLite store at CloudAutoFillCorrections.db. 2018-10-10 15:27:18.300530-0700 Safari[1020:16718] Failed to acquire exclusive access to AutoFill corrections SQLite store at AutoFillCorrections.db. Failed to acquire exclusive access to AutoFill corrections SQLite store at AutoFillCorrections.db. 2018-10-10 15:27:18.304153-0700 Safari[1020:16718] Failed to acquire exclusive access to AutoFill corrections SQLite store at CloudAutoFillCorrections.db. Failed to acquire exclusive access to AutoFill corrections SQLite store at CloudAutoFillCorrections.db. 2018-10-10 15:27:18.620185-0700 Safari[1020:16763] Failed to acquire exclusive access to AutoFill corrections SQLite store at AutoFillCorrections.db. Failed to acquire exclusive access to AutoFill corrections SQLite store at AutoFillCorrections.db. 2018-10-10 15:27:18.623032-0700 Safari[1020:16773] [CrowdsourcedAutoFill] Unable to read cloud AutoFill correction sets, error: Error Domain=NSCocoaErrorDomain Code=260 "The file couldn’t be opened because it doesn’t exist." 2018-10-10 15:27:18.629453-0700 Safari[1020:16763] Failed to acquire exclusive access to AutoFill corrections SQLite store at CloudAutoFillCorrections.db. Failed to acquire exclusive access to AutoFill corrections SQLite store at CloudAutoFillCorrections.db. 2018-10-10 15:27:18.675086-0700 Safari[1020:16765] [CloudBookmarks] Error fetching remote migration state: Error Domain=com.apple.SafariBookmarksSync.CloudBookmarksErrorDomain Code=0 "(null)" 2018-10-10 15:27:18.771588-0700 Safari[1020:16718] [RemotePlistController] The downloaded plist could not be loaded: Error Domain=NSCocoaErrorDomain Code=260 "The file couldn’t be opened because it doesn’t exist." 2018-10-10 15:27:19.161007-0700 Safari[1020:16773] Failed to acquire exclusive access to AutoFill corrections SQLite store at AutoFillCorrections.db. Failed to acquire exclusive access to AutoFill corrections SQLite store at AutoFillCorrections.db. 2018-10-10 15:27:19.167933-0700 Safari[1020:16773] Failed to acquire exclusive access to AutoFill corrections SQLite store at CloudAutoFillCorrections.db. Failed to acquire exclusive access to AutoFill corrections SQLite store at CloudAutoFillCorrections.db. 2018-10-10 15:27:19.279743-0700 Safari[1020:16763] [RemotePlistController] The downloaded plist could not be loaded: Error Domain=NSCocoaErrorDomain Code=260 "The file couldn’t be opened because it doesn’t exist." 2018-10-10 15:27:20.064438-0700 Safari[1020:16763] Failed to acquire exclusive access to AutoFill corrections SQLite store at AutoFillCorrections.db. Failed to acquire exclusive access to AutoFill corrections SQLite store at AutoFillCorrections.db. 2018-10-10 15:27:20.081337-0700 Safari[1020:16763] Failed to acquire exclusive access to AutoFill corrections SQLite store at CloudAutoFillCorrections.db. Failed to acquire exclusive access to AutoFill corrections SQLite store at CloudAutoFillCorrections.db. 2018-10-10 15:27:20.084003-0700 Safari[1020:16763] [CrowdsourcedAutoFill] Neither local nor cloud classification correction databases could be opened Program ended with exit code: 0

我已尝试重新启动计算机.

I've tried restarting my computer.

我已经尝试清理项目.

我试过用

xatter -cr .

我一次尝试了所有三个.

I've tried all three at once.

推荐答案

如果 Xcode 调试器未从内容脚本接收任何事件,则它倾向于终止扩展进程.根据我的观察,这完全没问题,在生产环境中你的应用不会那么容易死(这不是真的,看看帖子的底部).

Xcode debugger has a tendency to kill the extension process if it doesn't receive any events from the content script. From my observations, this is completely okay, and in production your app will not die as easily (edited: this isn't true, look at the bottom of the post).

为了避免这种行为,您可能需要将此代码段添加到您的 script.js 中:

To circumvent this behavior you might want to add this snippet to your script.js:

setInterval(() => safari.extension.dispatchMessage("ping", {}), 1000);

它将使内容脚本发送一条名为ping"的消息;每秒到扩展名.这应该足以让您的扩展保持活力.同样,这只是调试真正需要的,您的生产构建不需要这条线可靠地工作(这不是真的,看看帖子的底部).

It will make content script send a message named "ping" to the extension every second. This should be enough to keep your extension alive. Again, this is only really needed for debugging, your production build won't need this line to work reliably (edited: this isn't true, look at the bottom of the post).

请记住,默认情况下,内容脚本仅注入 *.webkit.org 页面.这由扩展程序的 Info.plist 文件中的 SFSafariToolbarItem 属性值决定.出于测试目的,您可能希望在所有网站上启用您的扩展程序,如下所示:

Keep in mind that by default content scripts are only injected on *.webkit.org pages. This is determined by the value of SFSafariToolbarItem property in your extension's Info.plist file. For testing purposes, you might want to enable your extension on all websites like so:

<key>SFSafariWebsiteAccess</key>
<dict>
  <key>Level</key>
  <string>All</string>
</dict>

注意,内容脚本不会注入到空标签中,所以一定要加载一些远程页面.

Be careful, content script is not injected into an empty tab, so be sure to load some remote page.

更新

显然,Safari 实际上会以与调试器中相同的方式终止生产构建中的扩展.所以 setInterval() hack 在这种情况下仍然是相关的.这仅适用于没有弹出窗口的扩展程序.

Apparently, Safari actually kills extensions in production builds the same way as it does in the debugger. So setInterval() hack is still relevant in that case. This only applies to extensions without a popover.

这篇关于对于 hello world 项目,safari 应用扩展在几秒钟后崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆