[英]Safari app extension how to capture beforeNavigate event?
隨着較早的safari擴展,我們有全球javascript來處理beforeNavigate事件,但新的safari應用程序擴展概念有沒有辦法在應用程序代碼中捕獲相同的事件?
我試過overiding beginRequest
但不知道如何在這里捕獲url信息
override func beginRequest(with context: NSExtensionContext) {
//TODO:
}
您可以在safari app擴展中使用腳本文件,該腳本會在Safari中的頁面加載之前自動注入。
該腳本從safari瀏覽器獲取導航事件,然后腳本將事件提供給應用程序擴展,並且擴展通過以下方法處理此事件:
override func messageReceived(withName messageName: String, from page: SFSafariPage, userInfo: [String : AnyObject]!) {
page.getPropertiesWithCompletionHandler { properties in
NSLog("The extension received a message (\(messageName)) from a script injected into (\(properties?.url)) with userInfo (\(userInfo))")
}
}
注意:該事件包含您想要的網址信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.