safari app extension crashes after a few seconds for hello world project

寵の児 提交于 2020-02-20 04:48:51

问题


  1. open xcode

  2. file > new >project > Cocoa app

  3. file > new > target > safari extension

  4. compile and run extension

  5. select safari.

  6. xcode compiles with no errors.

Safari opens for a few seconds then crashes.

this is the output of the debug window.

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.

I've tried cleaning the project.

I've tried deleting meta data with

xatter -cr .

I've tried all three at once.


回答1:


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.

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

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

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.

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.




回答2:


At the first run you should select your Cocoa App target and only after this run the extension. Please, try build and run your app at first and say if it helped.



来源:https://stackoverflow.com/questions/52749680/safari-app-extension-crashes-after-a-few-seconds-for-hello-world-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!