Detecting Gears and Dojo Offline
Tagged dojo, dojo-offline-toolkit, google-gears, local-storage
I was wondering if I could sniff whether or not a visitor has the Dojo Offline Toolkit or Google Gears installed. So I took a dive in their code and I came up with the following.
// Detect Google Gears.
try{
window.gears = !!(typeof GearsFactory != 'undefined' || navigator.mimeTypes['application/x-googlegears'] || new ActiveXObject(’Gears.Factory’));
}catch(e){}
// Detect Dojo Offline.
var head = document.getElementsByTagName(’head’)[0];
var script = document.createElement(’script’);
script.setAttribute(’src’, ‘http://localhost:8123/polipo/offline’);
window.offlineCacheCallback = function(name, results){
head = script = null;
window.djoffline = true;
};
head.appendChild(script);
// Use a timeout because IE isn’t finished
// with dojo on the window.onload event.
setTimeout(function(){
alert(’gears: ‘ + window.gears);
alert(’dojo offline: ‘ + window.djoffline);
},1000);
To see this working, go visit the example page. To detect Google Gears is quite obvious. Just check if some variables exist. To detect a Dojo Offline installation, we to insert a script tag in the html head. The script tags’ src attribute points to some localhost service called Polipo, a caching web proxy Dojo Offline is built on. When the service exists, it’ll call the window.offlineCacheCallback function. So when that function is called, we know Dojo Offline is installed and running.
Other engines?
I also tried to sniff Adobe Air, the former Adobe Appollo, but I couldn’t find a way to do this. I don’t think it’s possible to do this through javascript (only through flash/actionscript). Another client side storage provider is Microsoft Silverlight. I didn’t do any research on this one, because I couldn’t get any examples running.
Cool post and code! One thing — we have ported Dojo Offline to use the Google Gears runtime instead of the Dojo Offline runtime, keeping our old APIs and adding some new ones. Expect to see a download this week.
Brad Neuberg