Skip to content

Instantly share code, notes, and snippets.

@fillano
Created November 7, 2010 12:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fillano/666109 to your computer and use it in GitHub Desktop.
Save fillano/666109 to your computer and use it in GitHub Desktop.
detect SharedWorker global scope and report to js in html
(function(global){
function handleConnect(e) {
try {
if(e.ports && e.ports[0]) {
e.ports[0].onmessage = handleMessage(e.ports[0]);
}
} catch(e) {
}
}
function handleMessage(o) {
return function(e) {
if(e.data.indexOf('start') > -1) {
var str = '<table width="100%" border="1" cellspacing="0" cellpadding="2">\n';
for (var i in global) {
if(i!=='onconnect') {
str += '<tr><td style="background: #AABBCC">' + i + '</td><td style="background: #DDEEFF">' + global[i] + '</td></tr>\n';
} else {
str += '<tr><td style="background: #AABBCC">' + i + '</td><td style="background: #DDEEFF">onconnect eventHandler</td></tr>\n';
}
}
str += '</table>\n';
o.postMessage(str);
}
};
}
global.onconnect = handleConnect;
})(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment