views:

8765

answers:

9

What is the best way to write a Safari extension? I've written a couple XUL extensions for Firefox, and now I'd like to write versions of them for Safari. Is there a way that would allow you to add buttons or forms to the browser UI, since this is not possible with an Input manager or Service menu?

UPDATE: The best way to write a Safari Extension is to target Safari 5 or later :-)

+13  A: 

Safari plugin development is non-trivial. The interface is written in Objective-C, and most of it is not even part of WebKit (so you can't see the source), but there's machinery to inspect and patch the object hierarchy of a running application. It requires understanding of Cocoa and Objective-C, but no lower.

Here's a high level overview I had in my bookmarks of the process http://livingcode.org/2006/tab-dumping-in-safari. It goes over creating Safari plugins using Python with working (probably outdated) code. Instead of Python you can use anything that has Objective-C bindings.

There are two major parts to it:

Reading the links above will give you the scope of the project.

æon
Just to clarify, input managers ≠ Safari plugins. Safari does have a plug-in architecture, it's just not what developers expect compared to Firefox. This answer provides great advice for the input manager approach. My answer below has more information on "true" plugins, even though that approach is unlikely to meet your specific needs in this case.
Quinn Taylor
Now I want to make a safari plugin with simbl , and I have read the Armchair Guide To Cocoa Reverse Engineering. but when implement the method - (void)load; how to use the plugin to get the safari DOM object ,just like PIC or Flash URL ? Thank you very much !
jin
+4  A: 

Is there a way that would allow you to add buttons or forms to the browser UI, since this is not possible with an Input manager or Service menu?

Actually, with an InputManager, it would be possible. SIMBL, the common technique for Safari extensions, is simply a wrapper around InputManagers — it stands for Smart Input Manager Bundle Loader. You can add stuff to the menu bar, to the toolbar, dialogs, anywhere, simply by extending Safari's existing classes.

That said, writing extensions for Safari is not only non-trivial, as æon said, but also completely unsupported. There are some relatively popular ones out there, like Inquisitor (recently acquired by Yahoo!) and Google's Gears, but for the most part, it's very unlike Firefox's extensions, which are an officially-supported, widely used technique.

You also definitely want to take into consideration the special limitations of InputManagers on Leopard.

Sören Kuklau
+1  A: 

Also, to note - Apple has stated that InputManagers are being severely limited as of Leopard and will not run in 64-bit applications per Apple Leopard Release Notes. This is especially interesting considering most applications will be 64-bit in Snow Leopard (including presumably Safari). Apple is definitely trying to obliterate InputManager as a vector to overriding and extending functionality. Safari desperately needs an extension mechanism.

rcw3
+5  A: 

Nobody seems to have even mentioned the fact that Safari actually does support true plugins, which input manager hacks most definitely are not.

"WebKit Plug-In Programming Topics" http://developer.apple.com/documentation/InternetWeb/Conceptual/WebKit_PluginProgTopic/

This is how things like support for PDF and Flash content are implemented. Take a peek inside your /Library/Internet Plug-ins/ directory to see examples.

Of course, there are inherent limitations, and you may not be able to accomplish what you hope to as far as UI modification. Safari plug-ins can't do all the things that Input Manager hacks can, but they will work in WebKit anywhere, and in future versions of the OS. Note: Safari is 64-bit by default on Snow Leopard, so no Input Managers work. I'm missing Safari AdBlock already... :-( I would love to see it rewritten as a bonafide plugin.

Quinn Taylor
+10  A: 

Things have changed recently. Apple now has an extensions API available as a part of Safari 5. You can find out more on Apple's site and by joining the Safari Developer Program.

Extensions to Safari have to be digitally signed, but you can get the signing certificate free from Apple. This is the legitimate way to get your extension into Safari without resorting to hacks that will likely break every time Apple updates Safari.

Tim Sullivan
+1 for updating this, I would include they need approval though....not that this will surprise anyone, but still note-worthy.
Nick Craver
Done and done! Thanks.
Tim Sullivan
They don't actually need approval, they just need to be digitally signed with a free certificate from Apple.
Tim Sullivan
+8  A: 

With the release of Safari 5.0, Apple released a new extension framework for developers to use. In features it looks similar to Firefox extesion framework allowing to customize buttons, toolbars, context menus, injections using javascript and html 5

More at this link

http://developer.apple.com/safari/library/documentation/UserExperience/Reference/SafariExtensionsReference/index.html

Olivier Refalo
+1  A: 

Safari Extensions do NOT need to be Approved by apple. You just have a developer cert (for free) to make them, but you can pass them around and although Apple is making the Extension Gallery, you don't have to distribute it through there. As you can see there are already quite a few extensions that you can try today. The cert just ensures that it hasn't been tampered with.

http://safariextensions.tumblr.com/

Pete Akins
A: 

If you want to look at an existing extension to see how its done, download it or get it from your Safari extensions folder then change the .safariextz to .xar then open/extract with Pacifist to view the code and if you want add it to the Extension Builder app.

Mat
A: 

First SEO extension for Safari! You can test it right here: http://safari.seoquake.com/full/

Enjoy!

Eola