Detect if Google Chrome is blocking Java plugin

The Google Chrome plugin blocks Java until you explicitly allow it to run. https://www.google.com/support/chrome/bin/answer.py?answer=1247383&hl=en-US

How can I detect in javascript if Chrome blocks it?

+4
source share
2 answers

This is not only Chrome that uses the click-to-play functions - Firefox (Java made a click to play through the block list), Opera (their Turbo mode does all the plugins for playback), ... and there are also Add-Ons / Extensions that prohibit launch plugins automatically.

None of them let you know that plugins are clicks to play from content scripts. Therefore, ideally, you solve the problem in a more general way.

You can distinguish between an unconnected plugin (see navigator.plugins ) and other cases with

  • regular testing of scriptability or
  • with calling the plugin on the script page when loading

... and suppose "failed to load or blocked" based on this. To do this, there is a page of best practices on MDN.

This difference should usually be good enough, check for example. how SoundCloud handles plugins that are clicks to play.

+1
source

Answer edited on 2013.03.15 to increase the accuracy of information.

The list of supported plugins is available as an array in the navigator object:

 navigator.plugins 

This API is non-standard , but all modern browsers implement it. Internet Explorer support dates back to at least IE7, but is not available in older versions of Opera.

navigator.plugins has this basic structure:

 PluginArray [ ... Plugin { description: "Java Plug-In 2 for NPAPI Browsers" filename: "JavaAppletPlugin.plugin" length: 17 name: "Java Plug-In 2 for NPAPI Browsers" }, ... ] 

Here is a function that traverses navigator.plugins and checks the name property for a given string. It returns true or false if found.

 function pluginEnabled(name) { var plugins = navigator.plugins, i = plugins.length, regExp = new RegExp(name, 'i'); while (i--) { if (regExp.test(plugins[i].name)) return true; } return false; } 

Use it like this (case insensitive):

 pluginEnabled('java'); pluginEnabled('flash'); 
-1
source

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


All Articles