It seems to me you have two separate problems here:
- How to capture and serialize mouse events. This is pretty straightforward.
- How to re-create those mouse events in another context. This is tricky.
Even without using a library like jQuery, capturing mouse events is fairly simple (especially if, as you imply, you can be sure of the browser the client will be using). All you need to do is listen for the event, grab the information you need, and send it through your transport layer, e.g.
document.body.addEventListener('click', function(e) {
sendToOtherBrowser({ type: 'click', pageX: e.pageX, pageY: e.pageY });
}, false);
I don't know that you'd need much more than event type and location for most events. The harder part is taking this event data and re-creating it elsewhere. To do that, as I think you note, you'd need to:
- capture
e.target
as well
- come up with a serializable unique id for the DOM element
- send the id with your event data
- use the unique id to get a reference to the DOM element in your other browser
- use something like
myUniqueElement.dispatchEvent
to recreate the event
I'd say (2) and (4) are the tricky parts here - you might take a look at these related questions for ideas. For (5), you can take a look at the event simulation examples here.
All that said, I have no idea how that might work for touch events - it may not be as easy as it is for mouse events (already not that easy).