Epiphany Seed Extensions

February 8, 2009

Epiphany Seed extensions landed today. It’s still a pretty rough/simple API, but also exciting! Thanks to chpe, and xan for doing a lot of the clean up work.

One of the neat things about this, is all the bindings around the Epiphany API, were generated automatically by GObject-introspection, which made all of this rather easy!

For those not familiar yet, Seed is a library to embed JavaScriptCore as a scripting language, and provide automatic bindings around any (almost) GObject library.

As a quick example, I thought I’d do a small write up on how to make an Epiphany Seed extension, notably something quick that pops up a dialog when you try and close more than one tab. Thanks to Tim for writing the extension.

First, a file describing the extension is required, this can go in

~/.gnome2/epiphany/extensions
[Epiphany Extension]
Name=Don't Close Multiple Tabs
Description=Warns the user before closing a window containing multiple open tabs.
Authors=Tim Horton
Version=1
URL=


[Loader]
Type=seed
Module=close-multiple-tabs

This is all pretty straightforward I think, now when loading the extension, epiphany will look for “close-multiple-tabs.js” in the extensions directory (or a system extension directory).

The script should be a JavaScript file that returns an object containing several hook functions (attach window, detach tab, things like this). As the last thing evaluated is returned in JavaScript, the hello world extension could look like:

extension = {
   attach_window: function (window){
         Seed.print("Hello World!");
    }
}

With window being an EphyWindow object, which has all the useful methods from the epiphany API to write extensions. So, if we were actually trying to write our extension, we might do something like this:

function delete_event(window, event) {
	var n = window.get_notebook();
	if(n.get_n_pages() <= 1)
		return false;

        // Properties can be set in constructors with JSON synax.
	var dialog = new Gtk.MessageDialog({text:"You are about to close a window with " + n.get_n_pages() + " open tabs.", message_type:Gtk.MessageType.WARNING });
	dialog.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL).grab_focus();
	dialog.add_button(Gtk.STOCK_OK, Gtk.ResponseType.OK);
	dialog.set_default_response(Gtk.ResponseType.CANCEL);

	var result = dialog.run();
	dialog.hide();
	dialog.destroy();

	if(result == Gtk.ResponseType.OK)
		return false;
	else
		return true;
}

extension = {
    attach_window: function(window) {
		signal = window.signal.delete_event.connect(delete_event);
    }
}

This extension and one more (unlimited undo of Tab close) are available at (for now) http://racarr.me/epiphany-extensions/

5 Responses to “Epiphany Seed Extensions”

  1. Pacho Says:

    Could be possible doing an extension for not opening home page on every tab is opened?

    Thanks a lot 🙂


  2. Cool stuff! How does translations work the javascript bindings? Is it as simple as binding glib/i18n.h and just updating intltool (or whatever it is that does the magic) to extract strings from js files?

  3. Michael Says:

    Love it!

  4. Jaap Says:

    Great stuff, but can you store stuff in ~/.config instead of ~/.gnome2

    See http://live.gnome.org/GnomeGoals/XDGConfigFolders

  5. ReinoutS Says:

    @Jaap: Extensions should go where Epiphany looks for them. 🙂

    An extension is not ‘config’ data. if anything, it should live under .local/share aka XDG_DATA_HOME. Also, the GnomeGoal you link to is not approved.


Leave a Reply