4

With older safari extension, we had global javascript to handle beforeNavigate event but with new safari app extension concept is there any way to capture the same event in the app code ?

i tried overiding beginRequest but not sure how to capture the url information here

override func beginRequest(with context: NSExtensionContext) {
     //TODO:
    }
Akhil Thayyil
  • 9,263
  • 6
  • 34
  • 48

1 Answers1

0

You can use script file in the safari app extension, that script automatically injected before page load in the safari.

The script get the navigate event from safari browser and then script would give the event to the app extension and the extension handle this event by following method :

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))")
    }
}

Note : The event had url information that you want.

vijay
  • 1,235
  • 1
  • 11
  • 32