1

Basically, I'm looking for RequestPolicy for Safari. GlimmerBlocker, Privoxy and BFilter etc, those work well but none of them support "block 3rd party elements" feature.

I use GlimmerBlocker, and to imitate (barely) the function, I mainly put this code to filter script flooded website.

replace(/<(script|noscript|iframe)([\s\S]*?)<\/(script|noscript|iframe)>/img, "")

However I'm tired of repeating creating filters for each websites. Vice-versa, whitelisting will be the same. If anybody had an idea to solve this, that would be so great. Thanks.

1 Answer 1

5

I made this proof-of-concept Safari extension to block external resources (images, objects, and scripts, but NOT link elements, such as stylesheet links) until allowed. It has a bare minimum number of features, but if you are interested, I might develop it further.

I say "external" and not "third-party" because I don't know to tell reliably if a resource is third-party or not. This extension just blocks all resources that come from a different host than the web page. As a result, it blocks too many resources by default.

You can right-click a blocked image and use a context menu command to whitelist the image host. If the blocked image didn't have a specified width and height, it will be invisible, so you won't be able to right-click it. (To remedy this, I will need to add code to make the empty image visible as a box.)

The whitelist command does not show up for blocked plugin objects (such as Flash objects) or scripts. I will have to add code to deal with that.

You can also whitelist the current site itself, meaning that all external resources will be allowed on that site. Again, this is done with a context menu command.

As yet, there is no way to remove items from either whitelist. This can be added.

Download the extension from here.

You can extract the source files from the extension package using this command:

xar -xf PartyPooper.safariextz

You are welcome to do whatever you like with the source.

5
  • 1
    This is awesome, thanks so much for your work. It looks like it does not prevent external resources from being downloaded, but it does from showing locally, am I right? (by the way I'm sorry that I don't have enough reputation to vote your answer up)
    – provdr
    Jun 24, 2011 at 4:46
  • 1
    You know, I'm not really sure about that. According to Apple's docs, when a resource is blocked using the technique in my extension, it is "not loaded". But I don't know whether that means it's not downloaded. I will try to check that using Safari's developer tools.
    – chulster
    Jun 24, 2011 at 6:03
  • I see. I will also look around, if Apple allowed to do that and could be implemented, I will have no reasons to use neither Chromium nor Firefox any longer... which is awesome.
    – provdr
    Jun 24, 2011 at 6:28
  • Looking at the Network tab of Safari 5.1's Web Inspector, it does seem as though the extension is preventing the external resources from being downloaded—not just hiding them. I took a couple of screenshots of the Web Inspector after loading the home page of nytimes.com, the first with the extension disabled and the second with it enabled; making sure to empty the browser cache between runs. (Only image resources are shown.) You can see the screenshots at http://canisbos.imgur.com/party_pooper.
    – chulster
    Jun 24, 2011 at 16:24
  • You can see at the bottom of the window that the page had 161 image requests for a total of 1.65 MB transferred when the extension was off, vs. 67 requests and 553K transferred with the extension on. But you can also see that the images that are loaded even with the extension on do come from external hosts (such as graphics8.nytimes.com). I think this is happening because they are CSS background images and other types that do not trigger the beforeLoad event for some reason. I don't know if that's a bug in Safari or by design.
    – chulster
    Jun 24, 2011 at 16:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.