4

The Google Chrome block Java plugin 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 block it?

Andrey M.
  • 3,688
  • 3
  • 33
  • 36

2 Answers2

1

It's not only Chrome employing click-to-play features - Firefox (Java made click-to-play via blocklist), Opera (their Turbo mode makes all plugins click-to-play), ... and there are also Add-ons/Extensions that prevent plugins from running automatically.

None of those allow you do find out about plugins being click-to-play from content scripts. So ideally you address the problem in a more general way.

You can differentiate between the plugin not being installed (see navigator.plugins) and other cases by either

  • regularly testing it's scriptability or
  • having the plugin call into the pages script when it is loaded

... and assume "failed to load or got blocked" based on that. There is a best-practices page on MDN for this.

That distinction should usually be good enough, check e.g. how SoundCloud handles plugins being click-to-play.

Georg Fritzsche
  • 97,545
  • 26
  • 194
  • 236
-1

Answer edited 2013.03.15 to improve accuracy of information

A 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 goes back to at least IE7, but it's not available in old 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's a function that loops over 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 so (case insensitive):

pluginEnabled('java');
pluginEnabled('flash');
Liam Newmarch
  • 3,935
  • 3
  • 32
  • 46
  • 1
    Checking `navigator.plugins` only tells you if a plugin is installed or not. It may still fail to load, get blocked or made click-to-play, and those conditions can't be found out via a content-accessible API. – Georg Fritzsche Apr 08 '13 at 08:31