Last active
November 23, 2018 07:05
-
-
Save sydneyitguy/61e54e09e4ef3b9170ed93e0a740188e to your computer and use it in GitHub Desktop.
Detect whether a chrome extension is installed or not
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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