DOM events level 2 can be canceled by any event handler that calls the stopPropagation method of the event object it's handling. If you make sure that your event handler is the first one on the page (essentially by making sure that your script tags are the first ones on the page) then you can call stopPropagation to prevent other code from eavesdropping on your messages. You may also do this on a selective basis to make sure that only your events are filtered out.

So essentially you'll be doing this:

window.addEventListener("message", function (event) {
    var data = JSON.parse(event.data);

    if (data.secret === "my event and not anyone else's") {
        // do something
        event.stopPropagation();
    }
}, false);


Note however that people can still use tools like greasemonkey to intercept your events. On the web you can never be sure. JavaScript is an open source language. Hope this helps though.

How to use postMessage as message serializer?
I am willing to run a clustering algorithm on data records consisting in sets each one representing the features enabled at a certain time.

Is there any clustering algorithm you would recommend me to try out? In my first tests I'm experimenting with K-means, but maybe there is something more suitable.

Is there any distance function that works well with sets? I guess that there is something better than the Euclidean distance but I don't have may clue on how the better metric could look like.
