Safari extensions beforeNavigate event not triggers

Is that a bug on Safari? Version 8 (the older also)

When the user enters URL into the address bar and hit enter or clicks bookmark the 'beforeNavigate' event is not catched. But it works if open a link on a webpage. Any idea how to get initial requested URL? Sample code:

//global.html

<!DOCTYPE HTML>

<script>

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

function openHandler(e) { console.log(e); }

</script>

Also seeing this, beforeNavigate will not fire when navigating is performed from the URL bar. Tried giving beforeSearch a try too, but that only fires when there is a literal search performed.


I've been trying to migrate a Chrome extension over to Safari for the past year, each time Safari gets an update. Every time the events fail in new and wonderful ways.


Edit 8/12: Since filed Bug #22260191 - will report back if I get any response, which is unlikely.


Edit 8/13: Bug #22260191 was marked as a duplicate #15436601, but that case is Closed (and seemingly old) so this could be a regression, hopefully a fixable one?!


Edit: 8/14: Bug #22260191 was closed with no comment. Seems like a clear "Don't care; won't fix".

I've given up on this.

Hi,


I've spent some time trying to figure out what was going wrong here until I found this thread.


It's frustrating that nothing has been done about it.


@Jakeisonline - have you re-visited this since you gave up? Do you think it's worth me filing another bug?


Phil

I did revisit this yes. I was told, "The original report on the issue, Bug ID 15436601, was closed and the resolution is “Fixed in OS X 10.11”."


I have not yet upgraded to OS X 10.11 but did run my test once more on OS X 10.10.5 and Safari 9 and found the event does now fire from the URL bar... with one small problem.


"beforeNavigate" is supposed to fire when a new URL is about to load within a browser tab. However, the event fires when Safari autocompletes a URL, despite the user having NOT selected it themselves nor committed to the navigation. If the user does commit, no beforeNavigate is fired. So there seems to be no way to determine whether or not the event was the result of a user selecting a URL to navigate to.


Again, basing my understanding of this event on the rather sparse documentation at https://developer.apple.com/library/safari/documentation/Tools/Conceptual/SafariExtensionGuide/WorkingwithWindowsandTabs/WorkingwithWindowsandTabs.html

I have OS X 10.11.1 with Safari 9.0.1 and the problem still exists.

I have exactly the same requirement that I wish to sense when exactly the user wishes to navigate to the url so I can preventDefault and send the request myself with some of he cookies modified.

Is there a way to intercept any http/https request before it is sent out?

If you have found a fix or a workaround for this please let me know.

Safari extensions beforeNavigate event not triggers
 
 
Q