[webkit-dev] Thoughts on the best approach for accessing Ruby objects from WebKit's JavaScript engine

Andrew S. Townley ast at atownley.org
Tue Feb 24 09:42:16 PST 2009

Hi Everyone,

After many different attempts and loads of bizarre thoughts on the
subject, I figured I'd just ask the core question I'm trying to answer
and attempt to cut out the middle-man (in this case GObject and GTK+).

I would *love* to be able to achieve the following:

from myapp.rb:
require 'gtk2'
require 'webkit'

class Foo
  # ...
  def super_cool_method(arg1)
    # ...

class MyApp
  # ...

  webview = Gtk::WebKit::WebView.new
  jscontext = webview.window_script_object
  jscontext["foo"] = Foo.new
  # ...

from test.html:
<script ...>
   // ...
   var foo = window.foo;
   // ...

in a similar manner to:


Does anyone have any ideas what it would take to make this actually work
in a similar manner to the ObjC binding?

What I would like to avoid is to have my Ruby class be a GObject if
possible so that it would be direct Ruby/WebKit in this scenario without
being dependent on GTK+.  This would allow you to use Ruby from any of
the toolkit specific ports, and it might also provide hints on how to do
other dynamic language bindings directly into the JS runtime.

Is there some kind of idiom/pattern/framework in place to do this sort
of thing with static languages?

Beyond my work on extending Dan's Ruby/WebKit-GTK+ bindings, I really
don't know that much about the core WebKit code, so I wouldn't have a
clue where to start with this or how much effort would be involved.

Any information, thoughts or comments would be appreciated.


Andrew S. Townley <ast at atownley.org>

More information about the webkit-dev mailing list