<p>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?</p>

[{'answer_id': 60305, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 4, 'selected': False, 'text': '<p>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.</p>\n\n<p>Here\'s a high level overview I had in my bookmarks of the process <a href="http://livingcode.org/2006/tab-dumping-in-safari" rel="nofollow noreferrer">http://livingcode.org/2006/tab-dumping-in-safari</a>. 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.</p>\n\n<p>There are two major parts to it:</p>\n\n<ul>\n<li><p>You need to attach your code to a running Safari. This is typically done with SIMBL <a href="http://www.culater.net/software/SIMBL/SIMBL.php" rel="nofollow noreferrer">http://www.culater.net/software/SIMBL/SIMBL.php</a>.</p></li>\n<li><p>Once you\'re inside, you need to figure what to patch. There\'s a tutorial on reversing Cocoa applications <a href="http://www.culater.net/wiki/moin.cgi/CocoaReverseEngineering" rel="nofollow noreferrer">http://www.culater.net/wiki/moin.cgi/CocoaReverseEngineering</a>, which links to the most important tool, class-dump <a href="http://www.codethecode.com/projects/class-dump/" rel="nofollow noreferrer">http://www.codethecode.com/projects/class-dump/</a> (the link on wiki is broken). Class-dump gives you a complete hierarchy of Safari\'s classes, where you can guess by names what, specifically, you need to patch. This is a very trial and error mode.</p></li>\n</ul>\n\n<p>Reading the links above will give you the scope of the project.</p>\n'}, {'answer_id': 60401, 'author': 'Sören Kuklau', 'author_id': 1600, 'author_profile': 'https://Stackoverflow.com/users/1600', 'pm_score': 2, 'selected': False, 'text': '<blockquote>\n  <p>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?</p>\n</blockquote>\n\n<p>Actually, with an InputManager, it <em>would</em> be possible. SIMBL, the common technique for Safari extensions, is simply a wrapper around InputManagers — it stands for <strong>S</strong>mart <strong>I</strong>nput <strong>M</strong>anager <strong>B</strong>undle <strong>L</strong>oader. You can add stuff to the menu bar, to the toolbar, dialogs, anywhere, simply by extending Safari\'s existing classes.</p>\n\n<p>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.</p>\n\n<p>You also definitely want to take into consideration the special <a href="https://stackoverflow.com/questions/30966/inputmanager-on-os-x">limitations of InputManagers on Leopard</a>.</p>\n'}, {'answer_id': 984282, 'author': 'rcw3', 'author_id': 109115, 'author_profile': 'https://Stackoverflow.com/users/109115', 'pm_score': 0, 'selected': False, 'text': '<p>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 <a href="http://developer.apple.com/releasenotes/Cocoa/AppKit.html#NSInputManager" rel="nofollow noreferrer">Leopard Release Notes</a>.  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.</p>\n'}, {'answer_id': 1256724, 'author': 'Quinn Taylor', 'author_id': 120292, 'author_profile': 'https://Stackoverflow.com/users/120292', 'pm_score': 3, 'selected': False, 'text': '<p>Nobody seems to have even mentioned the fact that Safari actually does support true plugins, which input manager hacks most definitely are not.</p>\n\n<blockquote>\n  <p><strong>"WebKit Plug-In Programming Topics"</strong>\n  <a href="http://developer.apple.com/documentation/InternetWeb/Conceptual/WebKit_PluginProgTopic/" rel="nofollow noreferrer">http://developer.apple.com/documentation/InternetWeb/Conceptual/WebKit_PluginProgTopic/</a></p>\n</blockquote>\n\n<p>This is how things like support for PDF and Flash content are implemented. Take a peek inside your <code>/Library/Internet Plug-ins/</code> directory to see examples.</p>\n\n<p>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. <strong>Note:</strong> Safari is 64-bit by default on Snow Leopard, so no Input Managers work. I\'m missing <a href="http://safariadblock.sourceforge.net/" rel="nofollow noreferrer">Safari AdBlock</a> already... :-( I would love to see it rewritten as a bonafide plugin.</p>\n'}, {'answer_id': 2994128, 'author': 'Tim Sullivan', 'author_id': 722, 'author_profile': 'https://Stackoverflow.com/users/722', 'pm_score': 3, 'selected': False, 'text': '<p>Things have changed recently. Apple now has an extensions API available as a part of Safari 5. You can find out more on <a href="http://www.apple.com/safari/whats-new.html" rel="nofollow noreferrer">Apple\'s site</a> and by <a href="http://developer.apple.com/programs/safari/" rel="nofollow noreferrer">joining the Safari Developer Program</a>.</p>\n\n<p>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.</p>\n'}, {'answer_id': 2997758, 'author': 'Olivier Refalo', 'author_id': 258689, 'author_profile': 'https://Stackoverflow.com/users/258689', 'pm_score': 4, 'selected': True, 'text': '<p>With the release of Safari 5.0, Apple released a new extension framework for developers to use. In features it looks similar to Firefox extension framework allowing to customize buttons, toolbars, context menus, injections using javascript and html 5</p>\n\n<p>More at this link</p>\n\n<p><a href="https://developer.apple.com/documentation/safariextensions" rel="nofollow noreferrer">https://developer.apple.com/documentation/safariextensions</a></p>\n'}, {'answer_id': 3007519, 'author': 'Pete Akins', 'author_id': 362613, 'author_profile': 'https://Stackoverflow.com/users/362613', 'pm_score': 0, 'selected': False, 'text': '<p>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.</p>\n\n<p><a href="http://safariextensions.tumblr.com/" rel="nofollow noreferrer">http://safariextensions.tumblr.com/</a></p>\n'}, {'answer_id': 3013981, 'author': 'fission', 'author_id': 363360, 'author_profile': 'https://Stackoverflow.com/users/363360', 'pm_score': 0, 'selected': False, 'text': '<p>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.</p>\n'}]
['https://Stackoverflow.com/questions/60271', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4939/']