safari.application in Safari App Extension

Hi,


When I developed with Safari Extension, I could listen beforeNavigate event in global page, such as:


<!DOCTYPE html>

<head>

</head>

<body>

<script type="text/javascript" charset="utf-8">

safari.application.addEventListener("beforeNavigate", performCommand, true);

function performCommand(event) {

alert("The URL" + event.url);

}

</script>

</body>

</html>


I could receive this event, and handle it.


According to : https://developer.apple.com/documentation/safariservices/safari_app_extensions/converting_a_legacy_safari_extension_to_a_safari_app_extension?language=objc

Working in the native app extension. A Safari App Extension doesn’t have a global HTML page. Instead, pass messages from your injected code into the app extension.


But when I develop with Safari App Extension, in the SFSafariContentScript, the similar code is not worked.

It seems the safari.application object is NULL.


if(safari.application){

safari.application.addEventListener("beforeNavigate", performCommand, true);

function performCommand(event) {

alert("The URL" + event.url);

}

}

else{

alert("no application"); ----this is alerted

}


What should I do to listen beforeNavigate event with Safari App Extension?


Thak you very much!

Replies

Were you able to get around this (missing beforeSearch)?

The only solution I could devise so far was far from ideal, so much so that I don't think it's useable.
In addition, my questions both here and to developer support have had no hepful replies.
And time is running out.
Hopefully there are a lot of extension developers raising noise about this, since we are not the only ones that will suffer.
On top of that, generally, having no free control of the search provider is a terrible diservice to users. Sure you can select from a list of a few, but that list is not exhastive, the criteria for eligibility and curation process of that list is by no means transparent.

Is there any update on this API and possible ETA. Is there any other input we can provide? We would also be happy to beta test any proposed APIs if needed.


We would really like to provide an experience for our Safari users without pushing them to download another browser. Unforuntately we cannot launch a Safari experience without this API as it would viloate the terms of our agreements with retailer's affiliate programs.

The solution is probably redirecting, right?

Hi,


That would be great for us...


We develop extensions to improve user protection against fraudulent sites (phishing, ...).

We need to identify each URL the browser goes through to detect any URL matching our blacklist (including redirecting urls : 301,302, javascript redirections, http-equiv, ...).


Today, the only solution is validateToolbarItem, but that's not satisfying if we want to catch redirections before we reach the final URL after all redirections.


Adding a pageDidNavigate method would be great.


Emmanuel

It appears this was announced at WWDC 19 and will be available in Safari 13 https://developer.apple.com/videos/play/wwdc2019/720/. 4:25 and 7:30 are the relevant times within the video. Also located the documentation https://developer.apple.com/documentation/safariservices/sfsafariextensionhandling/3238031-page I hope this helps everyone.

Thanks for pointing this out Steve!

Thanks for the heads up 🙂