Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting Pepper (PPAPI) Flash with Javascript

We are using a proprietary document viewer which doesn't play terribly nice with the Pepper version of Flash found in some flavors of Chrome, so I'd like to be able to detect it and redirect to the same content in a different format.

Since this version seems to lag behind the NPAPI one, I have been using FlashDetect to look for the version number but this requires daily updating. I'd rather not look at the UserAgent since it's the flash architecture causing the trouble and not the browser, but is there any method of doing this with Javascript?

like image 802
Andy H-D Avatar asked Nov 28 '22 17:11

Andy H-D


2 Answers

I think it should be done this way:

var isPPAPI = false;
var type = 'application/x-shockwave-flash';
var mimeTypes = navigator.mimeTypes;

if (mimeTypes && mimeTypes[type] && mimeTypes[type].enabledPlugin &&
    mimeTypes[type].enabledPlugin.filename == 'pepflashplayer.dll') isPPAPI = true;

Demo on jsFiddle.


UPD №1: Not sure if needed, but I wrote a little explanation:

If our browser has a MIME types enumeration, we can get a plugin associated with a specified type. So we're getting plugin which associated with 'application/x-shockwave-flash' and check if its filename is 'pepflashplayer.dll'. I think that this name is constant and will not be changed in future.


UPD №2:

To enable/disable PPAPI in Google Chrome, you should go to this page: chrome://plugins/

(Sorry, this URL needs to be pasted directly into the address bar.)


UPD №3:

I did some investigation and found an interesting article that helped me to implement a cross-platform solution. I think that this code should work on all OS:

var isPPAPI = false;
var type = 'application/x-shockwave-flash';
var mimeTypes = navigator.mimeTypes;

var endsWith = function(str, suffix) {
    return str.indexOf(suffix, str.length - suffix.length) !== -1;
}

if (mimeTypes && mimeTypes[type] && mimeTypes[type].enabledPlugin &&
   (mimeTypes[type].enabledPlugin.filename == "pepflashplayer.dll" ||
    mimeTypes[type].enabledPlugin.filename == "libpepflashplayer.so" ||
    endsWith(mimeTypes[type].enabledPlugin.filename, "Chrome.plugin"))) isPPAPI = true;

Check out an updated fiddle.


UPD №4:

Slightly changed the code to meet today's realities. Now condition looks like this:

if (mimeTypes && mimeTypes[type] && mimeTypes[type].enabledPlugin &&
   (mimeTypes[type].enabledPlugin.filename.match(/pepflashplayer|Pepper/gi))) isPPAPI = true;

Check out jsFiddle.

like image 177
Igor Shastin Avatar answered Dec 05 '22 01:12

Igor Shastin


I couldn't get the other examples to work, but the following code works for me on both Mac and PC with Chrome PPAPI enabled or disabled. Also works correctly on other browsers.

function checkForPepper() {
  return navigator.plugins && _.any(navigator.plugins, function(plugin) {
    return plugin.filename === 'pepflashplayer.dll' || plugin.filename === 'PepperFlashPlayer.plugin';
  });
}
alert ('Pepper enabled: '+ checkForPepper());

Note: Requires underscore.js. Fiddle here.

like image 44
Darren Avatar answered Dec 05 '22 01:12

Darren