Detecting NPAPI support in Chrome using javascript
Asked Answered
H

3

27

As Google Chrome is dropping support for NPAPI post September 2015. Is there any way to detect the NPAPI support in chrome using JavaScript so that Alternative content will be load or show warning message to User to use an older version of Chrome.

Huckleberry answered 27/2, 2015 at 13:37 Comment(4)
You should never show users a message telling them to use an older version of a browser, as older versions do not receive security updates.Arvad
I totally agree with smorgan, however we still need to be able to detect which replacement technology to provide them with. Sure wish there was a way to feature detect instead of version sniffing...Jonquil
Just for the record: you can enable napi in the newer versions here: chrome://flags/#enable-npapiNoria
This comment now applies to Microsoft Edge as well since it has also dropped support for NPAPI.Inordinate
F
8

Had an issue created by chrome 42's disabling of NPAPI. What was done was something in the lines of this: (similar to )

function isJavaAvailable() {
  var javaRegex = /(Java)(\(TM\)| Deployment)/,
      plugins = navigator.plugins;
  if (navigator && plugins) {
    for (plugin in plugins){
      if(plugins.hasOwnProperty(plugin) &&
         javaRegex.exec(plugins[plugin].name)) {
        return true;
      }
    }
  }
  return false;
}

var chromeVersion = window.navigator.userAgent.match(/Chrome\/(\d+)\./);
if (chromeVersion && chromeVersion[1]) {
  if (parseInt(chromeVersion[1], 10) >= 42 && !isJavaAvailable()) {
    // do chrome-no-java-related task
    console.log('Java not available');
  }
}

This is not a direct "NPAPI-detector", but can be rewritten to test for the plugins affected by NPAPI disabling through changing the regex for instance. Regex was used for some kind of robustness. Had a look into navigator.plugins['some-number'].names to find what to check for.

Flatwise answered 21/4, 2015 at 12:11 Comment(0)
A
3

Due to auto-updates, Chrome users are generally running the latest version; once that rolls out, you should probably just assume that Chrome users don't have NPAPI support, and serve them the alternate content.

Arvad answered 28/2, 2015 at 0:34 Comment(0)
R
2

There is no javascript api to check NPAPI support, but as workaround I can suggest you to check browser version of Chrome.

If Chrome version older then 42 than NPAPI support is disabled. Yes, from 42 and before 45 version you can use chrome://flags/#enable-npapi but there is no way to check this flags from JS

For now I guess it's pretty actual information: https://www.chromium.org/developers/npapi-deprecation?pli=1

Roxane answered 20/4, 2015 at 11:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.