Skip to content

Instantly share code, notes, and snippets.

@lebbe
Forked from Rob--W/detect-pdfjs-chromium.js
Last active August 29, 2015 14:06
Show Gist options
  • Save lebbe/0eedf77e8f7e1449f02e to your computer and use it in GitHub Desktop.
Save lebbe/0eedf77e8f7e1449f02e to your computer and use it in GitHub Desktop.
/**
* 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)
*
* Made synchronous by a handwaiving Lebbe
*
* Public domain - all rights waived.
*/
function isPDFJSExtensionInstalledInChromium() {
if (!window.chrome) {
return false;
}
if(!chrome.webstore) {
// pdf.js from Opera's addon gallery
if(_isPDFJSExtensionInstalled('encfpfilknmenlmjemepncnlbbjlabkc')) return true;
}
// pdf.js from Chrome Web Store
if(__isPDFJSExtensionInstalled('oemmndcbldboiebfnladdacbdfmadadm')) {
return true;
}
return false;
function _isPDFJSExtensionInstalled(id) {
try {
var x = new XMLHttpRequest();
x.open('GET', 'chrome-extension://' + id + '/content/web/viewer.html', false);
x.send(null);
return x.status === 200;
} catch (e) {
return false;
}
return false;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment