Skip to content

Instantly share code, notes, and snippets.

@saruba
Last active August 29, 2015 14:02
Show Gist options
  • Save saruba/ee62ac02006c9ff16932 to your computer and use it in GitHub Desktop.
Save saruba/ee62ac02006c9ff16932 to your computer and use it in GitHub Desktop.
Detect that a specific Chrome extension
function detectChromeExtension(extensionId, accesibleResource, callback) {
if (typeof(chrome) !== 'undefined') {
var xmlHttp = new XMLHttpRequest(),
testUrl = 'chrome-extension://' + extensionId + '/' + accesibleResource;
xmlHttp.open('HEAD', testUrl, true);
xmlHttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xmlHttp.timeout = 1000;
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4 && typeof(callback) == 'function') {
if (xmlHttp.status == 200) {
callback.call(this, true);
} else {
callback.call(this, false);
}
}
};
xmlHttp.ontimeout = function () {
if (typeof(callback) == 'function')
callback.call(this, false);
};
xmlHttp.send();
} else {
if (typeof(callback) == 'function')
callback.call(this, false);
}
}
detectChromeExtension('pimkadpiclhfobplcdjbnjgjmjfdklig', 'img/icon128.png',
function myCallbackFunction(extensionExists) {
if (!extensionExists) {
element.removeClass('hidden');
}
});
@saruba
Copy link
Author

saruba commented Jun 24, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment