List Detection (PPAPI) Flash with Javascript

We use a proprietary document viewer that does not play amazingly with the Pepper version of Flash found in some versions of Chrome, so I would like to be able to detect it and redirect to the same content in a different format.

Since this version seems to be lagging behind NPAPI, I use FlashDetect to find the version number, but this requires a daily update. I would rather not look at UserAgent, as this flash architecture is causing problems, not the browser, but is there any way to do this with Javascript?

+4
source share
5 answers

I think this should be done as follows:

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 short explanation:

If our browser has an enumeration of MIME types, we can get a plugin associated with the specified type. Therefore, we get the plugin associated with 'application/x-shockwave-flash' and check if its file name is 'pepflashplayer.dll' . I think this name is permanent and will not be changed in the future.


UPD No. 2:

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

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


UPD No. 3:

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

 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 the updated fiddle .


UPD No. 4:

Changed the code a bit to fit today's realities. Now the condition is as follows:

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

Check out jsFiddle .

+16
source

I could not get other examples to work, but the following code works for me on both a Mac and a PC with PPAPI enabled or disabled. Also works correctly in 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 is here .

+4
source

Darren version that does not require Underscore.js

 var checkForPepper = function() { if (navigator.plugins) { for (var i=0, count = navigator.plugins.length; i < count; i++) { var filename = navigator.plugins[i].filename; if (filename === 'pepflashplayer.dll' || filename === 'PepperFlashPlayer.plugin') return true; } } return false; 

}

+4
source

I made a cleaner version of this method using regexp. Includes tests.

http://jsfiddle.net/YNCVh/

β†’> Is pepper currently working? true

β†’> Compatible with test case? pepflashplayer.dll: true

β†’> Compatible with test case? PepperFlashPlayer.plugin: true

β†’> Compatible with test case? libpepflashplayer.so: true

 /** * Regular expression to test for pepper PPAPI plugins */ var PPAPI_REGEX = /^(lib)?pep(per)?flashplayer/i; /** * Returns true if the current agent is running PPAPI version of flash */ function runningPepperFlash() { if (navigator.plugins) { for (var i = 0, count = navigator.plugins.length; i < count; i++) { var plugin = navigator.plugins[i].filename; var has_pepper = PPAPI_REGEX.test(plugin); if (has_pepper) { return true; } } return false; } } // ---------------------------------------------------------- // test cases: /** * Test case against the three (3) known plugin file types (win,mac,linux) */ function executeTestCases() { var plugins = ['pepflashplayer.dll', 'PepperFlashPlayer.plugin', 'libpepflashplayer.so']; for (var i = 0; i < plugins.length; i++) { var has_pepper = PPAPI_REGEX.test(plugins[i]); console.log('Test Case Plugin Matched? ', plugins[i], ': ', has_pepper); } } console.log('Currently Running Pepper?', runningPepperFlash()); executeTestCases();​ 
+2
source

I know that you asked for Javascript, but this can also be done (easier) in Flash. Just check

 if (Capabilities.manufacturer === "Google Pepper") { Alert.show("Using PPAPI"); } 

A source

+1
source

Source: https://habr.com/ru/post/1439469/


All Articles