Detect Chrome NaCl Availability

Is there a way to determine if NaCl is available in the current browser?

It seems that checking for chrome.app.isInstalledturns to false positive in some browsers other than Chrome.

+4
source share
2 answers

You can check if the browser supports mime NaCl type. For example:.

navigator.mimeTypes['application/x-nacl'] !== undefined.

Similarly, for PNaCl you can check 'application/x-pnacl'.

+5
source

You can check Chrome and a specific version of Chrome as follows:

var have_nacl = false;
var have_pnacl = false;

var index = navigator.userAgent.indexOf('Chrome');
if (index != -1) {
  var version = parseFloat(navigator.userAgent.substring(index + 7));

  if (31 <= version) have_pnacl = true;
  if (14 <= version) have_nacl = true;
}

. 31+ PNaCl . NaCl Chrome, , NaCl. - , NaCl . . :

var watchdog;
var watchdog_time;

function watchdog_timeout() {
  alert('NaCl module failed to load');
}

function watchdog_clear() {
  clearTimeout(watchdog);
}

function watchdog_set(time) {
  watchdog_time = time;
  watchdog = setTimeout(watchdog_timeout, time);
}

watchdog_set(5000); // Timeout in 5 sec

var module = document.getElementById('module'); // Use your module ID
module.addEventListener('load', function () {
  watchdog_clear();
  alert('NaCl module loaded');
}, true);

// Inject the module, where module.nmf is your NMF file.
module.innerHTML = '<embed src="module.nmf" type="application/x-nacl"/>';

, HTML - :

<div id="module"></div>

, .

function watchdog_extend() {
  watchdog_clear();
  watchdog_set(watchdog_time);
}

module.addEventListener('loadstart', watchdog_extend, true);
module.addEventListener('progress', watchdog_extend, true);
0

All Articles