Skip to content
This repository was archived by the owner on Mar 19, 2025. It is now read-only.

Commit 2b269d3

Browse files
committed
Fix #14: IE8/9 have console.* only when Developer Tools (F12) is open.
Replace console.log with _debug and let it be a NOP by default.
1 parent 143cc0f commit 2b269d3

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

src/hwcrypto.js

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
// https://github.com/open-eid/hwcrypto.js
33
var hwcrypto = (function hwcrypto() {
44
'use strict';
5-
console.log("hwcrypto.js activated");
5+
var _debug = function(x) {
6+
// console.log(x);
7+
};
8+
_debug("hwcrypto.js activated");
69
// Fix up IE8
710
window.addEventListener = window.addEventListener || window.attachEvent;
811
// Returns "true" if a plugin is present for the MIME
@@ -42,10 +45,10 @@ var hwcrypto = (function hwcrypto() {
4245
function loadPluginFor(mime) {
4346
var element = _mimeid(mime);
4447
if(document.getElementById(element)) {
45-
console.log("Plugin element already loaded");
48+
_debug("Plugin element already loaded");
4649
return document.getElementById(element);
4750
}
48-
console.log('Loading plugin for ' + mime + ' into ' + element);
51+
_debug('Loading plugin for ' + mime + ' into ' + element);
4952
// Must insert tag as string (not as an Element object) so that IE9 can access plugin methods
5053
var objectTag = '<object id="' + element + '" type="' + mime + '" style="width: 1px; height: 1px; position: absolute; visibility: hidden;"></object>';
5154
var div = document.createElement("div");
@@ -70,10 +73,10 @@ var hwcrypto = (function hwcrypto() {
7073
var msg = 'probe() detected ';
7174
// First try Chrome extensions
7275
if(hasExtensionFor(digidoc_chrome)) {
73-
console.log(msg + digidoc_chrome);
76+
_debug(msg + digidoc_chrome);
7477
}
7578
if(hasPluginFor(digidoc_mime)) {
76-
console.log(msg + digidoc_mime);
79+
_debug(msg + digidoc_mime);
7780
}
7881
}
7982
// TODO: remove
@@ -89,7 +92,7 @@ var hwcrypto = (function hwcrypto() {
8992
var certificate_ids = {};
9093

9194
function code2str(err) {
92-
console.log("Error: " + err + " with: " + p.errorMessage);
95+
_debug("Error: " + err + " with: " + p.errorMessage);
9396
switch(parseInt(err)) {
9497
case 1:
9598
return USER_CANCEL;
@@ -101,7 +104,7 @@ var hwcrypto = (function hwcrypto() {
101104
case 19:
102105
return NOT_ALLOWED;
103106
default:
104-
console.log("Unknown error: " + err + " with: " + p.errorMessage);
107+
_debug("Unknown error: " + err + " with: " + p.errorMessage);
105108
return TECHNICAL_ERROR;
106109
}
107110
}
@@ -141,7 +144,7 @@ var hwcrypto = (function hwcrypto() {
141144
});
142145
}
143146
} catch(ex) {
144-
console.log(ex);
147+
_debug(ex);
145148
reject(code2err(p.errorCode));
146149
}
147150
});
@@ -160,11 +163,11 @@ var hwcrypto = (function hwcrypto() {
160163
hex: v
161164
});
162165
} catch(ex) {
163-
console.log(JSON.stringify(ex));
166+
_debug(JSON.stringify(ex));
164167
reject(code2err(p.errorCode));
165168
}
166169
} else {
167-
console.log("invalid certificate: " + cert);
170+
_debug("invalid certificate: " + cert);
168171
reject(new Error(INVALID_ARGUMENT));
169172
}
170173
});
@@ -227,11 +230,11 @@ var hwcrypto = (function hwcrypto() {
227230
var b = new Backend();
228231
b.check().then(function(isLoaded) {
229232
if (isLoaded) {
230-
console.log("Using backend: " + b._name);
233+
_debug("Using backend: " + b._name);
231234
_backend = b;
232235
resolve(true);
233236
} else {
234-
console.log(b._name + " check() failed");
237+
_debug(b._name + " check() failed");
235238
resolve(false);
236239
}
237240
});
@@ -240,7 +243,7 @@ var hwcrypto = (function hwcrypto() {
240243

241244
function _autodetect(force) {
242245
return new Promise(function(resolve, reject) {
243-
console.log("Autodetecting best backend");
246+
_debug("Autodetecting best backend");
244247
if (typeof force === 'undefined') {
245248
force = false;
246249
}
@@ -260,7 +263,7 @@ var hwcrypto = (function hwcrypto() {
260263

261264
// IE BHO
262265
if (navigator.userAgent.indexOf("MSIE") != -1 || navigator.userAgent.indexOf("Trident") != -1) {
263-
console.log("Assuming IE BHO, testing");
266+
_debug("Assuming IE BHO, testing");
264267
return tryDigiDocPlugin();
265268
}
266269

@@ -317,7 +320,7 @@ var hwcrypto = (function hwcrypto() {
317320
// Get a certificate
318321
fields.getCertificate = function(options) {
319322
if(typeof options !== 'object') {
320-
console.log("getCertificate options parameter must be an object");
323+
_debug("getCertificate options parameter must be an object");
321324
return Promise.reject(new Error(INVALID_ARGUMENT));
322325
}
323326
// If options does not specify a language, set to 'en'
@@ -352,7 +355,7 @@ var hwcrypto = (function hwcrypto() {
352355
// Convert Hash to hex and vice versa.
353356
// TODO: All backends currently expect the presence of Hex.
354357
if (hash.hex && !hash.value) {
355-
console.log("DEPRECATED: hash.hex as argument to sign() is deprecated, use hash.value instead");
358+
_debug("DEPRECATED: hash.hex as argument to sign() is deprecated, use hash.value instead");
356359
hash.value = _hex2array(hash.hex);
357360
}
358361
if (hash.value && !hash.hex)

0 commit comments

Comments
 (0)