Skip to content

Instantly share code, notes, and snippets.

@sydneyitguy
Last active November 23, 2018 07:05
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 sydneyitguy/61e54e09e4ef3b9170ed93e0a740188e to your computer and use it in GitHub Desktop.
Save sydneyitguy/61e54e09e4ef3b9170ed93e0a740188e to your computer and use it in GitHub Desktop.
Detect whether a chrome extension is installed or not
export const isChrome = function() {
return /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
}
export const detectExtension = function(extensionId, callback) {
const xobj = new XMLHttpRequest();
xobj.overrideMimeType("application/json");
xobj.open('GET', 'chrome-extension://' + extensionId + '/manifest.json', true);
xobj.onreadystatechange = function () {
if (xobj.readyState === 4) {
if (xobj.status === 200) {
callback(true);
} else {
callback(false);
}
}
};
xobj.send(null);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment