Introducing the universal_dom_remote gem


require 'universal_dom_remote'

udr = debug: true

r = udr.send 'console.log("fun");' #=> "undefined" 
r = udr.send '"1" + "3"'           #=> "13" 
r = udr.send 'document.title'      #=> "" 
r = udr.send 'document.title()'    #=> "document.title is not a function" 

The above exampe was executed from an IRB session.

Running the example

To run the example you will need:

The SPS broker running:

require 'simplepubsub

SimplePubSub::Broker.start port: '55000'

A web browser web console window open with the follow code copied and pasted into it:

var ws = new WebSocket('ws://');
ws.onopen = function() {
  ws.send('subscribe to topic: udr/controller');
ws.onclose = function() {
ws.onmessage = function(event) {

  var a = +/,2);

  try {
    r = eval(a[1]);
  catch(err) {
    r = err.message;

  ws.send('udr/browser: ' + r);


A debug window with the following code to help troubleshoot message passing:

require 'sps-sub'

sps = host: '', port: '55000'

sps.subscribe(topic: '#') do |msg, topic|
  puts "%s: %s " % [topic, msg]


  1. JavaScript statements which don’t return a value e.g. (console.log) will return the string undefined
  2. An error message will be returned if a JavaScript statement contains an error
  3. The send command will timeout (after 30 seconds by default) if a return statement isn’t received within the given time
  4. The universal_dom_remote gem was intended to work with any web browser which support websockets. At present the only browser properly tested was Firefox.