1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-12 14:56:58 +01:00

Only load u2f-api.js implementation when necessary

Some browsers such as Firefox already provide a window.u2f
implementation. Detect the existing implementation and abort from
u2f-api.js.
This commit is contained in:
Kyle Spearrin 2017-09-29 11:22:23 -04:00
parent 6c93a63c06
commit f7b60febe9

View File

@ -11,12 +11,28 @@
*/ */
'use strict'; 'use strict';
/**
* Modification:
* Wrap implementation so that we can exit if window.u2f is already supplied by the browser (see below).
*/
(function (root) {
/**
* Modification:
* Only continue load this library if window.u2f is not already supplied by the browser.
*/
var isFirefox = navigator.userAgent.indexOf('Firefox') !== -1 || navigator.userAgent.indexOf('Gecko/') !== -1;
var browserImplementsU2f = !!((typeof root.u2f !== 'undefined') && root.u2f.register);
if (isFirefox && browserImplementsU2f) {
root.u2f.isSupported = true;
return;
}
/** /**
* Namespace for the U2F api. * Namespace for the U2F api.
* @type {Object} * @type {Object}
*/ */
var u2f = u2f || {}; var u2f = root.u2f || {};
/** /**
* Modification: * Modification:
@ -754,3 +770,10 @@ u2f.getApiVersion = function (callback, opt_timeoutSeconds) {
port.postMessage(req); port.postMessage(req);
}); });
}; };
/**
* Modification:
* Assign u2f back to window (root) scope.
*/
root.u2f = u2f;
}(this));