Skip to content

Instantly share code, notes, and snippets.

@Rob--W
Created September 17, 2014 13:39
Show Gist options
  • Save Rob--W/5c4e017e22a47bf55572 to your computer and use it in GitHub Desktop.
Save Rob--W/5c4e017e22a47bf55572 to your computer and use it in GitHub Desktop.
Detect whether PDF.js extension is installed in Google Chrome, Chromium or Opera.
/**
* Detects whether the PDF.js Chromium extension is installed in the browser.
* Example: isPDFJSExtensionInstalled(function(result) { alert('Is PDF.js installed? ' + result);});
*
* @param {function(boolean)} callback - Called when the detection completed.
*
* Author: Rob Wu <rob@robwu.nl> (https://robwu.nl)
* Public domain - all rights waived.
*/
function isPDFJSExtensionInstalled(callback) {
if (!window.chrome) {
// Not a Chromium browser.
setTimeout(callback, 0, false);
return;
}
if (chrome.webstore) {
// Chrome or Chromium
_isPDFJSExtensionInstalled('oemmndcbldboiebfnladdacbdfmadadm', callback);
} else {
// Opera? First detect PDF.js from Opera's addon gallery.
// If not available, try to detect PDF.js from the Chrome Web Store
_isPDFJSExtensionInstalled('encfpfilknmenlmjemepncnlbbjlabkc', function(result) {
if (result) callback(true);
else _isPDFJSExtensionInstalled('oemmndcbldboiebfnladdacbdfmadadm', callback);
});
}
function _isPDFJSExtensionInstalled(id, callback) {
var x = new XMLHttpRequest();
x.open('GET', 'chrome-extension://' + id + '/content/web/viewer.html');
x.onload = function() { callback(true); };
x.onerror = function() { callback(false); };
x.send();
}
}
@maisui99
Copy link

it seems that chrome has stopped this way to detect.

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