How to listen to "beforeNavigate" event in safari app extensions

911 views Asked by At

I'm developing a safari app extension. I've to listen to "beforeNavigate" event as in old Safari JS Extensions, we could listen to these events using Safari's Windows & Tabs API.

I went through the How to create Safari App Extension, but unfortunately couldn't find anything related to these events there.

Can anybody please help me with similar APIs for Safari App Extensions as we had in old Safari JS Extensions.

2

There are 2 answers

2
Emmanuel Sellier On

Unfortunately, there is not equivalent in Safari App Extension. The only thing you can do is catching a new tab id displayed through validateToolbarItem.

Or try to add a content or network filter in your App...

0
RawiSader On

Starting Safari 13, Apple added an API for page navigation notifications.

In your SafariExtensionHandler.swift, you can now override func page(_ page: SFSafariPage, willNavigateTo url: URL?).

Source: https://developer.apple.com/documentation/safari_release_notes/safari_13_release_notes