jacobq
jacobq

Reputation: 11577

Is it possible to monitor all network traffic in a Safari Extension?

Since the newer versions of Safari (I'm running version 5.2) seem to have removed the "Activity" viewer from the "Window" menu, I would like to write an extension to have this feature back. However, in order to do that I think that I will need to be able to see what URLs are being requested in that window/tab. For Chrome, there is a "webRequest" API that does this, but I can't seem to find what I'm looking for to do this in Safari. Would someone please tell me if this is possible, and if so, where should I look next? Thanks in advance.

So far, the most I've been able to get is using an injected start script like the one below:

function trackRequests() {
    console.log(event.timeStamp + ": " + event.type, event.url, event);
}
document.addEventListener("beforeload", trackRequests, true);

However, this does not provide enough for the features I'll need for this. For example, if a URL is specified without a protocol e.g. "//example.com/file.txt" that is all this handlers sees; it doesn't know what actual protocol was used or if the request was allowed.

It appears that some people on the Apple discussion forums, MacDailyNews, and ArsTechnica have expressed a desire to have this feature back in Safari as well. Here's a link to another discussion on MacRumors.com and another.

Upvotes: 12

Views: 6466

Answers (1)

Jos
Jos

Reputation: 420

On windows I would use Fiddler but since you appear to be using a Mac here are some alternatives:

http://alternativeto.net/software/fiddler/?platform=mac

Hope this helps!

Cheers!

Upvotes: 1

Related Questions